kaolin.math.quat¶
API¶
- kaolin.math.quat.angle_axis_from_quat(quat: Tensor) Tuple[Tensor, Tensor]¶
Convert a rotation quaternion to (angle, axis) representation.
The axis is normalized to unit length.
The angle is guaranteed to be between [0, pi], while axis may be positive or negative.
- Parameters
quat (Tensor) – Rotation quaternion of shape (b, 4).
- Returns
Angle in radians of shape (b, 1) and axis of shape (b, 3).
- Return type
Tuple[Tensor, Tensor]
- kaolin.math.quat.angle_axis_from_rot33(mat: Tensor) Tuple[Tensor, Tensor]¶
Convert a 3x3 rotation matrix to (angle, axis) representation.
- Parameters
mat (Tensor) – Rotation matrix of shape (b, 3, 3).
- Returns
Angle in radians of shape (b,1) and axis of shape (b,3).
- Return type
Tuple[Tensor, Tensor]
- kaolin.math.quat.euclidean_from_rotation_translation(r: Optional[Tensor] = None, t: Optional[Tensor] = None) Tensor¶
Construct a Euclidean transformation matrix from a rotation quaternion and 3d translation.
Only one of rotation and translation can be None.
- Parameters
r (Optional[Tensor], optional) – Rotation quaternion of shape (b, 4). Defaults to None.
t (Optional[Tensor], optional) – 3d translation vector of shape (b, 3). Defaults to None.
- Returns
Euclidean transformation matrix.
- Return type
Tensor
- kaolin.math.quat.euclidean_identity(batch_size: int, device: device = 'cuda') Tensor¶
Identity Euclidean transformation for given batch size.
- Parameters
batch_size (int) – Batch size.
device (torch.device, optional) – Device memory to use. Defaults to “cuda”.
- Returns
Batch of identity Euclidean transforms of shape (b, 4, 4).
- Return type
Tensor
- kaolin.math.quat.euclidean_inverse(x: Tensor) Tensor¶
Inverse of a Euclidean transformation matrix.
Rotation is inverted by \(R \rightarrow R^{-1} = R^{T}\).
Translation is inverted by \(T \rightarrow -R^{-1}T\).
The resulting matrix is of the form: \(\left[\begin{array}{cccc} R^{-1}&T^{-1}\\ \textbf{0}&\textbf{1}\\ \end{array}\right]\)
- Parameters
x (Tensor) – Euclidean transformation matrices of shape (b, 4, 4).
- Returns
Inverted matrices of shape (b, 4, 4).
- Return type
Tensor
- kaolin.math.quat.euclidean_rotation_matrix(x: Tensor) Tensor¶
Retrieve 3d rotation matrix from Euclidean transformation matrix.
- Parameters
x (Tensor) – Euclidean transformation matrices of shape (b, 4, 4).
- Returns
3d rotation matrices of shape (b, 3, 3)
- Return type
Tensor
- kaolin.math.quat.euclidean_translation_vector(x: Tensor) Tensor¶
Retrieve the 3d translation vector from the Euclidean transformation matrix.
- Parameters
x (Tensor) – Euclidean transformation matrices of shape (b, 4, 4).
- Returns
3d translation vectors of shape (b, 3)
- Return type
Tensor
- kaolin.math.quat.is_euclidean_valid(x: Tensor, throw: bool = False) bool¶
Check whether a matrix represents a valid Euclidean transformation matrix.
- Parameters
x (Tensor) – Euclidean transformation matrices of shape (b, 4, 4).
- Returns
True if all are valid, False otherwise.
- Return type
- kaolin.math.quat.is_rot33_valid(rot33: Tensor, atol: float = 1e-06) bool¶
Checks whether a 3x3 rotation matrix is valid.
Valid rotation matrices have determinant 1 and are orthogonal.
- kaolin.math.quat.pad_mat33_to_mat44(mat33: Tensor) Tensor¶
Pad a 3x3 rotation matrix to equivalent 4x4 rotation matrix.
Given input matrix \(R\), the output is: \(\left[\begin{array}{cc} R&\textbf{0}\\ \textbf{0}&\textbf{1}\\ \end{array}\right]\)
- Parameters
mat33 (torch.Tensor) – Batch of 3x3 rotation matices of shape (b, 3, 3).
- Returns
Batch of 4x4 rotation matrices of shape (b, 4, 4).
- Return type
- kaolin.math.quat.quat_abs(quat: Tensor) Tensor¶
Compute the L2 norm of a quaternion.
- Parameters
quat (Tensor) – Quaternion of shape (b, 4).
- Returns
Quaternion norm value of shape (b).
- Return type
Tensor
- kaolin.math.quat.quat_conjugate(quat: Tensor) Tensor¶
Generate conjugate quaternion. Imaginary components are negated.
- Parameters
quat (Tensor) – Quaternion of shape (b, 4).
- Returns
Conjugate quaternion of shape (b, 4).
- Return type
Tensor
- kaolin.math.quat.quat_from_angle_axis(angle: Tensor, axis: Tensor, is_degree: bool = False)¶
Convert an (angle, axis) representation to rotation quaternion representation.
- Parameters
angle (Tensor) – Angle in radians of shape (b, 1).
axis (Tensor) – Axis of rotation of shape (b, 3).
- Returns
Rotation quaternion of shape (b, 4).
- Return type
Tensor
- kaolin.math.quat.quat_from_rot33(mat: Tensor) Tensor¶
Convert a 3x3 rotation matrix to rotation quaternion representation.
- Parameters
mat (Tensor) – Rotation matrix of shape (b, 3, 3).
- Returns
Rotation quaternion of shape (b, 4).
- Return type
Tensor
- kaolin.math.quat.quat_identity(shape: List[int], device: device = 'cuda') Tensor¶
Generate a batch of identity quaternions.
- Parameters
shape (List[int]) – Batch shape to generate.
device (torch.device, optional) – Device memory to use. Defaults to “cuda”.
- Returns
Identity quaternion of shape (shape, 4).
- Return type
Tensor
- kaolin.math.quat.quat_imaginary(quat: Tensor) Tensor¶
Get the imaginary components (xyz) of the quaternion.
- Parameters
quat (Tensor) – Quaternion of shape (b, 4).
- Returns
Imaginary components of the quanternion of shape (b, 3).
- Return type
Tensor
- kaolin.math.quat.quat_inverse(quat: Tensor) Tensor¶
Invert a unit rotation quaternion.
Same as conjugating a quaternion.
- Parameters
quat (Tensor) – Quaternion of shape (b, 4).
- Returns
Inverted quaternion of shape (b, 4).
- Return type
Tensor
- kaolin.math.quat.quat_mul(a: Tensor, b: Tensor) Tensor¶
Multiply two quaternions.
- Parameters
a (Tensor) – First quaternion of shape (b, 4).
b (Tensor) – Second quaternion of shape (b, 4).
- Returns
Multiplication resulting quaternion of shape (b, 4).
- Return type
Tensor
- kaolin.math.quat.quat_positive(quat: Tensor) Tensor¶
Generate a quanternion with positive real component.
- Parameters
quat (Tensor) – Quaternion of shape (b, 4).
- Returns
Quaternion with positive real components of shape (b, 4).
- Return type
Tensor
- kaolin.math.quat.quat_real(quat: Tensor) Tensor¶
Get the real component (w) of the quaternion.
- Parameters
quat (Tensor) – Quaternion of shape (b, 4).
- Returns
Real valued component of the quanternion of shape (b, 1).
- Return type
Tensor
- kaolin.math.quat.quat_rotate(rotation: Tensor, point: Tensor) Tensor¶
Rotate a 3d point by a rotation quaternion.
- Parameters
rotation (Tensor) – Rotation quaternion of shape (b, 4).
point (Tensor) – Point to rotate of shape (b, 3).
- Returns
Rotated point of shape (b, 3).
- Return type
Tensor
- kaolin.math.quat.quat_unit(quat: Tensor) Tensor¶
Normalize quaternion to have norm of 1.
- Parameters
quat (Tensor) – Quaternion of shape (b, 4).
- Returns
Normalized quaternion with norm of 1 of shape (b, 4).
- Return type
Tensor
- kaolin.math.quat.quat_unit_positive(quat: Tensor) Tensor¶
Normalize quaternion to be a valid 3d rotation.
Forces the quaternion to have a norm of 1 and positive real component.
- Parameters
quat (Tensor) – Quaternion of shape (b, 4).
- Returns
Rotation quaternion of shape (b, 4).
- Return type
Tensor
- kaolin.math.quat.rot33_from_angle_axis(angle: Tensor, axis: Tensor) Tensor¶
Convert an (angle, axis) representation to 3x3 rotation matrix representation.
- Parameters
angle (Tensor) – Angle in radians of shape (b, 1).
axis (Tensor) – Axis of rotation of shape (b, 3).
- Returns
Batch of 3x3 rotation matrices of shape (b, 3, 3).
- Return type
Tensor
- kaolin.math.quat.rot33_from_quat(quat: Tensor) Tensor¶
Convert a rotation quaternion to 3x3 rotation matrix representation.
- Parameters
quat (Tensor) – Rotation quaternion of shape (b, 4).
- Returns
Batch of 3x3 rotation matrices of shape (b, 3, 3).
- Return type
Tensor
- kaolin.math.quat.rot33_identity(batch_size: int = 1, device: device = 'cuda') Tensor¶
Generate a batch of identity 3x3 rotation matrices.
- Parameters
batch_size (int, optional) – Number of rotation matrices in the batch. Defaults to 1.
device (torch.device, optional) – Device memory to use. Defaults to “cuda”.
- Returns
Batch of identity rotation matrices of shape (b, 3, 3).
- Return type
Tensor
- kaolin.math.quat.rot33_inverse(mat: Tensor) Tensor¶
Invert a 3x3 rotation matrix.
- Parameters
mat (Tensor) – Batch of 3x3 rotation matrices of shape (b, 3, 3).
- Returns
Batch of inverted 3x3 rotation matrices of shape (b, 3, 3).
- Return type
Tensor
- kaolin.math.quat.rot33_rotate(point: Tensor, mat: Tensor) Tensor¶
Rotate a point using a 3x3 rotation matrix.
- Parameters
point (Tensor) – Batch of points to rotate of shape (b, 3).
mat (Tensor) – Batch of 3x3 rotation matrices of shape (b, 3, 3).
- Returns
Batch of rotated points of shape (b, 3).
- Return type
Tensor
- kaolin.math.quat.rot44_from_quat(quat: Tensor) Tensor¶
Convert a rotation quaternion to a 4x4 rotation matrix.
- Parameters
quat (Tensor) – Rotation quaternion of shape (b, 4).
- Returns
4x4 rotation matrix of shape (b, 4, 4).
- Return type
Tensor
- kaolin.math.quat.scale_to_mat44(scale: Tensor) Tensor¶
Generate a 4x4 matrix scaled to the provided scale.
- Parameters
scale (Tensor) – 3d scaling vector of shape (b, 3).
- Returns
4x4 matrix with provided scaling of shape (b, 4, 4).
- Return type
- kaolin.math.quat.transform_apply(transform: Tensor, point: Tensor) Tensor¶
Apply a position-quaternion transform to a 3d point.
- Parameters
transform (Tensor) – Position-quaternion transform of shape (b, 7).
point (Tensor) – 3d point of shape (b, 3).
- Returns
Transformed 3d point of shape (b, 3).
- Return type
Tensor
- kaolin.math.quat.transform_from_euclidean(euclidean: Tensor) Tensor¶
Convert a Euclidean transformation matrix to position-quaternion transform representation.
- Parameters
euclidean (Tensor) – Euclidean transformation matrices of shape (b, 4, 4).
- Returns
Position-quaternion transform of shape (b, 7).
- Return type
Tensor
- kaolin.math.quat.transform_from_rotation_translation(rotation: Optional[Tensor] = None, translation: Optional[Tensor] = None) Tensor¶
Generate a position-quaternion transform from a rotation quaternion and 3d translation.
Only one argument can be None.
- Parameters
r (Optional[Tensor], optional) – Rotation quaternion of shape (b, 4). Defaults to None.
t (Optional[Tensor], optional) – 3d translation vector of shape (b, 3). Defaults to None.
- Returns
Position-quaternion transform of shape (b, 7).
- Return type
Tensor
- kaolin.math.quat.transform_identity(shape: List[int], device: device = 'cuda') Tensor¶
Generate a batch of identity position-quaternion transforms.
- Parameters
shape (List[int]) – Batch shape to generate.
device (torch.device, optional) – Device memory to use. Defaults to “cuda”.
- Returns
Identity position-quaternion transform of shape (shape, 7).
- Return type
Tensor
- kaolin.math.quat.transform_inverse(x: Tensor) Tensor¶
Invert a position-quaternion transform.
- Parameters
x (Tensor) – Position-quaternion transform of shape (b, 7).
- Returns
Inverted position-quaternion transform of shape (b, 7).
- Return type
Tensor
- kaolin.math.quat.transform_mul(x: Tensor, y: Tensor) Tensor¶
Combined two position-quaternion transforms.
- Parameters
x (Tensor) – First position-quaternion transform of shape (b, 7).
y (Tensor) – Second position-quaternion transform of shape (b, 7).
- Returns
Combined position-quaternion transform of shape (b, 7).
- Return type
Tensor
- kaolin.math.quat.transform_rotation(x: Tensor) Tensor¶
Retrieve the rotation component of a position-rotation transform.
- Parameters
x (Tensor) – Position-quaternion transform of shape (b, 7).
- Returns
Rotation quaternion of shape (b, 4).
- Return type
Tensor
- kaolin.math.quat.transform_translation(x: Tensor) Tensor¶
Retrieve the translation component of a position-rotation transform.
- Parameters
x (Tensor) – Position-quaternion transform of shape (b, 7).
- Returns
3d translation vector of shape (b, 3).
- Return type
Tensor
- kaolin.math.quat.translation_identity(batch_size: int = 1, device: device = 'cuda') Tensor¶
Generate a batch of identity 3d translation vectors.
- Parameters
batch_size (int, optional) – Number of translation vectors in the batch. Defaults to 1.
device (torch.device, optional) – Device memory to use. Defaults to “cuda”.
- Returns
Batch of identity translation vectors of shape (b, 3).
- Return type
Tensor
- kaolin.math.quat.translation_to_mat44(vec: Tensor) Tensor¶
Generate an identity 4x4 matrix with translation set.
- Parameters
vec (Tensor) – 3d translation vector of shape (b, 4). Ignores the last dimension (4th) of the vector.
- Returns
4x4 identity matrix with provided translation of shape (b, 4, 4).
- Return type
- kaolin.math.quat.vector_normalize(vec: Tensor) Tensor¶
Generate a normalized version of a batch of vectors.
Input is NOT modified in place.
- Parameters
vec (torch.Tensor) – Batch of Nd vectors of shape (b, N).
- Returns
Batch of normalized Nd vectors of shape (b, N).
- Return type