symforce.geo.quaternion module

class Quaternion(xyz, w)[source]

Bases: Group

Unit quaternions, also known as versors, provide a convenient mathematical notation for representing orientations and rotations of objects in three dimensions. Compared to Euler angles they are simpler to compose and avoid the problem of gimbal lock. Compared to rotation matrices they are more compact, more numerically stable, and more efficient.

Storage is (x, y, z, w).

References

https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

Parameters:
  • xyz (Vector3) –

  • w (T.Scalar) –

property x: float
property y: float
property z: float
classmethod storage_dim()[source]

Dimension of underlying storage

Return type:

int

to_storage()[source]

Flat list representation of the underlying storage, length of storage_dim(). This is used purely for plumbing, it is NOT like a tangent space.

Return type:

List[float]

classmethod from_storage(vec)[source]

Construct from a flat list representation. Opposite of to_storage().

Parameters:

vec (Sequence[float]) –

Return type:

Quaternion

classmethod symbolic(name, **kwargs)[source]

Construct a symbolic element with the given name prefix. Kwargs are forwarded to sf.Symbol (for example, sympy assumptions).

Parameters:
  • name (str) –

  • kwargs (Any) –

Return type:

Quaternion

classmethod identity()[source]

Identity element such that compose(a, identity) = a.

Return type:

Quaternion

compose(other)[source]

Apply the group operation with other.

Parameters:

other (Quaternion) –

Return type:

Quaternion

inverse()[source]

Group inverse, such that compose(a, inverse(a)) = identity.

Return type:

Quaternion

__mul__(right)[source]

Quaternion multiplication.

Parameters:

right (Quaternion) –

Returns:

Quaternion

Return type:

Quaternion

__neg__()[source]

Negation of all entries.

Returns:

Quaternion

Return type:

Quaternion

__add__(right)[source]

Quaternion addition.

Parameters:

right (Quaternion) –

Returns:

Quaternion

Return type:

Quaternion

__truediv__(scalar)[source]

Scalar division.

Parameters:

scalar (Scalar) –

Returns:

Quaternion

Return type:

Quaternion

classmethod zero()[source]

Construct with all zeros.

Returns:

Quaternion

Return type:

Quaternion

squared_norm()[source]

Squared norm when considering the quaternion as 4-tuple.

Returns:

Scalar

Return type:

float

conj()[source]

Quaternion conjugate.

Returns:

Quaternion

Return type:

Quaternion

classmethod unit_random()[source]

Generate a random unit quaternion

Return type:

Quaternion

classmethod unit_random_from_uniform_samples(u1, u2, u3, pi=pi)[source]

Generate a random unit quaternion from three variables uniformly sampled in [0, 1].

Reference:

http://planning.cs.uiuc.edu/node198.html

Parameters:
Return type:

Quaternion