/** * Returns the difference in degrees of longitude corresponding to the distance from the center * point. This distance can be used to find the extreme points. * * @param p1 * the p1 * @param distance * the distance * @return the extreme longitudes diff for point */ public static double getExtremeLongitudesDiffForPoint(final Point p1, final double distance) { double lat1 = p1.getLatitude(); lat1 = degreesToRadians(lat1); double longitudeRadius = Math.cos(lat1) * EARTH_RADIUS_KM; double diffLong = (distance / longitudeRadius); diffLong = radiansToDegrees(diffLong); return diffLong; }
/** * Returns the difference in degrees of longitude corresponding to the distance from the center * point. This distance can be used to find the extreme points. * * @param p1 * the p1 * @param distance * the distance * @return the extreme longitudes diff for point */ public static double getExtremeLongitudesDiffForPoint(final Point p1, final double distance) { double lat1 = p1.getLatitude(); lat1 = degreesToRadians(lat1); double longitudeRadius = Math.cos(lat1) * EARTH_RADIUS_KM; double diffLong = (distance / longitudeRadius); diffLong = radiansToDegrees(diffLong); return diffLong; }
/** * Returns an array of two extreme points corresponding to center point and the distance from * the center point. These extreme points are the points with max/min latitude and longitude. * * @param point * the point * @param distance * the distance * @return the extreme points from */ public static Point[] getExtremePointsFrom(final Point point, final Double distance) { double longDiff = getExtremeLongitudesDiffForPoint(point, distance); double latDiff = getExtremeLatitudesDiffForPoint(point, distance); Point p1 = new Point(point.getLatitude() - latDiff, point.getLongitude() - longDiff); Point p2 = new Point(point.getLatitude() + latDiff, point.getLatitude() + longDiff); return new Point[] { p1, p2 }; }
/** * Returns an array of two extreme points corresponding to center point and the distance from * the center point. These extreme points are the points with max/min latitude and longitude. * * @param point * the point * @param distance * the distance * @return the extreme points from */ public static Point[] getExtremePointsFrom(final Point point, final Double distance) { double longDiff = getExtremeLongitudesDiffForPoint(point, distance); double latDiff = getExtremeLatitudesDiffForPoint(point, distance); Point p1 = new Point(point.getLatitude() - latDiff, point.getLongitude() - longDiff); Point p2 = new Point(point.getLatitude() + latDiff, point.getLatitude() + longDiff); return new Point[] { p1, p2 }; }
/** * Returns the distance between tow points. * * @param p1 the p1 * @param p2 the p2 * @param unit the unit * @return the distance between points */ public static double getDistanceBetweenPoints(final Point p1, final Point p2, final String unit) { double theta = p1.getLongitude() - p2.getLongitude(); double dist = Math.sin(degreesToRadians(p1.getLatitude())) * Math.sin(degreesToRadians(p2.getLatitude())) + Math.cos(degreesToRadians(p1.getLatitude())) * Math.cos(degreesToRadians(p2.getLatitude())) * Math.cos(degreesToRadians(theta)); dist = Math.acos(dist); dist = radiansToDegrees(dist); dist = dist * 60 * 1.1515; if (unit.equals("K")) { dist = dist * 1.609344; } else if (unit.equals("M")) { dist = dist * 0.8684; } return (dist); }
double dist = Math.sin(degreesToRadians(p1.getLatitude())) * Math.sin(degreesToRadians(p2.getLatitude())) + Math.cos(degreesToRadians(p1.getLatitude())) * Math.cos(degreesToRadians(p2.getLatitude())) * Math.cos(degreesToRadians(theta)); dist = Math.acos(dist); dist = radiansToDegrees(dist);