Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def angleBetweenTwoPoints(p1, p2):
- '''return in angle in deg'''
- #old way 0-360
- a1 = math.atan2(p1[1], p1[0])
- a2 = math.atan2(p2[1], p2[0])
- angle1 = (a1 - a2) % (2 * math.pi)
- angle1 = math.degrees(angle1)
- #print 'first way of calc angle:', angle1
- #new way seems to work better -180 - 180
- x = p2[0] - p1[0]
- y = p2[1] - p1[1]
- angle2 = math.atan2(y, x) * (180 / math.pi)
- #print 'second way:', angle2
- return round(angle2, 2)
Advertisement
Add Comment
Please, Sign In to add comment