Java Distance Calculate calcDistanceHubery(double lat1, double lng1, double lat2, double lng2, int type)

Here you can find the source of calcDistanceHubery(double lat1, double lng1, double lat2, double lng2, int type)

Description

calc Distance Hubery

License

Open Source License

Declaration

public static double calcDistanceHubery(double lat1, double lng1, double lat2, double lng2, int type) 

Method Source Code

//package com.java2s;

public class Main {
    private static final double BESSEL_A = 6377397.155;
    private static final double BESSEL_E2 = 0.00667436061028297;
    private static final double BESSEL_MNUM = 6334832.10663254;
    public static final double GRS80_A = 6378137.000;
    private static final double GRS80_E2 = 0.00669438002301188;
    private static final double GRS80_MNUM = 6335439.32708317;
    private static final double WGS84_A = 6378137.000;
    private static final double WGS84_E2 = 0.00669437999019758;
    private static final double WGS84_MNUM = 6335439.32729246;
    private static final int BESSEL = 0;
    public static final int GRS80 = 1;
    private static final int WGS84 = 2;

    public static double calcDistanceHubery(double lat1, double lng1, double lat2, double lng2, int type) {
        switch (type) {
        case BESSEL:
            return calcDistOfHubeny(lat1, lng1, lat2, lng2, BESSEL_A, BESSEL_E2, BESSEL_MNUM);
        case WGS84:
            return calcDistOfHubeny(lat1, lng1, lat2, lng2, WGS84_A, WGS84_E2, WGS84_MNUM);
        case GRS80:
            return calcDistOfHubeny(lat1, lng1, lat2, lng2, GRS80_A, GRS80_E2, GRS80_MNUM);
        default:/*  w ww  .j a v  a  2  s . co m*/
            return -1.0;
        }
    }

    public static double calcDistOfHubeny(double lat1, double lng1, double lat2, double lng2, double a, double e2,
            double mnum) {
        double my = convertDegToRad((lat1 + lat2) / 2.0);
        double dy = convertDegToRad(lat1 - lat2);
        double dx = convertDegToRad(lng1 - lng2);

        double sin = Math.sin(my);
        double w = Math.sqrt(1.0 - e2 * sin * sin);
        double m = mnum / (w * w * w);
        double n = a / w;

        double dym = dy * m;
        double dxncos = dx * n * Math.cos(my);

        return Math.sqrt(dym * dym + dxncos * dxncos);
    }

    public static double convertDegToRad(double deg) {
        return deg * Math.PI / 180.0;
    }
}

Related

  1. calcDistance(double lon1, double lat1, double lon2, double lat2)
  2. calcDistance(final int coordinate1, final int coordinate2)
  3. calcDistance(int ax, int ay, int bx, int by)
  4. calcDistance(int x1, int y1, int x2, int y2)
  5. calcDistanceBetweenCoords(double startLat, double startLon, double endLat, double endLon)
  6. calcDistanceIfAccel(double startVelocity, double accel, double targetVelocity, double duration)
  7. calcDistanceToStop(double startingVelocity, double maxDeceleration)
  8. calculateDistance(double lat1, double lng1, double lat2, double lng2)
  9. calculateDistance(Double lng1, Double lat1, Double lng2, Double lat2)