/** * Forward project a point. If the point is not within the viewable hemisphere, return flags in * AzimuthVar variable if specified. * * @param phi double latitude in radians * @param lambda double longitude in radians * @param p Point2D * @param azVar AzimuthVar or null * @return Point2D pt */ protected Point2D _forward(double phi, double lambda, Point2D p, AzimuthVar azVar) { double c = hemisphere_distance(centerY, centerX, phi, lambda); // normalize invalid point to the edge of the sphere if (c > HEMISPHERE_EDGE) { double az = GreatCircle.sphericalAzimuth(centerY, centerX, phi, lambda); if (azVar != null) { azVar.invalid_forward = true; // set the invalid // flag azVar.current_azimuth = (float) az; // record azimuth // of this // point } return edge_point(p, az); } double kPrime = 1 / Math.cos(c); double cosPhi = Math.cos(phi); double sinPhi = Math.sin(phi); double lambdaMinusCtrLon = lambda - centerX; double cosLambdaMinusCtrLon = Math.cos(lambdaMinusCtrLon); double sinLambdaMinusCtrLon = Math.sin(lambdaMinusCtrLon); double x = (scaled_radius * kPrime * cosPhi * sinLambdaMinusCtrLon) + wx; double y = hy - (scaled_radius * kPrime * (cosCtrLat * sinPhi - sinCtrLat * cosPhi * cosLambdaMinusCtrLon)); p.setLocation(x, y); return p; }
// Examples of distances and directions calculations public static void main(String[] args) { GeoPoint from = new GeoPoint(37.501282801564244, -122.48082160949707); // the boat GeoPoint to = new GeoPoint(37.49403906867881, -122.48468399047852); // HMB Entrance double dist = from.gcDistanceBetween(to); double heading = GreatCircle.calculateRhumLineRoute(from.degreesToRadians(), to.degreesToRadians()); dist = GreatCircle.calculateRhumLineDistance(from.degreesToRadians(), to.degreesToRadians()); System.out.println( "Loxo Dist:" + dist + " nm, " + (dist * 1852) + " m, heading " + Math.toDegrees(heading)); GreatCircle gc = new GreatCircle(); gc.setStartInDegrees(from); gc.setArrivalInDegrees(to); gc.calculateGreatCircle(10); dist = Math.toDegrees(gc.getDistance()) * 60; GreatCircleWayPoint first = gc.getRoute().get(1); heading = first.getZ().doubleValue(); System.out.println("Ortho Dist:" + dist + " nm, " + (dist * 1852) + " m, heading " + heading); }
/** * Calculate point along edge of hemisphere (using center point and current azimuth). * * <p>This is invoked for points that aren't visible in the current hemisphere. * * @param p Point2D * @return Point2D p */ private Point2D edge_point(Point2D p, double current_azimuth) { double c = HEMISPHERE_EDGE; LatLonPoint tmpll = GreatCircle.sphericalBetween(centerY, centerX, c /*-epsilon*/, current_azimuth); double phi = tmpll.getRadLat(); double lambda = tmpll.getRadLon(); double kPrime = 1f / Math.cos(c); double cosPhi = Math.cos(phi); double sinPhi = Math.sin(phi); double lambdaMinusCtrLon = lambda - centerY; double cosLambdaMinusCtrLon = Math.cos(lambdaMinusCtrLon); double sinLambdaMinusCtrLon = Math.sin(lambdaMinusCtrLon); double x = (scaled_radius * kPrime * cosPhi * sinLambdaMinusCtrLon) + wx; double y = hy - (scaled_radius * kPrime * (cosCtrLat * sinPhi - sinCtrLat * cosPhi * cosLambdaMinusCtrLon)); p.setLocation(x, y); return p; }
public static final boolean hemisphere_clip( double phi1, double lambda0, double phi, double lambda) { return (GreatCircle.sphericalDistance(phi1, lambda0, phi, lambda) /*-epsilon*/ <= HEMISPHERE_EDGE); }
public static final double hemisphere_distance( double phi1, double lambda0, double phi, double lambda) { return GreatCircle.sphericalDistance(phi1, lambda0, phi, lambda) /*-epsilon*/; }
/** * Get the distance c of the point from the center of the hemisphere. * * @param phi1 latitude * @param lambda0 longitude * @param phi latitude * @param lambda longitude * @return float c angular distance in radians */ public static final float hemisphere_distance( float phi1, float lambda0, float phi, float lambda) { return GreatCircle.sphericalDistance(phi1, lambda0, phi, lambda) /*-epsilon*/; }