def angleOfVector(p1, v, p2):
"""
Accepts p1, v, and p2 of class Point or coordinate pairs
Returns the angle in radians between the vector v-to-p1 and vector v-to-p2
"""
#L1=distance(p1, p2)
#L2=distance(p1, p3)
#L3=distance(p2, p3)
#return math.acos((L1**2+L2**2-L3**2)/(2*L1*L2))
p1 = dPnt(p1)
p2 = dPnt(p2)
angle1 = angleOfLine(v, p1)
angle2 = angleOfLine(v, p2)
#get the absolute angle
angle = abs(angle1 - angle2)
#get the smallest angle of the vector, should not be greater than a straight line
if angle > pi:
angle = 2*pi - angle
return angle
评论列表
文章目录