Skip to content

Instantly share code, notes, and snippets.

@robgon-art
Created November 28, 2021 13:46
Show Gist options
  • Save robgon-art/ec5983cff11b0032854f2ff38029d7da to your computer and use it in GitHub Desktop.
Save robgon-art/ec5983cff11b0032854f2ff38029d7da to your computer and use it in GitHub Desktop.
def rotate_points(x, y, x_axis_index, y_axis_index):
num_points = len(x)
x_rotated = []
y_rotated = []
x_axis_angle = math.atan2(y[x_axis_index], x[x_axis_index])
y_axis_angle = math.atan2(y[y_axis_index], x[y_axis_index])
if math.sin(y_axis_angle - x_axis_angle) < 0:
flip_y = -1.0
else:
flip_y = 1.0
for i in range(num_points):
theta = math.atan2(y[i], x[i])
radius = math.hypot(x[i], y[i])
theta_rotated = theta - x_axis_angle
x_rotated.append(radius*math.cos(theta_rotated))
y_rotated.append(radius*math.sin(theta_rotated)*flip_y)
return(x_rotated, y_rotated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment