验证 2 LineString(形状)是否平行

Verify if 2 LineString (shapely) are parallel

我有2个shapely.LineString,我想验证它们是否平行

a = LineString(((0, 0), (0  , 1)))
b = LineString(((1, 0), (0.9, 1))) #Not intersecting, but also not parallel)

当我使用相交时,intersects,它returns False因为两条线不相交,但也不平行。

Shapely中有没有验证并行度的方法?我可以使用角度(通过 np.arctan)。

我想到的最好的:

def isparrallel(ls1, ls2):
    xs1, xe1 = ls1.xy[0]
    ys1, ye1 = ls1.xy[1]
    xs2, xe2 = ls2.xy[0]
    ys2, ye2 = ls2.xy[1]

    if xs1 == xe1:
        angle1 = np.pi/2
    else:
        angle1 = np.arctan((ye1-ys1)/(xe1-xs1))
    if xs2 == xe2:
        angle2 = np.pi/2
    else:
        angle2 = np.arctan((ye2-ys2)/(xe2-xs2))

    return True if angle1 == angle2 else False

>> isparrallel(a,b)
True

欢迎改进:-)

a = [(0,1), (0,0)]
b = [(0,0), (0,-1)]
c = [(2,1), (2,0)]

def is_parallel(line1, line2):
    vector_a_x = line1[1][0] - line1[0][0]
    vector_a_y = line1[1][1] - line1[0][1]
    vector_b_x = line2[1][0] - line2[0][0]
    vector_b_y = line2[1][1] - line2[0][1]
    
    if vector_a_x * vector_b_y == vector_a_y * vector_b_x:
        return True 
    else:
        return False 

is_parallel(a, b) 
# True