Last active
February 12, 2016 04:36
-
-
Save sungyongchoi/4760f925938d42572001 to your computer and use it in GitHub Desktop.
rotate points and draw plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(math.radians(angle)) | |
sin_theta = math.sin(math.radians(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]),8,(0,0))[0]) | |
# rotate x to 8 angle | |
z_rotate.append(rotate_vector((row[0],row[1]),8,(0,0))[1]) | |
# rotate z to 8 angle | |
plt.plot(x, z, 'r.') | |
plt.plot(x_rotate, z_rotate, 'r.') | |
plt.axis([-1, 30, -5,2]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment