@Test public void testPointOffset() { assertOffset(5.0, 5.0, 10.0, 5.0, 5.0, 8.0); assertOffset(5.0, 5.0, 10.0, 10.0, 2.878, 7.121); assertOffset(5.0, 5.0, 5.0, 10.0, 2.0, 5.0); assertOffset(5.0, 5.0, 0.0, 10.0, 2.878, 2.878); assertOffset(5.0, 5.0, 0.0, 5.0, 5.0, 2.0); assertOffset(5.0, 5.0, 0.0, 0.0, 7.121, 2.878); assertOffset(5.0, 5.0, 5.0, 0.0, 8.0, 5.0); assertOffset(5.0, 5.0, 10.0, 0.0, 7.121, 7.121); }
public static Point2D pointOffset(Point2D a, Point2D b, double k, Point2D dest) { if (dest == null) { dest = new Point2D.Double(); } double tanAlpha = (b.getY() - a.getY()) / (b.getX() - a.getX()); double alpha = Math.atan(tanAlpha); double sinAlpha = Math.sin(alpha); double cosAlpha = Math.cos(alpha); double destX; double destY; if (b.getX() < a.getX()) { destX = (a.getX() + k * sinAlpha); destY = (a.getY() - k * cosAlpha); } else { destX = (a.getX() - k * sinAlpha); destY = (a.getY() + k * cosAlpha); } dest.setLocation(destX, destY); return dest; }
GeoUtils { public static Point2D pointOffset(Point2D a, Point2D b, double k, Point2D dest) { if (dest == null) { dest = new Point2D.Double(); } double tanAlpha = (b.getY() - a.getY()) / (b.getX() - a.getX()); double alpha = Math.atan(tanAlpha); double sinAlpha = Math.sin(alpha); double cosAlpha = Math.cos(alpha); double destX; double destY; if (b.getX() < a.getX()) { destX = (a.getX() + k * sinAlpha); destY = (a.getY() - k * cosAlpha); } else { destX = (a.getX() - k * sinAlpha); destY = (a.getY() + k * cosAlpha); } dest.setLocation(destX, destY); return dest; } }
GeoUtils { public static Point2D pointOffset(Point2D a, Point2D b, double k, Point2D dest) { if (dest == null) { dest = new Point2D.Double(); } double tanAlpha = (b.getY() - a.getY()) / (b.getX() - a.getX()); double alpha = Math.atan(tanAlpha); double sinAlpha = Math.sin(alpha); double cosAlpha = Math.cos(alpha); double destX; double destY; if (b.getX() < a.getX()) { destX = (a.getX() + k * sinAlpha); destY = (a.getY() - k * cosAlpha); } else { destX = (a.getX() - k * sinAlpha); destY = (a.getY() + k * cosAlpha); } dest.setLocation(destX, destY); return dest; } private  GeoUtils(); }
GeoUtils { public static Point2D pointOffset(Point2D a, Point2D b, double k, Point2D dest) { if (dest == null) { dest = new Point2D.Double(); } double tanAlpha = (b.getY() - a.getY()) / (b.getX() - a.getX()); double alpha = Math.atan(tanAlpha); double sinAlpha = Math.sin(alpha); double cosAlpha = Math.cos(alpha); double destX; double destY; if (b.getX() < a.getX()) { destX = (a.getX() + k * sinAlpha); destY = (a.getY() - k * cosAlpha); } else { destX = (a.getX() - k * sinAlpha); destY = (a.getY() + k * cosAlpha); } dest.setLocation(destX, destY); return dest; } private  GeoUtils(); static Point2D nearestPointOnLine(Line2D l, Point2D p, boolean clampToSegment, Point2D dest); static double lineLength(Point2D a, Point2D b); static double distanceToLine(Line2D l, Point2D p); static double distanceToLine2(Line2D l, Point2D p); static double distanceToLine3(Line2D l, Point2D p); static Point2D pointOffset(Point2D a, Point2D b, double k, Point2D dest); static double DEG2RAD(double deg); static double RAD2DEG(double rad); static Point2D latLngToMap(double dLat, double dLng); static Point2D mapToLatLng(Point2D d); static double distance(Point2D a, Point2D b); static double distanceLatLng(double dLat1, double dLng1, double dLat2, double dLng2,
			LengthUtils.UnitOfMeasure u); static double distanceXY(double aLat, double aLng, double bLat, double bLng); static boolean isPointWithinBounds(Point2D p, Line2D l, double tolerance); }
GeoUtils { public static Point2D pointOffset(Point2D a, Point2D b, double k, Point2D dest) { if (dest == null) { dest = new Point2D.Double(); } double tanAlpha = (b.getY() - a.getY()) / (b.getX() - a.getX()); double alpha = Math.atan(tanAlpha); double sinAlpha = Math.sin(alpha); double cosAlpha = Math.cos(alpha); double destX; double destY; if (b.getX() < a.getX()) { destX = (a.getX() + k * sinAlpha); destY = (a.getY() - k * cosAlpha); } else { destX = (a.getX() - k * sinAlpha); destY = (a.getY() + k * cosAlpha); } dest.setLocation(destX, destY); return dest; } private  GeoUtils(); static Point2D nearestPointOnLine(Line2D l, Point2D p, boolean clampToSegment, Point2D dest); static double lineLength(Point2D a, Point2D b); static double distanceToLine(Line2D l, Point2D p); static double distanceToLine2(Line2D l, Point2D p); static double distanceToLine3(Line2D l, Point2D p); static Point2D pointOffset(Point2D a, Point2D b, double k, Point2D dest); static double DEG2RAD(double deg); static double RAD2DEG(double rad); static Point2D latLngToMap(double dLat, double dLng); static Point2D mapToLatLng(Point2D d); static double distance(Point2D a, Point2D b); static double distanceLatLng(double dLat1, double dLng1, double dLat2, double dLng2,
			LengthUtils.UnitOfMeasure u); static double distanceXY(double aLat, double aLng, double bLat, double bLng); static boolean isPointWithinBounds(Point2D p, Line2D l, double tolerance); static final double ERROR_MARGIN; static final QELLIPSOID ellipsoid; static final double EARTH_RADIUS_M; static final double EARTH_RADIUS_MI; static final ProjParams proj; }