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β.
- arrayΒΆ
Underlying array of Euler angles.
- Type:
np.ndarray
- seqΒΆ
Sequence of axes for Euler angles.
- Type:
str
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
kinematicsmethod 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
EulerAnglesinstance 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
QuaternionQuaternion representation of rotation in 3D
RigidBodyRigid body dynamics supporting
EulerAnglesattitude representationeuler_to_dcmDirectly calculate rotation matrix from roll-pitch-yaw angles
euler_kinematicsTransform roll-pitch-yaw rates to body-frame angular velocity
Methods
__init__(array[, seq])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