For my school assignment I need to create a function to find Euclidean distance using Cartesian points that are found using a different function.
I got the error
polar_to_cartesian() missing 1 required positional argument: 'R'
Any help is appreciated I feel so dumb and confused
What I have tried:
def polar_to_cartesian(latlon:tuple, R: float):
"""
Description: Takes in a tuple 'latlon' (latitude and longitude, in radians) and the float 'R' (nonnegative radius of the sphere), returning the cartesian coordinates of the points.
>>> polar_to_cartesian((99, 34), 300)
(-10.137244625211233, 6.320561508619837, -299.7620502559061)
>>> polar_to_cartesian((22, 56), 4000)
(-3412.746736059186, 2086.122284215118, -35.4052371616155)
"""
import math
(lat, lon) = latlon
x = R * math.cos(lat) * math.cos(lon)
y = R * math.cos(lat) * math.sin(lon)
z = R * math.sin(lat)
return (x, y, z)
# Problem 5.
def distance_Euclidean(points:list, R: float):
"""
Description: Takes in a list 'points' (2 latitudes, 2 longitudes, all in radians) and the float 'R' (nonnegative radius of the sphere), returning the Euclidean distance between the two points.
>>> distance_Euclidean([(10, 60),(70, 80)], 2000)
63.245553203367585
>>> distance_Euclidean([(40, 700),(600, 70)], 1000)
842.9116205154606
"""
import math
[(lat1, lon1), (lat2, lon2)] = points
lat1 = lat1 * (math.pi/180)
lon1 = lon1 * (math.pi/180)
lat2 = lat2 * (math.pi/180)
lon2 = lon2 * (math.pi/180)
(x1, y1, z1) = polar_to_cartesian((points[0], R))
(x2, y2, z2) = polar_to_cartesian((points[1], R))
#return math.sqrt((lon2 - lon1)**2 + (lat2 - lat1)**2)
return math.sqrt((x1 - x2)**2 + (y1 - y2)**2 + + (z1 - z2)**2)