3D transformations for Python with comprehensive rotation representations, coordinate conversions, and visualization tools
npx @tessl/cli install tessl/pypi-pytransform3d@3.14.0A comprehensive Python library for 3D transformations including rotations, translations, and coordinate conversions. pytransform3d provides complete mathematical support for spatial transformations with multiple representation formats, batch processing capabilities, uncertainty handling, and visualization tools for robotics, computer vision, and 3D graphics applications.
pip install pytransform3d or pip install 'pytransform3d[all]' for all optional dependenciesimport pytransform3dFor working with rotations:
import pytransform3d.rotations as pr
from pytransform3d.rotations import matrix_from_euler, quaternion_from_matrixFor working with transformations:
import pytransform3d.transformations as pt
from pytransform3d.transformations import transform_from, concatFor transform management:
from pytransform3d.transform_manager import TransformManagerimport numpy as np
import pytransform3d.rotations as pr
import pytransform3d.transformations as pt
from pytransform3d.transform_manager import TransformManager
# Create rotation from Euler angles (XYZ convention)
euler_angles = [0.1, 0.2, 0.3] # roll, pitch, yaw in radians
R = pr.matrix_from_euler(euler_angles, 0, 1, 2, True) # XYZ extrinsic
# Convert rotation matrix to quaternion
q = pr.quaternion_from_matrix(R)
# Create transformation matrix from rotation and translation
p = [1.0, 2.0, 3.0] # translation vector
T = pt.transform_from(R, p)
# Use TransformManager for complex transformation chains
tm = TransformManager()
tm.add_transform("base", "link1", T)
tm.add_transform("link1", "end_effector", pt.transform_from(np.eye(3), [0.5, 0, 0]))
# Get transformation from base to end effector
base_to_end = tm.get_transform("base", "end_effector")pytransform3d is organized around mathematical foundations for 3D transformations:
The library provides extensive conversion functions between all representation formats and maintains mathematical precision for robotics and computer vision applications.
Complete system for representing and converting between rotation formats including matrices, quaternions, axis-angles, Euler angles, Modified Rodrigues Parameters, and geometric algebra rotors.
def matrix_from_euler(e, i, j, k, extrinsic): ...
def quaternion_from_matrix(R): ...
def axis_angle_from_quaternion(q): ...
def euler_from_matrix(R, i, j, k, extrinsic, strict_check=True): ...Homogeneous transformations combining rotation and translation with support for multiple representations and composition operations.
def transform_from(R, p, strict_check=True): ...
def concat(*transforms): ...
def invert_transform(A2B): ...
def transform(A2B, PA): ...Optimized vectorized operations for processing arrays of rotations and transformations with significant performance improvements over iterative approaches.
def matrices_from_quaternions(Q): ...
def batch_concatenate_quaternions(Q1, Q2): ...
def transforms_from_pqs(pqs): ...
def invert_transforms(A2B): ...Optimized batch operations specifically for rotation representations with significant performance improvements for processing arrays of orientations.
def matrices_from_quaternions(Q): ...
def batch_concatenate_quaternions(Q1, Q2): ...
def active_matrices_from_intrinsic_euler_angles(e, i, j, k): ...
def quaternion_slerp_batch(start, end, t): ...Batch operations on 3D trajectories (SE(3)) using dual quaternions, position-quaternions, and exponential coordinates for high-performance trajectory processing.
def invert_transforms(A2B): ...
def concat_many_to_many(A2B, B2C): ...
def dual_quaternions_sclerp(start, end, t): ...
def transforms_from_pqs(pqs): ...Graph-based system for managing complex transformation chains with automatic path finding and temporal support.
class TransformManager:
def add_transform(self, from_frame, to_frame, A2B): ...
def get_transform(self, from_frame, to_frame): ...
def plot_frames_in(self, frame, ax=None, **kwargs): ...Camera-related transformations including world-to-image projection, coordinate system conversions, and camera pose visualization.
def world2image(P_world, cam2world, sensor_size, image_size, focal_length, **kwargs): ...
def cam2sensor(P_cam, focal_length, kappa=0.0): ...
def plot_camera(ax=None, cam2world=None, **kwargs): ...Conversions between Cartesian, cylindrical, and spherical coordinate systems for position representation.
def cartesian_from_spherical(p): ...
def spherical_from_cartesian(p): ...
def cylindrical_from_cartesian(p): ...Loading and managing robot kinematic chains from URDF files with joint control and visualization.
class UrdfTransformManager(TransformManager):
def load_urdf(self, urdf_xml, mesh_path=None, package_dir=None): ...
def set_joint(self, joint_name, value): ...
def plot_visuals(self, frame, ax=None, **kwargs): ...Operations on uncertain transformations with statistical estimation, covariance propagation, and sensor fusion.
def pose_fusion(poses, covariances, check_inputs=True): ...
def concat_uncertain_transforms(A2B, cov_A2B, B2C, cov_B2C): ...
def frechet_mean(poses, weights=None, **kwargs): ...3D plotting and visualization tools using matplotlib and Open3D backends for transformations, trajectories, and geometric objects.
def plot_transform(ax=None, A2B=None, s=1.0, **kwargs): ...
def plot_trajectory(P=None, show_direction=True, **kwargs): ...
class Figure: # Open3D-based 3D visualization
def add(self, artist): ...
def show(self): ...Matplotlib-based plotting utilities for 3D geometric shapes, coordinate frames, and visualization objects commonly used in robotics applications.
def plot_box(ax=None, size=[1, 1, 1], A2B=None, **kwargs): ...
def plot_sphere(ax=None, radius=1.0, p=[0, 0, 0], **kwargs): ...
def plot_cylinder(ax=None, length=1.0, radius=1.0, A2B=None, **kwargs): ...
class LabeledFrame: ...GUI tools for visual transformation editing using PyQt with real-time 3D visualization and parameter adjustment.
class TransformEditor(QMainWindow):
def __init__(self, transform_manager, base_frame, **kwargs): ...
def show(self): ...# Rotation representations
RotationMatrix = np.ndarray # shape (3, 3)
Quaternion = np.ndarray # shape (4,) - [w, x, y, z] or [x, y, z, w]
AxisAngle = np.ndarray # shape (4,) - [x, y, z, angle]
CompactAxisAngle = np.ndarray # shape (3,) - [x*angle, y*angle, z*angle]
EulerAngles = np.ndarray # shape (3,) - [angle1, angle2, angle3]
# Transformation representations
Transform = np.ndarray # shape (4, 4) - homogeneous transformation matrix
PositionQuaternion = np.ndarray # shape (7,) - [x, y, z, qw, qx, qy, qz]
DualQuaternion = np.ndarray # shape (8,) - dual quaternion representation
ScrewParameters = np.ndarray # shape (6,) - screw motion parameters
ExponentialCoordinates = np.ndarray # shape (6,) - exponential coordinates
# Batch representations
RotationMatrices = np.ndarray # shape (..., 3, 3)
Quaternions = np.ndarray # shape (..., 4)
Transforms = np.ndarray # shape (..., 4, 4)
PositionQuaternions = np.ndarray # shape (..., 7)
# Visualization types
Axes3D = matplotlib.axes._subplots.Axes3D
Figure3D = pytransform3d.visualizer.Figure