API Reference¶
- class quatorch.Quaternion(*args, **kwargs)¶
A
torch.Tensorsubclass representing quaternions, defined as\[q = w + x\mathbf{i} + y\mathbf{j} + z\mathbf{k}\]Quaternions are represented as tensors of shape \((..., 4)\), where the last dimension corresponds to the components \((W, X, Y, Z)\).
- Parameters:
w – The real part of the quaternion.
x – The first imaginary part of the quaternion.
y – The second imaginary part of the quaternion.
z – The third imaginary part of the quaternion.
or
- Parameters:
data – A tensor of shape \((..., 4)\) representing the quaternion components in the order \((W, X, Y, Z)\).
- abs() Tensor¶
Quaternion norm, defined as
\[\|q\| = \sqrt{w^2 + x^2 + y^2 + z^2}\]- Returns:
A tensor of shape \((...)\) representing the norm of the quaternion(s).
- add(other: Tensor | Quaternion) Quaternion¶
Quaternion addition (element-wise).
- conj() Quaternion¶
Alias for
.conj().
- conjugate()¶
Quaternion conjugate, defined as \(q^* = w - x\mathbf{i} - y\mathbf{j} - z\mathbf{k}\).
- div(other: int | float | Quaternion) Quaternion¶
Non-commutative quaternion division.
- exp() Quaternion¶
Quaternion exponential of \(q\), defined as
\[e^q=e^{w}\left(\cos \|\mathbf {v} \|+{\frac {\mathbf {v} }{\|\mathbf {v} \|}}\sin \|\mathbf {v} \|\right)\]where \(q = w + \mathbf{v}\) with \({w}\) the real part and \(\mathbf{v}\) the vector part of the quaternion.
- static from_axis_angle(axis: Tensor, angle: Tensor) Quaternion¶
Create a quaternion from an axis-angle representation. :param axis: A tensor of shape \((..., 3)\) representing the rotation axis :param angle: A tensor of shape \((...)\) representing the rotation angle in radians
- Returns:
An equivalent quaternion.
- static from_rotation_matrix(R: Tensor) Quaternion¶
Create a quaternion from a 3x3 rotation matrix.
- Parameters:
R – A tensor of shape \((..., 3, 3)\) representing the rotation matrix(or matrices).
- Returns:
An equivalent quaternion.
- property imag: Quaternion¶
Imaginary part of quaternion, i.e., \(x\mathbf{i} + y\mathbf{j} + z\mathbf{k}\)
- Returns:
A pure imaginary quaternion
- inverse()¶
Quaternion inverse, defined as \(q^{-1} = \frac{q^*}{\|q\|^2}\).
- log() Quaternion¶
Quaternion logarithm of \(q\), defined as
\[\log q=\log {\|q\|} +{\frac {\mathbf {v} }{\|\mathbf {v} \|}}\arccos {\frac {w}{\|q\|}}\]where \(q = w + \mathbf{v}\) with \(w\) the real part and \(\mathbf{v}\) the vector part of the quaternion.
- mul(other: int | float | Quaternion) Quaternion¶
Non-commutative quaternion multiplication.
- normalize()¶
Returns a normalized quaternion, defined as \(\frac{q}{\|q\|}\).
- pow(exponent: float | Tensor | Quaternion) Quaternion¶
Quaternion power, defined as
\[q^t = \exp(t \log q)\]where \(t\) is the exponent.
- property real: Quaternion¶
Real part of quaternion, i.e., \(w\)
- Returns:
A real quaternion
- rotate_vector(v: Tensor)¶
Rotate a 3D vector or a batch of 3D vectors using this quaternion.
- Parameters:
v – A tensor of shape \((..., 3)\) representing the 3D vector(s) to be rotated.
- Returns:
A tensor of shape \((..., 3)\) representing the rotated vector(s).
- slerp(other: Quaternion, t: float | Tensor)¶
Performs spherical linear interpolation (slerp) between this quaternion and another quaternion.
- Parameters:
other – The target quaternion to interpolate towards.
t – The interpolation factor, where 0.0 corresponds to this quaternion and 1.0 corresponds to the other quaternion.
- Returns:
The interpolated quaternion.
- sub(other: Tensor | Quaternion) Quaternion¶
Quaternion subtraction (element-wise).