Answer to Question #262386 in Python for Sam

Question #262386

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

1
Expert's answer
2021-11-07T10:12:18-0500
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS