python点到向量的距离,夹角


import numpy as np

def angle(v1, v2):
    dx1 = v1[2] - v1[0]
    dy1 = -(v1[3] - v1[1])
    dx2 = v2[2] - v2[0]
    dy2 = -(v2[3] - v2[1])
    angle1 = math.atan2(dy1, dx1)
    angle1 = -int(angle1 * 180 / math.pi)
    if angle1 < 0:
        angle1 = 360 + angle1

    # print(angle1)
    angle2 = math.atan2(dy2, dx2)
    angle2 = - int(angle2 * 180 / math.pi)
    if angle2 < 0:
        angle2 = 360 + angle2

    print(angle1, angle2)

    included_angle = angle1 - angle2
    if abs(included_angle) > 180:
        included_angle = included_angle / abs(included_angle) * (360 - abs(included_angle))
    else:
        included_angle *= -1
    return included_angle

if __name__ == '__main__':
    import math

    AB = [2, 5, 4, 1]
    CD = [2, 5, 5, 3]
    ang1 = angle(AB, CD)
    print("AB和CD的夹角")
    print(ang1)
    ang1 = angle(CD, AB)
    print("CD和AB的夹角")
    print(ang1)

    dis_long=np.sqrt((CD[3]-CD[1])**2+(CD[2]-CD[0])**2)

    print(dis_long)

    dis2= (ang1 / 180 * math.pi)*dis_long

    print(abs(dis2))




上一篇:Google Earth Engine ——MCD19A2 V6数据产品是MODIS Terra和Aqua结合的大气校正多角度实施(MAIAC)陆地气溶胶光学深度(AOD)网格化2级产品,1公里分辨率


下一篇:魔方还原算法学习笔记