A simple Python library for creating homogeneous transformation matrices for 3D transformations, including rotation, translation, and scaling. This library is built using NumPy and SciPy for efficient numerical computations.
- Generate homogeneous rotation matrices from
scipy.spatial.transform.Rotationinstance. - Create homogeneous translation matrices from 3D translation vectors.
- Construct homogeneous scaling matrices from 3D scale vectors.
- Easy-to-use functions for common transformation operations.
Install the package:
pip install homogeneous-transformimport numpy as np
from homogeneous_transform import rh, th, sh
from scipy.spatial.transform import Rotation as RConvert a rotation instance (e.g., 45 degrees around the Z-axis) into a 4x4 homogeneous matrix:
rotation = R.from_euler('z', 45, degrees=True) # Rotation around Z-axis
rotation_matrix = rh(rotation)
print("Homogeneous Rotation Matrix:")
print(rotation_matrix)Output:
Homogeneous Rotation Matrix:
[[ 0.70710678 -0.70710678 0. 0. ]
[ 0.70710678 0.70710678 0. 0. ]
[ 0. 0. 1. 0. ]
[ 0. 0. 0. 1. ]]
Convert a translation vector (e.g., ([1, 2, 3])) into a 4x4 homogeneous matrix:
translation_vector = [1, 2, 3]
translation_matrix = th(translation_vector)
print("Homogeneous Translation Matrix:")
print(translation_matrix)Output:
Homogeneous Translation Matrix:
[[1. 0. 0. 1.]
[0. 1. 0. 2.]
[0. 0. 1. 3.]
[0. 0. 0. 1.]]
Convert a scale vector (e.g., ([2, 3, 4])) into a 4x4 homogeneous matrix:
scale_vector = [2, 3, 4]
scaling_matrix = sh(scale_vector)
print("Homogeneous Scaling Matrix:")
print(scaling_matrix)Output:
Homogeneous Scaling Matrix:
[[2. 0. 0. 0.]
[0. 3. 0. 0.]
[0. 0. 4. 0.]
[0. 0. 0. 1.]]
- Description: Converts a
scipy.spatial.transform.Rotationinstance into a 4x4 homogeneous rotation matrix. - Parameters:
rotation_instance: Ascipy.spatial.transform.Rotationobject.
- Returns: A
numpy.ndarrayrepresenting the 4x4 rotation matrix.
- Description: Converts a 3D translation vector into a 4x4 homogeneous translation matrix.
- Parameters:
translation_vector: A 3-element list, tuple, or NumPy array representing x, y, z.
- Returns: A
numpy.ndarrayrepresenting the 4x4 translation matrix.
- Description: Converts a 3D scale vector into a 4x4 homogeneous scaling matrix.
- Parameters:
scale_vector: A 3-element list, tuple, or NumPy array representing sx, sy, sz.
- Returns: A
numpy.ndarrayrepresenting the 4x4 scaling matrix.
This project is licensed under the GNU GENERAL PUBLIC License. See the LICENSE file for details.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a clear description of the changes.