numpy - How to compare great circle distance with euclidean distance of two sphere points using python? -


i trying check error introduced when compute distance of 2 points on earth euclidean distance instead of using great circle distance (gcd). have 2 points defined lattitude , longtitude. used python geopy framework great circle distance. here code gcd:

def measure(self, a, b):         a, b = point(a), point(b)          lat1, lng1 = radians(degrees=a.latitude), radians(degrees=a.longitude)         lat2, lng2 = radians(degrees=b.latitude), radians(degrees=b.longitude)          sin_lat1, cos_lat1 = sin(lat1), cos(lat1)         sin_lat2, cos_lat2 = sin(lat2), cos(lat2)          delta_lng = lng2 - lng1         cos_delta_lng, sin_delta_lng = cos(delta_lng), sin(delta_lng)          d = atan2(sqrt((cos_lat2 * sin_delta_lng) ** 2 +                        (cos_lat1 * sin_lat2 -                         sin_lat1 * cos_lat2 * cos_delta_lng) ** 2),                   sin_lat1 * sin_lat2 + cos_lat1 * cos_lat2 * cos_delta_lng)          return self.radius * d 

so or 2 points:

p1=[39.8616,-75.0748], p2=[-7.30933,112.76]

the

gcd = 78.8433004543197 klm

using great_circle(p1,p2).kilometers function geopy

i transformed these 2 points in cartesian coordinates using formula:

  def spherical_to_cartesian(r,la,lo):        x=r*np.sin(90-la)*np.cos(lo)        y=r*np.sin(90-la)*np.sin(lo)        z=r*np.cos(90-la)        return (x,y,z) 

where r=6372.795, results in following cartesians coordinates

p1=[ -765.81579368,  -256.69640558,  6321.40405587],  p2=[480.8302149,-168.64726394,-6352.39140142] 

then typing: np.linalg.norm(p2-p1) getting 1103.4963114787836 euclidean norm doesn't seem reasonable compared ~78klm gcd. inffering sth wrong?

python includes 2 functions in math package; radians converts degrees radians, , degrees converts radians degrees.

the method sin() returns sine of x, in radians.

import math def spherical_to_cartesian(r,la,lo):    rlo = math.radians(lo)    rla = math.radians(90-la)    x=r*np.sin(rla)*np.cos(rlo)    y=r*np.sin(rla)*np.sin(rlo)    z=r*np.cos(rla)    return (x,y,z) 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -