Changeset 608 in josm for trunk/src/org/openstreetmap/josm/data/coor
- Timestamp:
- 2008-04-17T03:03:28+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/coor
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/Coordinate.java
r486 r608 41 41 * Return the squared distance of the northing/easting values between 42 42 * this and the argument. 43 * 44 * This method does NOT compute a great circle distance between two 45 * locations! 43 46 * 44 47 * @param other The other point to calculate the distance to. … … 46 49 * regarding to the x/y values. 47 50 */ 51 public double distanceSq(Coordinate other) { 52 return (x-other.x)*(x-other.x)+(y-other.y)*(y-other.y); 53 } 54 55 /** 56 * Return the distance of the northing/easting values between this and 57 * the argument. 58 * 59 * This method does NOT compute a great circle distance between two 60 * locations! 61 * 62 * @param other The other point to calculate the distance to. 63 * @return The square of the distance between this and the other point, 64 * regarding to the x/y values. 65 */ 48 66 public double distance(Coordinate other) { 49 return (x-other.x)*(x-other.x)+(y-other.y)*(y-other.y);67 return Math.sqrt(distanceSq(other)); 50 68 } 51 69 -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r589 r608 58 58 * @return distance in metres. 59 59 */ 60 public int distance(LatLon other) {61 return ( int) (Math.acos(60 public double greatCircleDistance(LatLon other) { 61 return (Math.acos( 62 62 Math.sin(Math.toRadians(lat())) * Math.sin(Math.toRadians(other.lat())) + 63 63 Math.cos(Math.toRadians(lat()))*Math.cos(Math.toRadians(other.lat())) * 64 64 Math.cos(Math.toRadians(other.lon()-lon()))) * 6378135); 65 } 66 67 /** 68 * Returns the heading, in radians, that you have to use to get from 69 * this lat/lon to another. 70 * 71 * @param other the "destination" position 72 * @return heading 73 */ 74 public double heading(LatLon other) { 75 double rv; 76 if (other.lat() == lat()) { 77 rv = (other.lon()>lon() ? Math.PI / 2 : Math.PI * 3 / 2); 78 } else { 79 rv = Math.atan((other.lon()-lon())/(other.lat()-lat())); 80 if (rv < 0) rv += Math.PI; 81 if (other.lon() < lon()) rv += Math.PI; 82 } 83 return rv; 65 84 } 66 85
Note: See TracChangeset
for help on using the changeset viewer.