- Timestamp:
- 2011-07-07T10:06:51+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r4126 r4206 6 6 import static java.lang.Math.PI; 7 7 import static java.lang.Math.asin; 8 import static java.lang.Math.atan2; 8 9 import static java.lang.Math.cos; 9 10 import static java.lang.Math.sin; … … 181 182 * this lat/lon to another. 182 183 * 184 * (I don't know the original source of this formula, but see 185 * http://math.stackexchange.com/questions/720/how-to-calculate-a-heading-on-the-earths-surface 186 * for some hints how it is derived.) 187 * 183 188 * @param other the "destination" position 184 * @return heading 189 * @return heading in the range 0 <= hd < 2*PI 185 190 */ 186 191 public double heading(LatLon other) { 187 double rv; 188 if (other.lat() == lat()) { 189 rv = (other.lon()>lon() ? Math.PI / 2 : Math.PI * 3 / 2); 190 } else { 191 rv = Math.atan((other.lon()-lon())/(other.lat()-lat())); 192 if (rv < 0) { 193 rv += Math.PI; 194 } 195 if (other.lon() < lon()) { 196 rv += Math.PI; 197 } 198 } 199 return rv; 200 } 192 double hd = atan2(sin(toRadians(this.lon() - other.lon())) * cos(toRadians(other.lat())), 193 cos(toRadians(this.lat())) * sin(toRadians(other.lat())) - 194 sin(toRadians(this.lat())) * cos(toRadians(other.lat())) * cos(toRadians(this.lon() - other.lon()))); 195 hd %= 2 * PI; 196 if (hd < 0) { 197 hd += 2 * PI; 198 } 199 return hd; 200 } 201 201 202 202 /**
Note:
See TracChangeset
for help on using the changeset viewer.