Conversion between quaternions and Euler angles

Spatial rotations in three dimensions can be parametrized using both Euler angles and unit quaternions. This article explains how to convert between the two representations. Actually this simple use of "quaternions" was first presented by Euler some seventy years earlier than Hamilton to solve the problem of magic squares. For this reason the dynamics community commonly refers to quaternions in this application as "Euler parameters".

Definition

There are two representations of quaternions. This article uses the more popular Hamilton.

A quaternion has 4 real values: qw (the real part or the scalar part) and qx qy qz (the imaginary part).

Defining the norm of the quaternion as follows:

A unit quaternion satisfies:

We can associate a quaternion with a rotation around an axis by the following expression

where α is a simple rotation angle (the value in radians of the angle of rotation) and cos(βx), cos(βy) and cos(βz) are the "direction cosines" of the angles between the three coordinate axes and the axis of rotation. (Euler's Rotation Theorem).

Intuition

To better understand how "direction cosines" work with quaternions:

If the axis of rotation is the x-axis:

If the axis of rotation is the y-axis:

If the axis of rotation is the z-axis:

If the axis of rotation is a vector located 45° (π/4 radians) between the x and y axes:

Therefore, the x and y axes "share" influence over the new axis of rotation.

Tait–Bryan angles

Tait–Bryan angles. z-y′-x″ sequence (intrinsic rotations; N coincides with y’). The angle rotation sequence is ψ, θ, φ. Note that in this case ψ > 90° and θ is a negative angle.

Similarly for Euler angles, we use the Tait Bryan angles (in terms of flight dynamics):

  • Heading – : rotation about the Z-axis
  • Pitch – : rotation about the new Y-axis
  • Bank – : rotation about the new X-axis

where the X-axis points forward, Y-axis to the right and Z-axis downward. In the conversion example above the rotation occurs in the order heading, pitch, bank.

Rotation matrices

The orthogonal matrix (post-multiplying a column vector) corresponding to a clockwise/left-handed (looking along positive axis to origin) rotation by the unit quaternion is given by the inhomogeneous expression:

or equivalently, by the homogeneous expression:

If is not a unit quaternion then the homogeneous form is still a scalar multiple of a rotation matrix, while the inhomogeneous form is in general no longer an orthogonal matrix. This is why in numerical work the homogeneous form is to be preferred if distortion is to be avoided.

The direction cosine matrix (from the rotated Body XYZ coordinates to the original Lab xyz coordinates for a clockwise/lefthand rotation) corresponding to a post-multiply Body 3-2-1 sequence with Euler angles (ψ, θ, φ) is given by:[1]

Euler angles for Body 3-1-3 Sequence – The xyz (original fixed Lab) system is shown in blue, the XYZ (rotated final Body) system is shown in red. The line of nodes, labelled N and shown in green, is the intermediate Body X-axis around which the second rotation occurs.

Euler angles (in 3-2-1 sequence) to quaternion conversion

By combining the quaternion representations of the Euler rotations we get for the Body 3-2-1 sequence, where the airplane first does yaw (Body-Z) turn during taxiing onto the runway, then pitches (Body-Y) during take-off, and finally rolls (Body-X) in the air. The resulting orientation of Body 3-2-1 sequence (around the capitalized axis in the illustration of Tait–Bryan angles) is equivalent to that of lab 1-2-3 sequence (around the lower-cased axis), where the airplane is rolled first (lab-x axis), and then nosed up around the horizontal lab-y axis, and finally rotated around the vertical lab-z axis (lB = lab2Body):

Other rotation sequences use different conventions.[1]

Source code

Below code in C++ illustrates above conversion:

struct Quaternion
{
    double w, x, y, z;
};

// This is not in game format, it is in mathematical format.
Quaternion ToQuaternion(double roll, double pitch, double yaw) // roll (x), pitch (y), yaw (z), angles are in radians
{
    // Abbreviations for the various angular functions

    double cr = cos(roll * 0.5);
    double sr = sin(roll * 0.5);
    double cp = cos(pitch * 0.5);
    double sp = sin(pitch * 0.5);
    double cy = cos(yaw * 0.5);
    double sy = sin(yaw * 0.5);

    Quaternion q;
    q.w = cr * cp * cy + sr * sp * sy;
    q.x = sr * cp * cy - cr * sp * sy;
    q.y = cr * sp * cy + sr * cp * sy;
    q.z = cr * cp * sy - sr * sp * cy;

    return q;
}

Quaternion to Euler angles (in 3-2-1 sequence) conversion

A direct formula for the conversion from a quaternion to Euler angles in any of the 12 possible sequences exists.[2] For the rest of this section, the formula for the sequence Body 3-2-1 will be shown. If the quaternion is properly normalized, the Euler angles can be obtained from the quaternions via the relations:

Note that the arctan functions implemented in computer languages only produce results between −π/2 and π/2, which is why atan2 is used to generate all the correct orientations. Moreover, typical implementations of arctan also might have some numerical disadvantages near zero and one.

Some implementations use the equivalent expression:[3]

Source code

The following C++ program illustrates conversion above:

#define _USE_MATH_DEFINES
#include <cmath>

struct Quaternion {
    double w, x, y, z;
};

struct EulerAngles {
    double roll, pitch, yaw;
};

// this implementation assumes normalized quaternion
// converts to Euler angles in 3-2-1 sequence
EulerAngles ToEulerAngles(Quaternion q) {
    EulerAngles angles;

    // roll (x-axis rotation)
    double sinr_cosp = 2 * (q.w * q.x + q.y * q.z);
    double cosr_cosp = 1 - 2 * (q.x * q.x + q.y * q.y);
    angles.roll = std::atan2(sinr_cosp, cosr_cosp);

    // pitch (y-axis rotation)
    double sinp = std::sqrt(1 + 2 * (q.w * q.y - q.x * q.z));
    double cosp = std::sqrt(1 - 2 * (q.w * q.y - q.x * q.z));
    angles.pitch = 2 * std::atan2(sinp, cosp) - M_PI / 2;

    // yaw (z-axis rotation)
    double siny_cosp = 2 * (q.w * q.z + q.x * q.y);
    double cosy_cosp = 1 - 2 * (q.y * q.y + q.z * q.z);
    angles.yaw = std::atan2(siny_cosp, cosy_cosp);

    return angles;
}

Singularities

One must be aware of singularities in the Euler angle parametrization when the pitch approaches ±90° (north/south pole). These cases must be handled specially. The common name for this situation is gimbal lock.

Code to handle the singularities is derived on this site: www.euclideanspace.com

Vector rotation

Let us define scalar and vector such that quaternion .

Note that the canonical way to rotate a three-dimensional vector by a quaternion defining an Euler rotation is via the formula

where is a quaternion containing the embedded vector , is a conjugate quaternion, and is the rotated vector . In computational implementations this requires two quaternion multiplications. An alternative approach is to apply the pair of relations

where indicates a three-dimensional vector cross product. This involves fewer multiplications and is therefore computationally faster. Numerical tests indicate this latter approach may be up to 30% [4] faster than the original for vector rotation.

Proof

The general rule for quaternion multiplication involving scalar and vector parts is given by

Using this relation one finds for that

and upon substitution for the triple product

where anti-commutivity of cross product and has been applied. By next exploiting the property that is a unit quaternion so that , along with the standard vector identity

one obtains

which upon defining can be written in terms of scalar and vector parts as

See also

References

  1. ^ a b NASA Mission Planning and Analysis Division (July 1977). "Euler Angles, Quaternions, and Transformation Matrices". NASA. Retrieved 24 May 2021.
  2. ^ Bernardes, Evandro; Viollet, Stéphane (10 November 2022). "Quaternion to Euler angles conversion: A direct, general and computationally efficient method". PLOS ONE. 17 (11): e0276302. Bibcode:2022PLoSO..1776302B. doi:10.1371/journal.pone.0276302. ISSN 1932-6203. PMC 9648712. PMID 36355707.
  3. ^ Blanco, Jose-Luis (2010). "A tutorial on se (3) transformation parameterizations and on-manifold optimization". University of Malaga, Tech. Rep. CiteSeerX 10.1.1.468.5407.
  4. ^ Janota, A; Šimák, V; Nemec, D; Hrbček, J (2015). "Improving the Precision and Speed of Euler Angles Computation from Low-Cost Rotation Sensor Data". Sensors. 15 (3): 7016–7039. Bibcode:2015Senso..15.7016J. doi:10.3390/s150307016. PMC 4435132. PMID 25806874.

Read other articles:

Nation's Restaurant NewsCover of the May 13, 2013, issueFrequencyBi-weeklyCirculation60,544Founded1967; 57 years ago (1967)CompanyInforma plcCountryUnited StatesBased inNew York CityLanguageEnglishWebsitewww.nrn.comISSN0028-0518 Nation's Restaurant News (NRN) is an American trade publication, founded in 1967.[1][2] NRN covers the foodservice industry, including restaurants, restaurant chains, operations, marketing, and events. It is owned by Penton Media (ac...

 

Bonkis adalah sebuah seri drama televisi Turki tahun 2021. Seri tersebut menampilkan Vildan Atasever, Oyku Naz Altay, Deniz Tezuysal, Sergen Deveci, Burak Sevinç, dan Mehmetcan Mincinozlu. Seri tersebut terdiri dari 15 episode.[1] Sinopsis Deniz merupakan seorang perempuan yang mengikuti mimpinya untuk membuka sebuah kafe bernama Bonkis. Denis sebenarnya memiliki karier di bidang arsitektur tetapi alih-alih melanjutkan profesinya, ia malah membuka kafe bernama Bonkis. Ia memang seora...

 

Chili pepper cultivar 'Siling Labuyo''Siling Labuyo' pepper. The small triangular fruits of siling labuyo are distinctively borne pointing upwards, like other Capsicum frutescens cultivars.GenusCapsicumSpeciesCapsicum frutescensCultivar'Siling Labuyo'Heat Very hotScoville scale80,000 - 100,000 SHU Siling labuyo at a Philippine supermarket Siling labuyo is a small chili pepper cultivar that developed in the Philippines after the Columbian Exchange. It belongs to the species Capsicum ...

IT for Business Pays France Zone de diffusion Pays Francophone Langue Français Périodicité Mensuel Genre spécialisé dans l'informatique Diffusion 63 165 ex. (2005) Date de fondation 1966 Ville d’édition Paris Directeur de publication Frédéric Ktorza Rédacteur en chef Pierre Landry ISSN 2258-5117 Site web https://itforbusiness.fr modifier  IT for Business, anciennement 01 Informatique[1] puis 01 Business, est un magazine mensuel français spécialisé dans l'informatique, cré...

 

For other uses, see Beaconsfield (disambiguation). Human settlement in EnglandBeaconsfieldMemorial Green, the Old Town, BeaconsfieldBeaconsfieldLocation within BuckinghamshireArea19.66 km2 (7.59 sq mi)Population12,081 (2011 census)[1]• Density614/km2 (1,590/sq mi)OS grid referenceSU9490Civil parishBeaconsfieldUnitary authorityBuckinghamshireCeremonial countyBuckinghamshireRegionSouth EastCountryEnglandSovereign stateUnited Kingd...

 

Chataio dalam peta Fra Mauro (sekitar tahun 1450). Dicatat bahwa selatan adalah di sebelah atas Bagian dari seri mengenaiNama-nama Tiongkok Cathay Empat Lautan Huaxia Kekaisaran Langit Sembilan Provinsi Serica Shenzhou Shina Tianxia Tiongkok lbs Cathay (/kæˈθeɪ/) adalah versi Anglikan dari Catai dan sebuah nama alternatif untuk Tiongkok dalam bahasa Inggris. Kata ini berasal dari Khitan[1] (Hanzi: 契丹; Pinyin: Qìdān), nama dari sebuah suku nomaden yang mendirikan Dina...

ParkstadionParkstadion pada 12 September 1998LokasiGelsenkirchen, JermanKapasitas62.004 (pertandingan liga)55.877 (pertandingan internasional)PermukaanRumputKonstruksiMulai pembangunan29 Agustus 1969Dibuka4 Agustus 1973Direnovasi1998Ditutup2008PemakaiFC Schalke 04 (1973–2001) Parkstadion adalah sebuah stadion yang terletak di Gelsenkirchen, Jerman. Stadion ini umumnya dipergunakan untuk menggelar pertandingan sepak bola dan menjadi markas FC Schalke 04 sejak tahun 1973 hingga 2001. Stadion ...

 

Monan ParkFull nameJ. Donald Monan, SJ ParkAddress150 William T. Morrissey BoulevardLocationBoston, Massachusetts, U.S.Coordinates42°18′57″N 71°02′32″W / 42.315854°N 71.042351°W / 42.315854; -71.042351Public transit MBTA:  Red Line   Greenbush Line   Old Colony Lines at JFK/UMass stationTypeBaseball parkCapacity500 (baseball)[3]Record attendance379 (May 25, 2019: UMass Boston vs. New England College)[4]Field...

 

Culture jamming activist duo This article is about the culture-jamming activists. For this group's 2003 documentary of the same name, see The Yes Men (film). For other things with similar titles, see Yes man (disambiguation). Part of a series onAnti-consumerism Theories and ideas Affluenza Alternative culture Anti-capitalism Autonomous building Billboard hacking Buyer's remorse Bioeconomics Buddhist economics Buy Nothing Day Collaborative consumption Collapsology Commodification Commodity fet...

Species of fish Lake whitefish Conservation status Secure  (NatureServe)[1] Scientific classification Domain: Eukaryota Kingdom: Animalia Phylum: Chordata Class: Actinopterygii Order: Salmoniformes Family: Salmonidae Genus: Coregonus Species: C. clupeaformis Binomial name Coregonus clupeaformis(Mitchill, 1818) Range of C. clupeaformis Synonyms[2] List Coregonus albus Lesueur, 1818Coregonus atikameg Bajkov, 1933Coregonus clupeaformis subsp. dustini Koelz, 1931Coregonu...

 

Shopping Centre London, United Kingdom Putney ExchangeLocationPutney, London, EnglandCoordinates51°27′49″N 0°12′59″W / 51.4636°N 0.2164°W / 51.4636; -0.2164Opening date1990OwnerBlackRockNo. of stores and services44No. of anchor tenants1 - WaitroseNo. of floors2Websiteputneyexchange.co.uk Putney Exchange is an indoor shopping centre in Putney, in the London Borough of Wandsworth. It was built in 1990, revamped in 2014, and is owned by BlackRock. Building The...

 

NGC 260Galassia a spiraleNGC 260 nelle immagini SDSSScopertaScopritoreGeorge Johnstone Stoney Data22 dicembre 1848 [1] Dati osservativi(epoca J2000)CostellazioneAndromeda Ascensione retta00h 48m 34.6s [2] Declinazione27° 41′ 33″ [2] Distanza235,5 mega anni luce (72,20 Mpc) [1][2] a.l.   Magnitudine apparente (V)13,5 [3] nella banda B: 14,2 [3][4] Redshift+0,017392 ± 0,000002 &#...

Boris BeckerKebangsaanJerman Barat (1983–1990) Jerman (sejak 1990)Tempat tinggalSchwyz, SwissTinggi190 m (623 ft 4+1⁄2 in)Berat85 kg (187 pon; 13,4 st)Memulai pro1984Pensiun30 Juni 1999Tipe pemainTangan kananTotal hadiah25.080.956 Dolar AS Pendapatan terbanyak ke-5 sepanjang masa Int. Tennis HoF2003 (member page)TunggalRekor (M–K)713–214 (76.91%)Gelar49Peringkat tertinggiNo. 1 (28 Januari 1991)Hasil terbaik di Grand Slam (tunggal)Australia TerbukaJuar...

 

County in Mississippi, United States County in MississippiWarren CountyCountyWarren County Courthouse in Vicksburg, built c. 1940, located across from the Old Courthouse Museum.Location within the U.S. state of MississippiMississippi's location within the U.S.Coordinates: 32°22′N 90°51′W / 32.36°N 90.85°W / 32.36; -90.85Country United StatesState MississippiFoundedDecember 22, 1809Named forJoseph WarrenSeatVicksburgLargest cityVicksburgArea •&#...

 

This article's lead section may be too technical for most readers to understand. Please help improve it to make it understandable to non-experts, without removing the technical details. (May 2024) (Learn how and when to remove this message) Networking hardware that forwards packets based on hardware address Avaya ERS 2550T-PWR, a 50-port Ethernet switch A network switch (also called switching hub, bridging hub, Ethernet switch, and, by the IEEE, MAC bridge[1]) is networking hardware t...

Japanese professional wrestler (born 1990) Naoki Tanisaki redirects here. Not to be confused with T. Hawk or Naoki Tanizaki. T-HawkOnodera in February 2022Birth nameTakuya OnoderaBorn (1990-04-30) April 30, 1990 (age 34)[1]Tomakomai, Hokkaido[1]Professional wrestling careerRing name(s)Mr. Pii Pii Tomakomai Penguin[1]Naoki Tanisaki[2]Takuya Tomakomai[2]T-HawkTomahawkTomahawk T.T.[2]Billed height1.74 m (5 ft 8+1⁄2 in)[...

 

DC Comics superhero Comics character Doctor Mid-NiteCover to JSA: All-Stars #6. Art by John Cassaday and Mark Lewis.Publication informationPublisherDC ComicsFirst appearanceMcNider: All-American Comics #25 (April 1941)Chapel:Infinity Inc. #19 (October 1985)As Doctor Midnight:Infinity Inc. #21 (December 1985)Cross:Doctor Mid-Nite #1 (September 1999)Created byMcNider: Charles ReizensteinStanley Josephs AschmeierChapel:Roy ThomasTodd McFarlaneCross:Matt WagnerJohn K. Snyder IIIIn-story informati...

 

Saab 32 Lansen (artinya Lance) adalah dua kursi, pesawat tempur serang transsonic tinggi sayap rendah (low wing) diproduksi oleh SAAB dari 1955 sampai 1960 untuk Angkatan Udara Swedia (Flygvapnet). Selama sepanjang umur operasionalnya, Saab 32 juga menjabat sebagai pesawat tempur, pesawat pengintai, pesawat peperangan elektronik dan pesawat sasaran-tunda. Spesifikasi (J 32B) Karakteristik umum Kru: 2 Panjang: 14,94 m (49 ft 0 in) Lebar sayap: 13,0 m (42 ft 8 in) Tinggi: 4,65 m (15 ft 3 in) A...

American actress This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This biography of a living person needs additional citations for verification. Please help by adding reliable sources. Contentious material about living persons that is unsourced or poorly sourced must be removed immediately from the article and its talk page, especially if potentially libelous.Find sources: Sarah Jones...

 

Pour les articles homonymes, voir PM et Mitraillette. Ne doit pas être confondu avec Fusil-mitrailleur. Le HK MP5 est un pistolet-mitrailleur allemand très répandu dans toutes les armées du monde en tant qu'arme tactique depuis la fin des années 1960. Le général John T. Thompson brandissant un Thompson M1921. Le pistolet-mitrailleur (PM), aussi appelé mitraillette[1],[a], est une arme à feu individuelle à tir automatique utilisant une cartouche de pistolet. Ce type d'arme apparaît...