Ejemplo n.º 1
0
def test_intersect_two_greatcircles():
    '''
    intersect_two_greatcircles(): axis circles, oblique circles, identical
    '''

    from sphere import plane_origin, intersect_two_greatcircles
    from convert_coord.cart_ll import latlon2xyz


    #---------------------------------------
    # axis circles
    #---------------------------------------
    xyz1 = (1,0,0)
    xyz2 = (0,1,0)
    xyz3 = (0,0,1)

    # x axis
    plane1 = plane_origin(xyz1, xyz2)
    plane2 = plane_origin(xyz1, xyz3)
    ret = intersect_two_greatcircles(plane1, plane2)
    equal(ret, [(1,0,0), (-1,0,0)])

    # y axis
    plane1 = plane_origin(xyz1, xyz2)
    plane2 = plane_origin(xyz2, xyz3)
    ret = intersect_two_greatcircles(plane1, plane2)
    equal(ret, [(0,1,0), (0,-1,0)])

    # z axis
    plane1 = plane_origin(xyz1, xyz3)
    plane2 = plane_origin(xyz2, xyz3)
    ret = intersect_two_greatcircles(plane1, plane2)
    equal(ret, [(0,0,1), (0,0,-1)])


    #---------------------------------------
    # oblique circles
    #---------------------------------------
    xyz1 = (0, 0, 1)
    xyz2 = latlon2xyz(pi/4, pi/4)
    xyz3 = (1,0,0)

    plane1 = plane_origin(xyz1, xyz2)
    plane2 = plane_origin(xyz2, xyz3)

    ret = intersect_two_greatcircles(plane1, plane2)
    aa_equal(ret, [xyz2, latlon2xyz(-pi/4, 5*pi/4)], 15)


    #---------------------------------------
    # identical
    #---------------------------------------
    xyz1 = (0, 0, 1)
    xyz2 = latlon2xyz(pi/4, pi/4)
    plane = plane_origin(xyz1, xyz2)
    ret = intersect_two_greatcircles(plane, plane)
    equal(ret, [None, None])
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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