@Test public void distance() { final Point start = WayPoint.of(47.2692124, 11.4041024); final Point end = WayPoint.of(47.3502, 11.70584); Assert.assertEquals( GEOID.distance(start, end).doubleValue(), 24528.356073554987, EPSILON ); Assert.assertEquals( GEOID.distance(end, start).doubleValue(), 24528.356073555155, EPSILON ); Assert.assertEquals( GEOID.distance(end, end).doubleValue(), 0.0, EPSILON ); }
public Length distance(final Point start, final Point end) { final double lat1 = start.getLatitude().toRadians(); final double lon1 = start.getLongitude().toRadians(); final double lat2 = end.getLatitude().toRadians(); final double lon2 = end.getLongitude().toRadians(); final double omega = lon2 - lon1; final double tanphi1 = tan(lat1); final double tanU1 = (1.0 - F)*tanphi1; final double U1 = atan(tanU1); final double sinU1 = sin(U1); final double cosU1 = cos(U1); final double tanphi2 = tan(lat2); final double tanU2 = (1.0 - F)*tanphi2; final double U2 = atan(tanU2); final double sinU2 = sin(U2); final double cosU2 = cos(U2); final double sinU1sinU2 = sinU1*sinU2; final double cosU1sinU2 = cosU1*sinU2; final double sinU1cosU2 = sinU1*cosU2; final double cosU1cosU2 = cosU1*cosU2; double lambda = omega; double a; double b; double sigma; double deltasigma; double lambda0; int iteration = 0; do { lambda0 = lambda; final double sinlambda = sin(lambda); final double coslambda = cos(lambda); final double sin2sigma = (cosU2*sinlambda*cosU2*sinlambda) + (cosU1sinU2 - sinU1cosU2*coslambda)* (cosU1sinU2 - sinU1cosU2*coslambda); final double sinsigma = sqrt(sin2sigma); final double cossigma = sinU1sinU2 + (cosU1cosU2*coslambda); sigma = atan2(sinsigma, cossigma); final double sinalpha = sin2sigma == 0.0 ? 0.0 : cosU1cosU2*sinlambda/sinsigma; final double alpha = asin(sinalpha); final double cosalpha = cos(alpha); double cos2alpha = cosalpha*cosalpha; final double cos2sigmam = cos2alpha == 0.0 ? 0.0 : cossigma - 2*sinU1sinU2/cos2alpha; final double u2 = cos2alpha*AABBBB; final double cos2sigmam2 = cos2sigmam*cos2sigmam; a = 1.0 + u2/16384*(4096 + u2*(-768 + u2*(320 - 175*u2))); b = u2/1024*(256 + u2*(-128 + u2*(74 - 47*u2))); deltasigma = b*sinsigma*(cos2sigmam + b/4*(cossigma*(-1 + 2 * cos2sigmam2) - b/6*cos2sigmam*(-3 + 4*sin2sigma)*(-3 + 4*cos2sigmam2))); final double C = F/16*cos2alpha*(4 + F*(4 - 3*cos2alpha)); lambda = omega + (1 - C)*F*sinalpha* (sigma + C*sinsigma*(cos2sigmam + C*cossigma*(-1 + 2*cos2sigmam2))); } while (iteration++ < DISTANCE_ITERATION_MAX && (abs((lambda - lambda0)/lambda) > DISTANCE_ITERATION_EPSILON)); if (iteration >= DISTANCE_ITERATION_MAX) { throw new ArithmeticException(format( "Calculating distance between %s and %s didn't converge.", start, end )); } final double s = B*a*(sigma - deltasigma); return Length.of(s, Unit.METER); }
Geoid { public Length distance(final Point start, final Point end) { final double lat1 = start.getLatitude().toRadians(); final double lon1 = start.getLongitude().toRadians(); final double lat2 = end.getLatitude().toRadians(); final double lon2 = end.getLongitude().toRadians(); final double omega = lon2 - lon1; final double tanphi1 = tan(lat1); final double tanU1 = (1.0 - F)*tanphi1; final double U1 = atan(tanU1); final double sinU1 = sin(U1); final double cosU1 = cos(U1); final double tanphi2 = tan(lat2); final double tanU2 = (1.0 - F)*tanphi2; final double U2 = atan(tanU2); final double sinU2 = sin(U2); final double cosU2 = cos(U2); final double sinU1sinU2 = sinU1*sinU2; final double cosU1sinU2 = cosU1*sinU2; final double sinU1cosU2 = sinU1*cosU2; final double cosU1cosU2 = cosU1*cosU2; double lambda = omega; double a; double b; double sigma; double deltasigma; double lambda0; int iteration = 0; do { lambda0 = lambda; final double sinlambda = sin(lambda); final double coslambda = cos(lambda); final double sin2sigma = (cosU2*sinlambda*cosU2*sinlambda) + (cosU1sinU2 - sinU1cosU2*coslambda)* (cosU1sinU2 - sinU1cosU2*coslambda); final double sinsigma = sqrt(sin2sigma); final double cossigma = sinU1sinU2 + (cosU1cosU2*coslambda); sigma = atan2(sinsigma, cossigma); final double sinalpha = sin2sigma == 0.0 ? 0.0 : cosU1cosU2*sinlambda/sinsigma; final double alpha = asin(sinalpha); final double cosalpha = cos(alpha); double cos2alpha = cosalpha*cosalpha; final double cos2sigmam = cos2alpha == 0.0 ? 0.0 : cossigma - 2*sinU1sinU2/cos2alpha; final double u2 = cos2alpha*AABBBB; final double cos2sigmam2 = cos2sigmam*cos2sigmam; a = 1.0 + u2/16384*(4096 + u2*(-768 + u2*(320 - 175*u2))); b = u2/1024*(256 + u2*(-128 + u2*(74 - 47*u2))); deltasigma = b*sinsigma*(cos2sigmam + b/4*(cossigma*(-1 + 2 * cos2sigmam2) - b/6*cos2sigmam*(-3 + 4*sin2sigma)*(-3 + 4*cos2sigmam2))); final double C = F/16*cos2alpha*(4 + F*(4 - 3*cos2alpha)); lambda = omega + (1 - C)*F*sinalpha* (sigma + C*sinsigma*(cos2sigmam + C*cossigma*(-1 + 2*cos2sigmam2))); } while (iteration++ < DISTANCE_ITERATION_MAX && (abs((lambda - lambda0)/lambda) > DISTANCE_ITERATION_EPSILON)); if (iteration >= DISTANCE_ITERATION_MAX) { throw new ArithmeticException(format( "Calculating distance between %s and %s didn't converge.", start, end )); } final double s = B*a*(sigma - deltasigma); return Length.of(s, Unit.METER); } }
Geoid { public Length distance(final Point start, final Point end) { final double lat1 = start.getLatitude().toRadians(); final double lon1 = start.getLongitude().toRadians(); final double lat2 = end.getLatitude().toRadians(); final double lon2 = end.getLongitude().toRadians(); final double omega = lon2 - lon1; final double tanphi1 = tan(lat1); final double tanU1 = (1.0 - F)*tanphi1; final double U1 = atan(tanU1); final double sinU1 = sin(U1); final double cosU1 = cos(U1); final double tanphi2 = tan(lat2); final double tanU2 = (1.0 - F)*tanphi2; final double U2 = atan(tanU2); final double sinU2 = sin(U2); final double cosU2 = cos(U2); final double sinU1sinU2 = sinU1*sinU2; final double cosU1sinU2 = cosU1*sinU2; final double sinU1cosU2 = sinU1*cosU2; final double cosU1cosU2 = cosU1*cosU2; double lambda = omega; double a; double b; double sigma; double deltasigma; double lambda0; int iteration = 0; do { lambda0 = lambda; final double sinlambda = sin(lambda); final double coslambda = cos(lambda); final double sin2sigma = (cosU2*sinlambda*cosU2*sinlambda) + (cosU1sinU2 - sinU1cosU2*coslambda)* (cosU1sinU2 - sinU1cosU2*coslambda); final double sinsigma = sqrt(sin2sigma); final double cossigma = sinU1sinU2 + (cosU1cosU2*coslambda); sigma = atan2(sinsigma, cossigma); final double sinalpha = sin2sigma == 0.0 ? 0.0 : cosU1cosU2*sinlambda/sinsigma; final double alpha = asin(sinalpha); final double cosalpha = cos(alpha); double cos2alpha = cosalpha*cosalpha; final double cos2sigmam = cos2alpha == 0.0 ? 0.0 : cossigma - 2*sinU1sinU2/cos2alpha; final double u2 = cos2alpha*AABBBB; final double cos2sigmam2 = cos2sigmam*cos2sigmam; a = 1.0 + u2/16384*(4096 + u2*(-768 + u2*(320 - 175*u2))); b = u2/1024*(256 + u2*(-128 + u2*(74 - 47*u2))); deltasigma = b*sinsigma*(cos2sigmam + b/4*(cossigma*(-1 + 2 * cos2sigmam2) - b/6*cos2sigmam*(-3 + 4*sin2sigma)*(-3 + 4*cos2sigmam2))); final double C = F/16*cos2alpha*(4 + F*(4 - 3*cos2alpha)); lambda = omega + (1 - C)*F*sinalpha* (sigma + C*sinsigma*(cos2sigmam + C*cossigma*(-1 + 2*cos2sigmam2))); } while (iteration++ < DISTANCE_ITERATION_MAX && (abs((lambda - lambda0)/lambda) > DISTANCE_ITERATION_EPSILON)); if (iteration >= DISTANCE_ITERATION_MAX) { throw new ArithmeticException(format( "Calculating distance between %s and %s didn't converge.", start, end )); } final double s = B*a*(sigma - deltasigma); return Length.of(s, Unit.METER); } private  Geoid(final Ellipsoid ellipsoid); }
Geoid { public Length distance(final Point start, final Point end) { final double lat1 = start.getLatitude().toRadians(); final double lon1 = start.getLongitude().toRadians(); final double lat2 = end.getLatitude().toRadians(); final double lon2 = end.getLongitude().toRadians(); final double omega = lon2 - lon1; final double tanphi1 = tan(lat1); final double tanU1 = (1.0 - F)*tanphi1; final double U1 = atan(tanU1); final double sinU1 = sin(U1); final double cosU1 = cos(U1); final double tanphi2 = tan(lat2); final double tanU2 = (1.0 - F)*tanphi2; final double U2 = atan(tanU2); final double sinU2 = sin(U2); final double cosU2 = cos(U2); final double sinU1sinU2 = sinU1*sinU2; final double cosU1sinU2 = cosU1*sinU2; final double sinU1cosU2 = sinU1*cosU2; final double cosU1cosU2 = cosU1*cosU2; double lambda = omega; double a; double b; double sigma; double deltasigma; double lambda0; int iteration = 0; do { lambda0 = lambda; final double sinlambda = sin(lambda); final double coslambda = cos(lambda); final double sin2sigma = (cosU2*sinlambda*cosU2*sinlambda) + (cosU1sinU2 - sinU1cosU2*coslambda)* (cosU1sinU2 - sinU1cosU2*coslambda); final double sinsigma = sqrt(sin2sigma); final double cossigma = sinU1sinU2 + (cosU1cosU2*coslambda); sigma = atan2(sinsigma, cossigma); final double sinalpha = sin2sigma == 0.0 ? 0.0 : cosU1cosU2*sinlambda/sinsigma; final double alpha = asin(sinalpha); final double cosalpha = cos(alpha); double cos2alpha = cosalpha*cosalpha; final double cos2sigmam = cos2alpha == 0.0 ? 0.0 : cossigma - 2*sinU1sinU2/cos2alpha; final double u2 = cos2alpha*AABBBB; final double cos2sigmam2 = cos2sigmam*cos2sigmam; a = 1.0 + u2/16384*(4096 + u2*(-768 + u2*(320 - 175*u2))); b = u2/1024*(256 + u2*(-128 + u2*(74 - 47*u2))); deltasigma = b*sinsigma*(cos2sigmam + b/4*(cossigma*(-1 + 2 * cos2sigmam2) - b/6*cos2sigmam*(-3 + 4*sin2sigma)*(-3 + 4*cos2sigmam2))); final double C = F/16*cos2alpha*(4 + F*(4 - 3*cos2alpha)); lambda = omega + (1 - C)*F*sinalpha* (sigma + C*sinsigma*(cos2sigmam + C*cossigma*(-1 + 2*cos2sigmam2))); } while (iteration++ < DISTANCE_ITERATION_MAX && (abs((lambda - lambda0)/lambda) > DISTANCE_ITERATION_EPSILON)); if (iteration >= DISTANCE_ITERATION_MAX) { throw new ArithmeticException(format( "Calculating distance between %s and %s didn't converge.", start, end )); } final double s = B*a*(sigma - deltasigma); return Length.of(s, Unit.METER); } private  Geoid(final Ellipsoid ellipsoid); Ellipsoid ellipsoid(); Length distance(final Point start, final Point end); Collector<Point, ?, Length> toPathLength(); Collector<Point, ?, Length> toTourLength(); static Geoid of(final Ellipsoid ellipsoid); }
Geoid { public Length distance(final Point start, final Point end) { final double lat1 = start.getLatitude().toRadians(); final double lon1 = start.getLongitude().toRadians(); final double lat2 = end.getLatitude().toRadians(); final double lon2 = end.getLongitude().toRadians(); final double omega = lon2 - lon1; final double tanphi1 = tan(lat1); final double tanU1 = (1.0 - F)*tanphi1; final double U1 = atan(tanU1); final double sinU1 = sin(U1); final double cosU1 = cos(U1); final double tanphi2 = tan(lat2); final double tanU2 = (1.0 - F)*tanphi2; final double U2 = atan(tanU2); final double sinU2 = sin(U2); final double cosU2 = cos(U2); final double sinU1sinU2 = sinU1*sinU2; final double cosU1sinU2 = cosU1*sinU2; final double sinU1cosU2 = sinU1*cosU2; final double cosU1cosU2 = cosU1*cosU2; double lambda = omega; double a; double b; double sigma; double deltasigma; double lambda0; int iteration = 0; do { lambda0 = lambda; final double sinlambda = sin(lambda); final double coslambda = cos(lambda); final double sin2sigma = (cosU2*sinlambda*cosU2*sinlambda) + (cosU1sinU2 - sinU1cosU2*coslambda)* (cosU1sinU2 - sinU1cosU2*coslambda); final double sinsigma = sqrt(sin2sigma); final double cossigma = sinU1sinU2 + (cosU1cosU2*coslambda); sigma = atan2(sinsigma, cossigma); final double sinalpha = sin2sigma == 0.0 ? 0.0 : cosU1cosU2*sinlambda/sinsigma; final double alpha = asin(sinalpha); final double cosalpha = cos(alpha); double cos2alpha = cosalpha*cosalpha; final double cos2sigmam = cos2alpha == 0.0 ? 0.0 : cossigma - 2*sinU1sinU2/cos2alpha; final double u2 = cos2alpha*AABBBB; final double cos2sigmam2 = cos2sigmam*cos2sigmam; a = 1.0 + u2/16384*(4096 + u2*(-768 + u2*(320 - 175*u2))); b = u2/1024*(256 + u2*(-128 + u2*(74 - 47*u2))); deltasigma = b*sinsigma*(cos2sigmam + b/4*(cossigma*(-1 + 2 * cos2sigmam2) - b/6*cos2sigmam*(-3 + 4*sin2sigma)*(-3 + 4*cos2sigmam2))); final double C = F/16*cos2alpha*(4 + F*(4 - 3*cos2alpha)); lambda = omega + (1 - C)*F*sinalpha* (sigma + C*sinsigma*(cos2sigmam + C*cossigma*(-1 + 2*cos2sigmam2))); } while (iteration++ < DISTANCE_ITERATION_MAX && (abs((lambda - lambda0)/lambda) > DISTANCE_ITERATION_EPSILON)); if (iteration >= DISTANCE_ITERATION_MAX) { throw new ArithmeticException(format( "Calculating distance between %s and %s didn't converge.", start, end )); } final double s = B*a*(sigma - deltasigma); return Length.of(s, Unit.METER); } private  Geoid(final Ellipsoid ellipsoid); Ellipsoid ellipsoid(); Length distance(final Point start, final Point end); Collector<Point, ?, Length> toPathLength(); Collector<Point, ?, Length> toTourLength(); static Geoid of(final Ellipsoid ellipsoid); static final Geoid WGS84; static final Geoid IERS_1989; static final Geoid IERS_2003; static final Geoid DEFAULT; }