hadley/ggplot2 — Issue #365: dist_central_angle gives wrong values
Author: wch
Created: 2012-01-21 20:58:59+00:00
State: open

As I understand it, the dist_central_angle function is supposed to give an angle which, if multiplied by the radius, will give the great-circle distance.

The problem is that if there are two points which have the same latitude, it returns 0. Here are two examples. The first seems right, the second doesn't.

```
> dist_central_angle(lat=c(-90,90), lon=c(-45,-45))
[1] 3.141593

> dist_central_angle(lat=c(45,45), lon=c(0,180))
[1] 0
```

Inside the function, the distance seems to be calculated by this line of code - but it doesn't use `lon` at all, only `lat`:

```
ahav(sqrt(hav(diff(lat)) + cos(lat[-n]) * cos(lat[-1]) * hav(diff(lat))))
```