Quaternion

class gdt.core.coords.Quaternion(quaternion: Union[Sequence, ndarray], scalar_first: bool = False)[source]

Bases: ArrayBase

A 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

EPSILON

How close the floating point numbers need to be before they are considered equal.

conjugate

Conjugate of the quaternion(s)

info

Used by astropy Table to store column information

inverse

The inverse of the quaternion(s)

isscalar

Is or is not scalar

norm

The norm of the quaternion(s)

rotation

The rotation matrix for the quaternion(s)

scalar_first

Array of quaternion values with the scalar as the first column

scalar_last

An array of quaternion values with the scalar as the last column

shape

The shape of the array

unit

The quaternion(s) as unit quaternion(s)

w

The w value(s) in the quaternion

x

The x value(s) in the quaternion

xyz

The vector portion of the quaternion(s)

y

The y value(s) in the quaternion

z

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:

(Quaternion)

info

Used by astropy Table to store column information

Type:

(astropy.utils.data_info.MixinInfo)

inverse

The inverse of the quaternion(s)

Type:

(Quaternion)

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:

(Quaternion)

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:

(Quaternion)

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:

(Quaternion)

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:

(Quaternion)

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:

(Quaternion)

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:

(Quaternion)