Changeset 18109 in josm for trunk/src/org
- Timestamp:
- 2021-08-01T22:03:28+02:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r17141 r18109 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.tools; 3 4 import static org.openstreetmap.josm.data.projection.Ellipsoid.WGS84; 3 5 4 6 import java.awt.geom.Area; … … 26 28 import org.openstreetmap.josm.data.coor.EastNorth; 27 29 import org.openstreetmap.josm.data.coor.ILatLon; 30 import org.openstreetmap.josm.data.coor.LatLon; 28 31 import org.openstreetmap.josm.data.osm.BBox; 29 32 import org.openstreetmap.josm.data.osm.DataSet; … … 1557 1560 1558 1561 /** 1562 * Create a new LatLon at a specified distance. Currently uses WGS84, but may change randomly in the future. 1563 * This does not currently attempt to be hugely accurate. The actual location may be off 1564 * depending upon the distance and the elevation, but should be within 0.0002 meters. 1565 * 1566 * @param original The originating point 1567 * @param angle The angle (from true north) in radians 1568 * @param offset The distance to the new point in the current projection's units 1569 * @return The location at the specified angle and distance from the originating point 1570 * @since 18109 1571 */ 1572 public static ILatLon getLatLonFrom(final ILatLon original, final double angle, final double offset) { 1573 final double meterOffset = ProjectionRegistry.getProjection().getMetersPerUnit() * offset; 1574 final double radianLat = Math.toRadians(original.lat()); 1575 final double radianLon = Math.toRadians(original.lon()); 1576 final double angularDistance = meterOffset / WGS84.a; 1577 final double lat = Math.asin(Math.sin(radianLat) * Math.cos(angularDistance) 1578 + Math.cos(radianLat) * Math.sin(angularDistance) * Math.cos(angle)); 1579 final double lon = radianLon + Math.atan2(Math.sin(angle) * Math.sin(angularDistance) * Math.cos(radianLat), 1580 Math.cos(angularDistance) - Math.sin(radianLat) * Math.sin(lat)); 1581 return new LatLon(Math.toDegrees(lat), Math.toDegrees(lon)); 1582 } 1583 1584 /** 1559 1585 * Calculate closest distance between a line segment s1-s2 and a point p 1560 1586 * @param s1 start of segment
Note:
See TracChangeset
for help on using the changeset viewer.