"""Contains transforms for spatially manipulating the root system.
This module defines the spatial transforms needed for
manipulating the root system using affline transformation matrices.
"""
import numpy as np
[docs]
def get_x_rotation_matrix(theta: float) -> np.ndarray:
"""
Construct a rotation matrix for the x axis.
Args:
theta (float):
The x rotation angle in degrees.
Returns:
np.ndarray:
The x rotation matrix.
"""
cos = np.cos(np.radians(theta))
sin = np.sin(np.radians(theta))
x_rotate = np.eye(4)
x_rotate[1:3, 1:3] = np.array([[cos, sin], [-sin, cos]])
return x_rotate
[docs]
def get_y_rotation_matrix(theta: float) -> np.ndarray:
"""
Construct a rotation matrix for the y axis.
Args:
theta (float):
The y rotation angle in degrees.
Returns:
np.ndarray:
The y rotation matrix.
"""
cos = np.cos(np.radians(theta))
sin = np.sin(np.radians(theta))
y_rotate = np.eye(4)
y_rotate[0, 0:3] = [cos, 0, -sin]
y_rotate[2, 0:3] = [sin, 0, cos]
return y_rotate
[docs]
def get_z_rotation_matrix(theta: float) -> np.ndarray:
"""
Construct a rotation matrix for the z axis.
Args:
theta (float):
The z rotation angle in degrees.
Returns:
np.ndarray:
The z rotation matrix.
"""
cos = np.cos(np.radians(theta))
sin = np.sin(np.radians(theta))
z_rotate = np.eye(4)
z_rotate[0:2, 0:2] = np.array([[cos, sin], [-sin, cos]])
return z_rotate
[docs]
def make_homogenous(arr: np.array) -> np.ndarray:
"""
Adds an additional 'W' dimension of ones to the array.
Performs a conversion from Cartesian coordinates to homogenous coordinates.
Args:
arr (float):
The array of Cartesian coordinates.
Returns:
np.ndarray:
The homogenous array.
"""
ones = np.ones((len(arr), 1))
homogenous_coordinates = np.hstack((arr, ones)).T
return homogenous_coordinates