Quaternion.from_rpy
Quaternion.from_rpy(angles: ndarray) → ndarray : Quaternion from given RPY angles.
code
The quaternion can be constructed from the Aerospace cardanian angle
sequence that follows the order ,
where is the **roll** (or *bank*) angle,
is the **pitch** (or *elevation*) angle, and is the
**yaw** (or *heading*) angle.
The composing quaternions are:
The elements of the final quaternion
are obtained as:
Warning
The Aerospace sequence is only
one of the [twelve possible rotation sequences](https://en.wikipedia.org/wiki/Euler_angles#Tait.E2.80.93Bryan_angles)
around the main axes. Other sequences might be more suitable for
other applications, but this one is the most common in practice.
Parameters:
: **angles** (*numpy.ndarray*) – 3 cardanian angles, in radians, following the order: roll -> pitch -> yaw.
Returns:
: **q** – Quaternion from roll-pitch-yaw angles.
Return type:
: numpy.ndarray
Examples
```defaultfrom ahrs import DEG2RAD # Helper variable to convert angles to radians q = Quaternion() q.from_rpy(np.array([10.0, 20.0, 30.0])*DEG2RAD) # Give roll-pitch-yaw angles as radians. array([0.95154852, 0.23929834, 0.18930786, 0.03813458])
code
It can be corroborated with the class [DCM](https://ahrs.readthedocs.io/en/latest/quaternion/dcm.html), which represents a Direction
Cosine Matrix, and can also be built with roll-pitch-yaw angles.
```default
>>> from ahrs import DCM
>>> R = DCM(rpy=[10.0, 20.0, 30.0]) # Here you give the angles as degrees
>>> R
DCM([[ 0.92541658, 0.01802831, 0.37852231],
[ 0.16317591, 0.88256412, -0.44096961],
[-0.34202014, 0.46984631, 0.81379768]])
>>> q.from_DCM(R)
array([0.95154852, 0.23929834, 0.18930786, 0.03813458])code
With both approaches the same quaternion is obtained.