Created
February 1, 2019 15:51
-
-
Save 5agado/76218fa1b25f75faf44e83741ecb2e38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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