Here you can find the source of distVincentyRAD(double lat1, double lon1, double lat2, double lon2)
public static double distVincentyRAD(double lat1, double lon1, double lat2, double lon2)
//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); } }