def test_circum_center_radius(): ''' circum_center_radius(): boundary, near lon=0, big triangle ''' from numpy import pi from circumcircle import circum_center_radius from sphere import angle from convert_coord.cart_ll import latlon2xyz # boundary ll1, ll2, ll3 = (0,pi/3), (0,2/3*pi), (pi/6,pi/2) xyz1, xyz2, xyz3 = [latlon2xyz(*ll) for ll in [ll1,ll2,ll3]] center, radius = circum_center_radius(xyz1, xyz2, xyz3) equal(center, (0,1,0)) # near lon=0 ll1, ll2, ll3 = (pi/5, 2*pi-pi/6), (0,pi/7), (pi/7,pi/6) xyz1, xyz2, xyz3 = [latlon2xyz(*ll) for ll in [ll1,ll2,ll3]] center, radius = circum_center_radius(xyz1, xyz2, xyz3) d1 = angle(center, xyz1) d2 = angle(center, xyz2) d3 = angle(center, xyz3) aa_equal(d1, radius, 15) aa_equal(d2, radius, 15) aa_equal(d3, radius, 15) # big triangle ll1, ll2, ll3 = (pi/2,0), (0,0), (0,pi/2) xyz1, xyz2, xyz3 = [latlon2xyz(*ll) for ll in [ll1,ll2,ll3]] center, radius = circum_center_radius(xyz1, xyz2, xyz3) aa_equal(center, latlon2xyz(0.61547970867038737,pi/4), 15)
def circum_center_radius(xyz1, xyz2, xyz3): x1, y1, z1 = xyz1 x2, y2, z2 = xyz2 x3, y3, z3 = xyz3 # bisector plane of p1 and p2 mx, my, mz = (x1+x2)/2, (y1+y2)/2, (z1+z2)/2 cx, cy, cz = y1*z2-z1*y2, z1*x2-x1*z2, x1*y2-y1*x2 a1, b1, c1 = my*cz-mz*cy, mz*cx-mx*cz, mx*cy-my*cx # plane parameters # bisector plane of p2 and p3 mx, my, mz = (x2+x3)/2, (y2+y3)/2, (z2+z3)/2 cx, cy, cz = y2*z3-z2*y3, z2*x3-x2*z3, x2*y3-y2*x3 a2, b2, c2 = my*cz-mz*cy, mz*cx-mx*cz, mx*cy-my*cx # plane parameters # intersection points cc1, cc2 = intersect_two_greatcircles((a1,b1,c1), (a2,b2,c2)) # circumcircle point mxyz = (x1+x2+x3)/2, (x2+y2+y3)/2, (x3+z2+z3)/2 d1 = angle(cc1, mxyz) d2 = angle(cc2, mxyz) cc = cc1 if d1 < d2 else cc2 dist = angle(cc,xyz1) return cc, dist
def __init__(self, latlon1, latlon2): self.latlon1 = latlon1 self.latlon2 = latlon2 self.xyz1 = latlon2xyz(*latlon1) self.xyz2 = latlon2xyz(*latlon2) self.max_angle = angle(self.xyz1, self.xyz2) # pt3 which is perpendicular with pt1 on the great circle pt1_pt2 self.xyz3 = self.get_xyz3() self.latlon3 = xyz2latlon(*self.xyz3)
def test_angle(): ''' angle(): yz plane circle, oblique circle ''' from sphere import angle from convert_coord.cart_ll import latlon2xyz ret = angle(latlon2xyz(pi/4,0), latlon2xyz(0,0)) equal(ret, pi/4) ret = angle(latlon2xyz(pi/2,0), latlon2xyz(0,0)) equal(ret, pi/2) ret = angle(latlon2xyz(0,0), latlon2xyz(0,0)) equal(ret, 0) ret = angle(latlon2xyz(pi/4,0), latlon2xyz(-pi/4,0)) aa_equal(ret, pi/2, 15) ret = angle(latlon2xyz(pi/2,0), latlon2xyz(-pi/4,0)) aa_equal(ret, 3*pi/4, 15) ret = angle(latlon2xyz(pi/2,0), latlon2xyz(-pi/2,0)) aa_equal(ret, pi, 15)
def circum_center_radius(latlon1, latlon2, latlon3, return_xyz=False): xyz1 = x1,y1,z1 = latlon2xyz(*latlon1) xyz2 = x2,y2,z2 = latlon2xyz(*latlon2) xyz3 = x3,y3,z3 = latlon2xyz(*latlon3) # bisector plane of p1 and p2 mx, my, mz = (x1+x2)/2, (y1+y2)/2, (z1+z2)/2 cx, cy, cz = y1*z2-z1*y2, z1*x2-x1*z2, x1*y2-y1*x2 a1, b1, c1 = my*cz-mz*cy, mz*cx-mx*cz, mx*cy-my*cx # plane parameters # bisector plane of p2 and p3 mx, my, mz = (x2+x3)/2, (y2+y3)/2, (z2+z3)/2 cx, cy, cz = y2*z3-z2*y3, z2*x3-x2*z3, x2*y3-y2*x3 a2, b2, c2 = my*cz-mz*cy, mz*cx-mx*cz, mx*cy-my*cx # plane parameters # intersection points cc1, cc2 = intersect_two_greatcircles((a1,b1,c1), (a2,b2,c2)) # circumcircle point mxyz = (x1+x2+x3)/2, (x2+y2+y3)/2, (x3+z2+z3)/2 d1 = angle(cc1, mxyz) d2 = angle(cc2, mxyz) #d1 = distance(cc1, mxyz) #d2 = distance(cc2, mxyz) cc = cc1 if d1 < d2 else cc2 dist = angle(cc,xyz1) if return_xyz: return cc, dist else: return xyz2latlon(*cc), dist