{"id":5527,"library":"transforms3d","title":"3D Coordinate Transformations","description":"transforms3d is a Python library providing a collection of functions and classes for creating and converting 3-dimensional transformations, including rotations, zooms, shears, and reflections. It is largely based on the `transformations.py` module by Christoph Gohlke, with significant restructuring and ongoing maintenance by Matthew Brett. The library is currently at version 0.4.2 and sees active maintenance for bugfixes and compatibility updates, particularly with NumPy.","status":"active","version":"0.4.2","language":"en","source_language":"en","source_url":"https://github.com/matthew-brett/transforms3d","tags":["3D","transformations","quaternions","euler angles","matrices","robotics","geometry","scientific computing"],"install":[{"cmd":"pip install transforms3d","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core dependency for numerical array operations.","package":"numpy","optional":false}],"imports":[{"symbol":"euler2mat","correct":"from transforms3d.euler import euler2mat"},{"symbol":"mat2quat","correct":"from transforms3d.quaternions import mat2quat"},{"symbol":"axangle2mat","correct":"from transforms3d.axangles import axangle2mat"}],"quickstart":{"code":"import numpy as np\nfrom transforms3d.euler import euler2mat, mat2euler\nfrom transforms3d.quaternions import mat2quat, quat2mat\n\n# Define Euler angles (roll, pitch, yaw) in radians\nr, p, y = np.deg2rad(30), np.deg2rad(45), np.deg2rad(60)\n\n# Convert Euler angles to a 3x3 rotation matrix\nrotation_matrix = euler2mat(r, p, y, axes='sxyz')\nprint(\"Rotation Matrix:\\n\", rotation_matrix)\n\n# Convert rotation matrix to a quaternion (w, x, y, z order)\nquaternion = mat2quat(rotation_matrix)\nprint(\"Quaternion (w, x, y, z): \", quaternion)\n\n# Convert quaternion back to rotation matrix\nreconstructed_matrix = quat2mat(quaternion)\nprint(\"Reconstructed Matrix:\\n\", reconstructed_matrix)\n\n# Verify accuracy\nassert np.allclose(rotation_matrix, reconstructed_matrix)","lang":"python","description":"This quickstart demonstrates converting Euler angles to a rotation matrix, then converting that matrix to a quaternion, and finally reconstructing the matrix from the quaternion. This covers common transformations and module imports from `transforms3d` while leveraging `numpy` for array handling. The `axes` argument in `euler2mat` specifies the order and type of Euler angles (e.g., 'sxyz' for static XYZ)."},"warnings":[{"fix":"Ensure input quaternions are normalized before passing them to `transforms3d` functions, or be aware of the automatic normalization behavior.","message":"In version 0.3, the calculation of quaternion to axis-angle changed. Quaternions are now normalized to unit quaternions on input, which may produce different results for code relying on previously unnormalized quaternions.","severity":"breaking","affected_versions":"0.3 and later"},{"fix":"Manually reorder quaternion components or map them correctly when converting between `tf.transformations` and `transforms3d` APIs.","message":"When migrating from `tf.transformations` (used in ROS 1) to `transforms3d` (recommended for ROS 2), be aware that the quaternion order is different. `tf.transformations` uses `x, y, z, w`, whereas `transforms3d` uses `w, x, y, z`. This requires careful adjustment of quaternion components.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Prefer using `float64` (default NumPy float type) for array inputs to Euler angle functions to ensure numerical stability and correctness.","message":"Some Euler angle functions may not work correctly or as expected with `float32` NumPy arrays, leading to potential precision or calculation errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Thoroughly consult the `transforms3d` documentation, especially sections on 'Conventions for transforms' and 'Naming conventions', to ensure correct application of functions for specific transformation needs.","message":"The library is built upon specific conventions for 3D transformations, including rotation orders (e.g., 'sxyz', 'rzyx'), axis definitions, and gimbal lock considerations. Misunderstanding these conventions can lead to incorrect transformation results.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Migrate existing code from `transformations.py` to `transforms3d` to benefit from ongoing development, bug fixes, and compatibility with newer Python and NumPy versions.","message":"The original `transformations.py` module by Christoph Gohlke, from which `transforms3d` is derived, is no longer actively developed and has known issues and numerical instabilities. `transforms3d` is the recommended, actively maintained alternative.","severity":"deprecated","affected_versions":"Users of `transformations.py`"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}