2

以下に示すように、Java で Haversine 式を使用して、大円のキロメートル単位の距離を計算しようとしています。

/* Program to demonstrate the Floating-point numbers and the Math library.
 * The great-circle distance is the length of the shortest path between two points (x1,y1) and (x2,y2) on the surface of a sphere, where the path is constrained to be along the surface.*/
public class GreatCircle 
{
    public static void main(String[] args) 
    {
        double r = 6371.0; // Equatorial radius of the Earth
        double x1 = Math.toRadians(Double.parseDouble(args[0]));
        double y1 = Math.toRadians(Double.parseDouble(args[1]));
        double x2 = Math.toRadians(Double.parseDouble(args[2]));
        double y2 = Math.toRadians(Double.parseDouble(args[3]));

        // Compute using Haversine formula
        double distance = 2 * r * Math.asin(Math.sqrt(Math.pow(Math.sin((x2 - x1) / 2),2 + Math.cos(x2) * Math.pow(Math.sin((y2 - y1) / 2),2)));

        // Output the distance
        System.out.println(distance + " kilometers ");
    }
}

input で実行していますjava GreatCircle 60.0 15.0 120.0 105.0。期待される出力は ですが4604.53989281927 kilometers、得られ13406.238676180266 kilometersます。誰かが私が間違っているところを指摘してもらえますか?

4

3 に答える 3