(Geometry: great circle distance) 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. Note that you need to convert the degrees into radians using the math.radians function since the Python trigonometric functions use radians. The latitude and longitude degrees in the formula are for north and west Use negative to indicate south and east degrees. Here is a sample run:
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
#importing math module
import math
#Taking input as latitude and longitude in degrees
print("Enter the side:")
print("Enter point 1 (latitude and longitude) in degrees: ")
x1 = math.radians(float(input()))
y1 = math.radians(float(input()))
print("Enter point 2 (latitude and longitude) in degrees: ")
x2 = math.radians(float(input()))
y2 = math.radians(float(input()))
#formula for the distance between two points
distance = 6371.01 * math.acos(math.sin(x1) * math.sin(x2)
+ math.cos(x1) * math.cos(x2) * math.cos(y1 - y2))
#Display the result
print("The distance between the two points is ",distance,"km")
Output:
Enter the side:
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
>