Ticket #21172: 21172.patch

File 21172.patch, 2.6 KB (added by taylor.smock, 4 years ago)
  • src/org/openstreetmap/josm/tools/Geometry.java

    diff --git a/src/org/openstreetmap/josm/tools/Geometry.java b/src/org/openstreetmap/josm/tools/Geometry.java
    index b10ce47a16..d65d245589 100644
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
    33
     4import static org.openstreetmap.josm.data.projection.Ellipsoid.WGS84;
     5
    46import java.awt.geom.Area;
    57import java.awt.geom.Line2D;
    68import java.awt.geom.Path2D;
    import org.openstreetmap.josm.command.ChangeNodesCommand;  
    2527import org.openstreetmap.josm.command.Command;
    2628import org.openstreetmap.josm.data.coor.EastNorth;
    2729import org.openstreetmap.josm.data.coor.ILatLon;
     30import org.openstreetmap.josm.data.coor.LatLon;
    2831import org.openstreetmap.josm.data.osm.BBox;
    2932import org.openstreetmap.josm.data.osm.DataSet;
    3033import org.openstreetmap.josm.data.osm.INode;
    public final class Geometry {  
    15551558        return smallest != Double.MAX_VALUE ? Math.sqrt(smallest) : Double.NaN;
    15561559    }
    15571560
     1561    /**
     1562     * Create a new LatLon at a specified distance. Uses WGS84.
     1563     * This does not currently attempt to be hugely accurate. The actual location may be off
     1564     * depending upon the distance and the
     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 xxx
     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 deltaLongitudeDegree = (Math.PI * WGS84.a * Math.cos(Math.toRadians(original.lat())))
     1575                / (180 * Math.sqrt(1 - WGS84.e2 * Math.pow(Math.sin(Math.toRadians(original.lat())), 2)));
     1576        final double deltaLatitudeDegree = (Math.PI * WGS84.a * (1 - WGS84.e2))
     1577                / (180 * Math.pow(1 - WGS84.e2 * Math.pow(Math.sin(original.lat()), 2), 1.5));
     1578        final double dx = meterOffset * Math.sin(angle);
     1579        final double dy = meterOffset * Math.cos(angle);
     1580        final double dLon = dx / deltaLongitudeDegree;
     1581        final double dLat = dy / deltaLatitudeDegree;
     1582        return new LatLon(original.lat() + dLat, original.lon() + dLon);
     1583    }
     1584
    15581585    /**
    15591586     * Calculate closest distance between a line segment s1-s2 and a point p
    15601587     * @param s1 start of segment