archimedes.spatial.EulerAngles¶

class archimedes.spatial.EulerAngles(array: ndarray, seq: str = 'xyz')¶

Euler angle representation of a rotation in 3 dimensions

Parameters:
  • angles (array_like) – Euler angles in radians

  • seq (str, optional) – Sequence of axes for Euler angles (up to length 3). Each character must be one of ā€˜x’, ā€˜y’, ā€˜z’ (extrinsic) or ā€˜X’, ā€˜Y’, ā€˜Z’ (intrinsic). Default is ā€˜xyz’.

Variables:
  • array (np.ndarray) – Underlying array of Euler angles.

  • seq (str) – Sequence of axes for Euler angles.

Examples

>>> from archimedes.spatial import EulerAngles
>>> import numpy as np

Consider a right-handed rotation of 90 degrees about the z-axis. This corresponds to a single yaw rotation:

>>> euler = EulerAngles(np.deg2rad(90), 'z')

This can be converted to other representations:

>>> euler.as_matrix()
array([[ 6.123234e-17,  1.000000e+00,  0.000000e+00],
   [-1.000000e+00,  6.123234e-17,  0.000000e+00],
   [ 0.000000e+00,  0.000000e+00,  1.000000e+00]])
>>> np.rad2deg(euler.as_euler('xyx'))  # Roll-pitch-roll sequence
array([-90.,  90.,  90.])
>>> euler.as_quat()
Quaternion([0.70710678 0.         0.         0.70710678])

The associated rotation matrix can be used to change coordinate systems. If the Euler sequence represents the orientation of a frame B relative to a frame A, then the rotation matrix transforms vectors from frame A to frame B:

>>> v_A = np.array([1, 0, 0])  # Vector in frame A
>>> R_BA = euler.as_matrix()
>>> R_BA @ v_A  # Vector in frame B
[6.12323e-17, -1, 0]

The kinematics method can be used to compute the time derivative of the Euler angles given the angular velocity in the body frame. Note that Euler kinematics are currently only supported for the ā€œxyzā€ sequence (standard roll-pitch-yaw):

>>> w_B = np.array([0, 0, np.pi/2])  # 90 deg/s about z-axis
>>> rpy = EulerAngles([0.1, 0.2, 0.3], "xyz")
>>> rpy.kinematics(w_B)
EulerAngles([ 0.31682542 -0.15681796  1.59473746], seq='xyz')

Be careful with the kinematics output; this is expressed as an EulerAngles instance for consistency with ODE solvers but represents rotation _rates_. Trying to apply this output as a rotation or convert to a DCM will not produce meaningful results.

See also

Quaternion

Quaternion representation of rotation in 3D

RigidBody

Rigid body dynamics supporting EulerAngles attitude representation

euler_to_dcm

Directly calculate rotation matrix from roll-pitch-yaw angles

euler_kinematics

Transform roll-pitch-yaw rates to body-frame angular velocity

Methods

as_euler([seq])

Return the Euler angles in a different sequence of axes.

as_matrix()

Convert the Euler angles to a direction cosine matrix (DCM).

as_quat()

Return the corresponding Quaternion representation.

from_euler(euler[, seq])

Return an EulerAngles instance from another EulerAngles instance.

from_quat(quat[, seq])

Create EulerAngles from a Quaternion.

identity([seq])

Return the identity EulerAngles (zero rotation).

inv()

Return the inverse (conjugate) of this Euler angle rotation.

kinematics(w_B)

Compute the time derivative of the Euler angles given angular velocity.

replace(**updates)

Returns a new object replacing the specified fields with new values.

Attributes

seq

array

classmethod from_euler(
euler: EulerAngles,
seq: str = 'xyz',
) → EulerAngles¶

Return an EulerAngles instance from another EulerAngles instance.

Can be used to change the sequence of axes.

classmethod from_quat(
quat: Quaternion | ndarray,
seq: str = 'xyz',
) → EulerAngles¶

Create EulerAngles from a Quaternion.

Parameters:

quat (Quaternion or array_like) – Quaternion representing the rotation.

Returns:

New EulerAngles instance representing the same rotation.

Return type:

EulerAngles

classmethod identity(seq: str = 'xyz') → EulerAngles¶

Return the identity EulerAngles (zero rotation).

Parameters:

seq (str, optional) – Sequence of axes for Euler angles. Default is ā€˜xyz’.

Returns:

New EulerAngles instance representing the identity rotation.

Return type:

EulerAngles

__init__(array: ndarray, seq: str = 'xyz') → None¶
as_euler(seq: str = 'xyz') → EulerAngles¶

Return the Euler angles in a different sequence of axes.

If the requested sequence is the same as the current sequence, returns self.

as_matrix() → ndarray¶

Convert the Euler angles to a direction cosine matrix (DCM).

If the Euler angles represent the orientation of a body A relative to a frame B, then this method returns the matrix R_BA that transforms vectors from frame A to frame B. Specifically, for a vector v_A expressed in frame A, the corresponding vector in frame B is given by v_B = R_BA @ v_A.

The inverse transformation can be obtained by transposing this matrix: R_AB = R_BA.T.

Return type:

A 3x3 numpy array representing the DCM.

as_quat() → Quaternion¶

Return the corresponding Quaternion representation.

Returns:

The equivalent Quaternion representation of this rotation.

Return type:

Quaternion

inv() → EulerAngles¶

Return the inverse (conjugate) of this Euler angle rotation.

Returns:

A new EulerAngles instance representing the inverse rotation.

Return type:

EulerAngles

kinematics(w_B: ndarray) → EulerAngles¶

Compute the time derivative of the Euler angles given angular velocity.

CAUTION: This method returns the time derivative of the attitude, which is represented with the same data structure for consistency with ODE solving - but this return is not itself a valid rotation representation until integrated in time. Hence, the output of kinematics should never be converted to a different attitude representation or rotation matrix.

Parameters:

w_B (np.ndarray) – Angular velocity vector expressed in the body frame B.

Returns:

Time derivative of the Euler angles.

Return type:

EulerAngles

replace(**updates) → T¶

Returns a new object replacing the specified fields with new values.