diff --git a/src/org/openstreetmap/josm/data/coor/LatLon.java b/src/org/openstreetmap/josm/data/coor/LatLon.java
index 084bc9c..280a7de 100644
a
|
b
|
public class LatLon extends Coordinate {
|
177 | 177 | |
178 | 178 | /** |
179 | 179 | * Returns the heading, in radians, that you have to use to get from |
180 | | * this lat/lon to another. |
| 180 | * this lat/lon to another. North=0, East=Pi/2 |
181 | 181 | * |
182 | 182 | * @param other the "destination" position |
183 | 183 | * @return heading |
184 | 184 | */ |
185 | 185 | public double heading(LatLon other) { |
186 | | double rv; |
187 | | if (other.lat() == lat()) { |
188 | | rv = (other.lon()>lon() ? Math.PI / 2 : Math.PI * 3 / 2); |
189 | | } else { |
190 | | rv = Math.atan((other.lon()-lon())/(other.lat()-lat())); |
191 | | if (rv < 0) { |
192 | | rv += Math.PI; |
193 | | } |
194 | | if (other.lon() < lon()) { |
195 | | rv += Math.PI; |
196 | | } |
| 186 | double dlon = other.lon() - lon(); |
| 187 | double dlat = other.lat() - lat(); |
| 188 | if (dlon > 180.0) { |
| 189 | dlon -= 360.0; |
| 190 | } |
| 191 | if (dlon < -180.0) { |
| 192 | dlon += 360.0; |
| 193 | } |
| 194 | double rv = Math.atan2(dlon * cos(Math.toRadians(lat())), dlat); |
| 195 | if (rv < 0.0) { |
| 196 | rv += 2.0 * Math.PI; |
197 | 197 | } |
198 | 198 | return rv; |
199 | 199 | } |