public class GreatCircle {
|
public static void main(String[] args) {
|
double x1 = Double.parseDouble(args[0]);
|
double y1 = Double.parseDouble(args[1]);
|
double x2 = Double.parseDouble(args[2]);
|
double y2 = Double.parseDouble(args[3]);
|
|
double r = 6371.0; // Earth radius
|
|
double dx = Math.toRadians(x2 - x1) / 2.0;
|
double dy = Math.toRadians(y2 - y1) / 2.0;
|
|
double under = Math.sin(dx) * Math.sin(dx) +
|
Math.cos(Math.toRadians(x1)) * Math.cos(Math.toRadians(x2))
|
* Math.sin(dy) * Math.sin(dy);
|
|
double distance = 2.0 * r * Math.asin(Math.sqrt(under));
|
|
System.out.println(distance + " kilometers");
|
}
|
}
|