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))