Quaternion¶
- class gdt.core.coords.Quaternion(quaternion: Union[Sequence, ndarray], scalar_first: bool = False)[source]¶
Bases:
ArrayBaseA class for containing a quaternion and performing quaternion operations.
The quaternion is represented internally as a two-dimensional array of size (n,4) where the elements follow numpy’s row-major order (i.e. array[row, colum]) and each quaternion is stored by row with the columns representing i(x), j(y), k(z), and w in that order (scalar-last).
Overloaded operations supported are:
Addition
Subtraction
Multiplication
Division
Negation
Equivalence
- Parameters:
quaternion (np.array) – Either a 1D 4-element array containing a single quaternion or a 2D array of shape (n, 4) containing n quaternions.
scalar_first (bool, optional) – Set to True if the input arrays are in scalar-first representation, False if in scalar-last representation. Default is False.
Attributes Summary
How close the floating point numbers need to be before they are considered equal.
Conjugate of the quaternion(s)
Used by astropy Table to store column information
The inverse of the quaternion(s)
Is or is not scalar
The norm of the quaternion(s)
The rotation matrix for the quaternion(s)
Array of quaternion values with the scalar as the first column
An array of quaternion values with the scalar as the last column
The shape of the array
The quaternion(s) as unit quaternion(s)
The w value(s) in the quaternion
The x value(s) in the quaternion
The vector portion of the quaternion(s)
The y value(s) in the quaternion
The z value(s) in the quaternion
Methods Summary
copy()Returns a copy of the object.
dot(other)Return the dot product of this quaternion and another.
equal_rotation(other)Determine if another quaternion represents the same rotation as this quaternion.
from_rotation(rot)Create a quaternion from SciPy Rotation objects.
from_vectors(vec1, vec2)Create a quaternion from the rotation between two vectors.
from_xyz_w(xyz, w)Create a quaternion from a vector and scalar.
round(decimals)Returns the quaternion(s) with the components rounded to the given decimal places
Attributes Documentation
- EPSILON = 1e-12¶
How close the floating point numbers need to be before they are considered equal.
- Type:
(float)
- conjugate¶
Conjugate of the quaternion(s)
- Type:
- info¶
Used by astropy Table to store column information
- Type:
(
astropy.utils.data_info.MixinInfo)
- inverse¶
The inverse of the quaternion(s)
- Type:
- isscalar¶
Is or is not scalar
- Type:
(bool)
- norm¶
The norm of the quaternion(s)
- Type:
(float or np.array)
- rotation¶
The rotation matrix for the quaternion(s)
- Type:
(
scipy.spatial.transform.Rotation)
- scalar_first¶
Array of quaternion values with the scalar as the first column
- Type:
(np.array)
- scalar_last¶
An array of quaternion values with the scalar as the last column
- Type:
(np.array)
- shape¶
The shape of the array
- Type:
(tuple)
- unit¶
The quaternion(s) as unit quaternion(s)
- Type:
- w¶
The w value(s) in the quaternion
- Type:
(np.array)
- x¶
The x value(s) in the quaternion
- Type:
(np.array)
- xyz¶
The vector portion of the quaternion(s)
- Type:
(np.array)
- y¶
The y value(s) in the quaternion
- Type:
(np.array)
- z¶
The z value(s) in the quaternion
- Type:
(np.array)
Methods Documentation
- copy()¶
Returns a copy of the object. For compatibility with Astropy frames.
- dot(other)[source]¶
Return the dot product of this quaternion and another.
- Parameters:
other (
Quaternion) – The other quaternion- Returns:
- equal_rotation(other)[source]¶
Determine if another quaternion represents the same rotation as this quaternion.
- Parameters:
other (
Quaternion) – The other quaternion- Returns:
(bool or np.array)
- classmethod from_rotation(rot: Rotation) Quaternion[source]¶
Create a quaternion from SciPy Rotation objects.
- Parameters:
rot (scipy.spatial.transform.Rotation): The SciPy Rotation object
- Returns:
- classmethod from_vectors(vec1: Union[ndarray, List], vec2: Union[ndarray, List])[source]¶
Create a quaternion from the rotation between two vectors.
- Parameters:
vec1 (np.array) – A cartesian vector
vec2 (np.array) – Another cartesian vector
- Returns:
- classmethod from_xyz_w(xyz: Union[Sequence, ndarray], w: Union[int, float, Sequence, ndarray]) Quaternion[source]¶
Create a quaternion from a vector and scalar.
- Parameters:
xyz – Represents the values for the x, y and z axis
w – Represents the rotation for the resultant (w)
- Returns:
- round(decimals: int) Quaternion[source]¶
Returns the quaternion(s) with the components rounded to the given decimal places
- Args:
decimals: Number of decimal places to round the components of the quaternion.
- Returns: