Java Distance Calculate distVincentyRAD(double lat1, double lon1, double lat2, double lon2)

Here you can find the source of distVincentyRAD(double lat1, double lon1, double lat2, double lon2)

Description

Calculates the great circle distance using the Vincenty Formula, simplified for a spherical model.

License

Apache License

Declaration

public static double distVincentyRAD(double lat1, double lon1, double lat2, double lon2) 

Method Source Code

//package com.java2s;
/*/*from ww  w. ja v a  2  s.c om*/
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Calculates the great circle distance using the Vincenty Formula, simplified for a spherical model. This formula
     * is accurate for any pair of points. The equation
     * was taken from <a href="http://en.wikipedia.org/wiki/Great-circle_distance">Wikipedia</a>.
     * <p>
     * The arguments are in radians, and the result is in radians.
     */
    public static double distVincentyRAD(double lat1, double lon1, double lat2, double lon2) {
        // Check for same position
        if (lat1 == lat2 && lon1 == lon2)
            return 0.0;

        double cosLat1 = Math.cos(lat1);
        double cosLat2 = Math.cos(lat2);
        double sinLat1 = Math.sin(lat1);
        double sinLat2 = Math.sin(lat2);
        double dLon = lon2 - lon1;
        double cosDLon = Math.cos(dLon);
        double sinDLon = Math.sin(dLon);

        double a = cosLat2 * sinDLon;
        double b = cosLat1 * sinLat2 - sinLat1 * cosLat2 * cosDLon;
        double c = sinLat1 * sinLat2 + cosLat1 * cosLat2 * cosDLon;

        return Math.atan2(Math.sqrt(a * a + b * b), c);
    }
}

Related

  1. distSquareVec3(final float[] v1, final float[] v2)
  2. distSymbol(int dist)
  3. distToRectNode(double[] point, double[] nodeCenter, double nodeRadius)
  4. distUndermod(double a, double b, double mod)
  5. distVector(double[] vector1, double[] vector2)
  6. getDistance(double lat1, double lng1, double lat2, double lng2)
  7. sqrDistance(float x1, float y1, float x2, float y2)
  8. squaredDistance(float[] p, int a, int b)
  9. squaredEuclideanDistance(double[] x, double[] y)