Skip to content

Instantly share code, notes, and snippets.

@5agado
Created February 1, 2019 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 5agado/76218fa1b25f75faf44e83741ecb2e38 to your computer and use it in GitHub Desktop.
Save 5agado/76218fa1b25f75faf44e83741ecb2e38 to your computer and use it in GitHub Desktop.
from math import sin, cos
def rotate_stroke(stroke, angle, axis='z'):
# Define rotation matrix based on axis
if axis.lower() == 'x':
transform_matrix = np.array([[1, 0, 0],
[0, cos(angle), -sin(angle)],
[0, sin(angle), cos(angle)]])
elif axis.lower() == 'y':
transform_matrix = np.array([[cos(angle), 0, -sin(angle)],
[0, 1, 0],
[sin(angle), 0, cos(angle)]])
# default on z
else:
transform_matrix = np.array([[cos(angle), -sin(angle), 0],
[sin(angle), cos(angle), 0],
[0, 0, 1]])
# Apply rotation matrix to each point
for i, p in enumerate(stroke.points):
p.co = transform_matrix @ np.array(p.co).reshape(3, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment