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
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
as_euler([seq])Return the Euler angles in a different sequence of axes.
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
seqarray- classmethod from_euler(
- euler: EulerAngles,
- seq: str = 'xyz',
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',
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:
- 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:
- 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:
- inv() EulerAngles¶
Return the inverse (conjugate) of this Euler angle rotation.
- Returns:
A new EulerAngles instance representing the inverse rotation.
- Return type:
- 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
kinematicsshould 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:
- replace(**updates) T¶
Returns a new object replacing the specified fields with new values.