Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import csv
- import math
- def rotate_vector(v, angle, anchor):
- """Rotate a vector `v` by the given angle, relative to the anchor point."""
- x, y = v
- x = float(x) - anchor[0]
- y = float(y) - anchor[1]
- # Here is a compiler optimization; inplace operators are slower than
- # non-inplace operators like above. This function gets used a lot, so
- # performance is critical.
- cos_theta = math.cos(angle)
- sin_theta = math.sin(angle)
- nx = x*cos_theta - y*sin_theta
- ny = x*sin_theta + y*cos_theta
- nx = nx + anchor[0]
- ny = ny + anchor[1]
- return [nx, ny]
- x=[]
- z=[]
- x_rotate=[]
- z_rotate=[]
- f= open("data.csv")
- #append values to list
- for row in csv.reader(f):
- x.append(row[0])
- z.append(row[1])
- x_rotate.append(rotate_vector((row[0],row[1]),7,(0,0))[0])
- z_rotate.append(rotate_vector((row[0],row[1]),7,(0,0))[1])
- plt.plot(x, z, 'r.')
- plt.plot(x_rotate, z_rotate, 'r.')
- plt.axis([-1, 30, -5,20 ])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement