Quaternions¶
Class-based Quaternion representation and mathematics for 3-D rotations.
-
class pybosl2.quaternions.Quaternion(w=
1.0, x=0.0, y=0.0, z=0.0)[source]¶ Bases:
objectClass to represent a 4-dimensional complex number or quaternion.
Quaternion objects can be used generically as 4D numbers, or as unit quaternions to represent rotations in 3D space.
- q¶
Quaternion 4-vector represented as a Numpy array
- classmethod from_array(array)[source]¶
Create a Quaternion from a 4-element numeric sequence.
- classmethod from_scalar_vector(scalar, vector)[source]¶
Create a Quaternion from a scalar and a 3-element vector.
- classmethod from_real_imaginary(real, imaginary)[source]¶
Create a Quaternion from real and 3-element imaginary parts.
-
classmethod from_matrix(matrix, rtol=
1e-05, atol=1e-08)[source]¶ Initialise from 3x3 or 4x4 matrix representation.
- classmethod from_axis_angle(axis, angle)[source]¶
Create a Quaternion from rotation axis and angle (in radians).
- classmethod random()[source]¶
Generate a random unit quaternion.
Uniformly distributed across the rotation space.
- Return type:¶
- property conjugate : Quaternion¶
Quaternion conjugate clone.
- property inverse : Quaternion¶
Inverse of the quaternion object.
- property norm : float¶
L2 norm of the quaternion 4-vector.
- property magnitude : float¶
Alias for norm.
- property normalised : Quaternion¶
Return a unit normalised copy.
- property polar_angle : float¶
Return polar angle of the quaternion.
- property unit : Quaternion¶
Alias for normalised.
- classmethod exp_map(q, eta)[source]¶
Quaternion exponential map.
- Parameters:¶
- q : Quaternion¶
- eta : Quaternion¶
- Return type:¶
- classmethod sym_exp_map(q, eta)[source]¶
Symmetrized exponential map.
- Parameters:¶
- q : Quaternion¶
- eta : Quaternion¶
- Return type:¶
- classmethod log_map(q, p)[source]¶
Quaternion logarithm map.
- Parameters:¶
- q : Quaternion¶
- p : Quaternion¶
- Return type:¶
- classmethod sym_log_map(q, p)[source]¶
Symmetrized logarithm map.
- Parameters:¶
- q : Quaternion¶
- p : Quaternion¶
- Return type:¶
- classmethod absolute_distance(q0, q1)[source]¶
Quaternion absolute distance.
- Parameters:¶
- q0 : Quaternion¶
- q1 : Quaternion¶
- Return type:¶
float
- classmethod distance(q0, q1)[source]¶
Quaternion intrinsic distance.
- Parameters:¶
- q0 : Quaternion¶
- q1 : Quaternion¶
- Return type:¶
float
- classmethod sym_distance(q0, q1)[source]¶
Symmetrized geodesic distance.
- Parameters:¶
- q0 : Quaternion¶
- q1 : Quaternion¶
- Return type:¶
float
-
classmethod slerp(q0, q1, amount=
0.5)[source]¶ Spherical Linear Interpolation between unit quaternions.
The endpoints are normalised (and one may be negated, to take the short way round) on copies: interpolating between two rotations does not change either of them.
- Parameters:¶
- q0 : Quaternion¶
- q1 : Quaternion¶
- amount : float¶
- Return type:¶
-
classmethod intermediates(q0, q1, n, include_endpoints=
False)[source]¶ Generate iterable sequence of intermediates.
- Parameters:¶
- q0 : Quaternion¶
- q1 : Quaternion¶
- n : int¶
- include_endpoints : bool¶
- Return type:¶
Iterator[Quaternion]
- derivative(rate)[source]¶
Instantaneous quaternion derivative.
- property yaw_pitch_roll : tuple[float, float, float]¶
Get Yaw, Pitch, Roll angles (in radians).
- property angle : float¶
Get angle of rotation in radians.
- property degrees : float¶
Get angle of rotation in degrees.
- property radians : float¶
Get angle of rotation in radians.
- property scalar : float¶
Get scalar component.
- property real : float¶
Get real component.
- property w : float¶
Get w element.
- property x : float¶
Get x element.
- property y : float¶
Get y element.
- property z : float¶
Get z element.
-
pybosl2.quaternions.quaternion(angle=
None, axis=None, rpy=None, matrix=None)[source]¶ Construct a 4-element quaternion [x, y, z, w].
If no arguments are provided, returns the identity quaternion [0, 0, 0, 1]. All angles are specified in degrees.
- pybosl2.quaternions.quaternion_to_axis(q)[source]¶
Convert a quaternion to its angle and rotation axis representation.