jhylands

Rotate ship

Aug 31st, 2014
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. import math
  2.  
  3. #rotation function
  4. def rotate(coordinates,angle):
  5. #convert the coordinates from dictionary to integers
  6.     x = coordinates['x']
  7.     y = coordinates['y']
  8.     #apply the rotation matrix
  9.     Xn = x * math.cos(angle) - y * math.cos(angle)
  10.     Yn = x * math.sin(angle) + y * math.cos(angle)
  11.     #return the new coordinates in dictionary format
  12.     return {'x': Xn , 'y': Yn}
  13. AircraftCarrier = [{'x':0,'y':0},{'x':0,'y':-1},{'x':0,'y':-2},{'x':0,'y':-3},{'x':-1,'y':-3},{'x':1,'y':-3}]
  14. for panel in AircraftCarrier:
  15.     print rotate(panel,(math.pi*3/2))
Advertisement
Add Comment
Please, Sign In to add comment