The great circle distance is the distance between two points on the surface of a sphere.
Let (x1, y1) and (x2, y2) be the geographical latitude and longitude of two points.
The great circle distance between the two points can be computed using the following formula:
d = radius * arccos(sin(x1) * sin(x2) + cos(x1) * cos(x2) * cos(y1 - y2))
Write a program that prompts the user to enter the latitude and longitude of two points on the earth in degrees and displays its great circle distance.
The average earth radius is 6,371.01 km.
The angles as given in the formula are all in degrees.
Use negative values
for south and east degrees, positive values for north and west degrees.
Do all you can to make your program structure when running, conform with the sample run given below:
Enter point 1 (latitude and longitude) in degrees:
39.55, -116.25
Enter point 2 (latitude and longitude) in degrees:
41.5, 87.37
The distance between the two points is 10691.79183231593 km
import math
n=(input("Enter latitude separated by , : "))
a1,b1=n.split(",")
x1=int(a1)
y1=int(b1)
n2=(input("Enter longitude separated by , : "))
a2,b2=n.split(",")
x2=int(a1)
y2=int(b1)
radius=eval(input("Enter radius: "))
d = radius * math.acos(math.sin(x1) * math.sin(x2) + math.cos(x1) * math.cos(x2) * math.cos(y1 - y2))
print("The great circle distance between the two points = ",d)
Comments
Leave a comment