Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import csv
  3. import math
  4. def rotate_vector(v, angle, anchor):
  5. """Rotate a vector `v` by the given angle, relative to the anchor point."""
  6. x, y = v
  7.  
  8. x = float(x) - anchor[0]
  9. y = float(y) - anchor[1]
  10. # Here is a compiler optimization; inplace operators are slower than
  11. # non-inplace operators like above. This function gets used a lot, so
  12. # performance is critical.
  13.  
  14. cos_theta = math.cos(angle)
  15. sin_theta = math.sin(angle)
  16.  
  17. nx = x*cos_theta - y*sin_theta
  18. ny = x*sin_theta + y*cos_theta
  19.  
  20. nx = nx + anchor[0]
  21. ny = ny + anchor[1]
  22. return [nx, ny]
  23.  
  24. x=[]
  25. z=[]
  26. x_rotate=[]
  27. z_rotate=[]
  28.  
  29. f= open("data.csv")
  30. #append values to list
  31. for row in csv.reader(f):
  32. x.append(row[0])
  33. z.append(row[1])
  34. x_rotate.append(rotate_vector((row[0],row[1]),7,(0,0))[0])
  35. z_rotate.append(rotate_vector((row[0],row[1]),7,(0,0))[1])
  36. plt.plot(x, z, 'r.')
  37. plt.plot(x_rotate, z_rotate, 'r.')
  38.  
  39. plt.axis([-1, 30, -5,20 ])
  40. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement