TankorSmash

Untitled

Feb 11th, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. def angleBetweenTwoPoints(p1, p2):
  2.     '''return in angle in deg'''
  3.     #old way 0-360
  4.     a1 = math.atan2(p1[1], p1[0])
  5.     a2 = math.atan2(p2[1], p2[0])
  6.     angle1 = (a1 - a2) % (2 * math.pi)
  7.     angle1 = math.degrees(angle1)
  8.     #print 'first way of calc angle:', angle1
  9.    
  10.     #new way seems to work better -180 - 180
  11.     x = p2[0] - p1[0]
  12.     y = p2[1] - p1[1]
  13.     angle2 = math.atan2(y, x) * (180 / math.pi)
  14.     #print 'second way:', angle2
  15.    
  16.     return round(angle2, 2)
Advertisement
Add Comment
Please, Sign In to add comment