paralleldomain.utilities.transformation¶
- class Transformation(quaternion=None, translation=None)¶
Multi-purpose 6DoF object.
When printed, the rotation is given as euler angles in degrees following intrinsic rotation order XYZ, rounded to 2 decimal places.
- Parameters
quaternion (Union[pyquaternion.quaternion.Quaternion, List[float], numpy.ndarray]) – Quaternion instance or elements for rotation. Elements are expected in order (w,x,y,z). Default: Unit quaternion without rotation.
translation (Union[numpy.ndarray, List]) – List-like translation information in order (x,y,z). Default: [0,0,0]
Example
Transformation instances can be easily matrix-multiplied with other Transformation instances or any np.ndarray of shape (4,n).
lidar_frame = ... # get any `SensorFrame` from a LiDAR sensor points_vehicle_frame = (lidar_frame.extrinsic @ lidar_frame.xyz_one.T).T points_world_frame = (lidar_frame.pose @ lidar_frame.xyz_one.T).T boxes_3d = lidar_frame.get_annotations(AnnotationTypes.BoundingBoxes3D) for b in boxes_3d.boxes: box_pose_world_frame = lidar_frame.pose @ b.pose
- property transformation_matrix: numpy.ndarray¶
Returns the homogeneous transformation matrix in shape (4,4).
/ \ |R_11 R_12 R_13 t_x| |R_21 R_22 R_23 t_y| |R_31 R_32 R_33 t_z| |0 0 0 1 | \ /
- Return type
ndarray
- property rotation: numpy.ndarray¶
Returns the rotation matrix in shape (3,3).
/ \ |R_11 R_12 R_13| |R_21 R_22 R_23| |R_31 R_32 R_33| \ /
- Return type
ndarray
- property quaternion: pyquaternion.quaternion.Quaternion¶
Returns the rotation as a
pyquaternion.quaternion.Quaternion
instance.Full documentation can be found in pyquaternion API Documentation.
To get the quaternion coefficients, either call .elements, iterate over the object itself or use the dedicated named properties. The element order (until explicitly stated otherwise) should always be assumed as (w,x,y,z) for function w + xi+ yj + zk
from paralleldomain.model.transformation import Transformation tf = Transformation.from_euler_angles(yaw=90, pitch=0, roll=0, is_degrees=True) assert(tf.quaternion.elements[0] == tf.quaternion[0] == tf.quaternion.w) assert(tf.quaternion.elements[1] == tf.quaternion[1] == tf.quaternion.x) assert(tf.quaternion.elements[2] == tf.quaternion[2] == tf.quaternion.y) assert(tf.quaternion.elements[3] == tf.quaternion[3] == tf.quaternion.z)
Please note that when using
scipy.spatial.transform.Rotation
, scipy assumes the order as (x,y,w,z).from paralleldomain.model.transformation import Transformation from scipy.spatial.transform import Rotation import numpy as np tf = Transformation.from_euler_angles(yaw=90, pitch=0, roll=0, is_degrees=True) tf_scipy = Rotation.from_quat([ tf.quaternion.x, tf.quaternion.y, tf.quaternion.z, tf.quaternion.w ]) # Check that rotation quaternion is equal within tolerance np.allclose(tf.rotation == tf_scipy.as_matrix()) # returns True
- Return type
Quaternion
- property translation: numpy.ndarray¶
Returns the translation vector (x,y,z) in shape (3,).
- Return type
ndarray
- property inverse: paralleldomain.utilities.transformation.Transformation¶
Returns the inverse transformation as a new
Transformation
object.- Return type
- classmethod from_transformation_matrix(mat)¶
Creates a Transformation object from an homogeneous transformation matrix of shape (4,4)
- Parameters
mat (numpy.ndarray) – Transformation matrix as described in
transformation_matrix
- Returns
Instance of
Transformation
with provided parameters.- Return type
- as_euler_angles(order, degrees=False)¶
Returns the rotation of a Transformation object as euler angles.
- Parameters
order (str) – Defines the axes rotation order. Use lower case for extrinsic rotation, upper case for intrinsic rotation. Ex: xyz, ZYX, xzx.
degrees (bool) – Defines if euler angles should be returned in degrees instead of radians. Default: False
- Returns
Ordered array of euler angles with length 3.
- Return type
ndarray
- classmethod from_euler_angles(angles, order, translation=None, degrees=False)¶
Creates a transformation object from euler angles and optionally translation (default: (0,0,0))
- Parameters
angles (Union[numpy.ndarray, List[float]]) – Ordered euler angles array with length 3
translation (Optional[numpy.ndarray]) – Translation vector in order (x,y,z). Default: [0,0,0]
order (str) – Defines the axes rotation order. Use lower case for extrinsic rotation, upper case for intrinsic rotation. Ex: xyz, ZYX, xzx.
degrees (bool) – Defines if euler angles are provided in degrees instead of radians. Default: False
- Returns
Instance of
Transformation
with provided parameters.- Return type