Last Updated:

Quaternion

Andrea Del Bravo
Andrea Del Bravo

Preface

Let’s now face another central argument to solve the problem to find the attitude of an aircraft in a clean, consistent, reliable way on a digital computer. To follow this post is essential some basic knowledge of complex number (see “Complex numbers” post)

Quaternion, this amazing mathematical entity

Hamilton in 1843 introduced this new mathematical entity: here we don’t want to enter into specific mathematical important issues, like the consistency and the completeness of the theory. We assume its validity and we want only understand its meaning and its use.

The definition I like is my own interpretation of this entity. Let’s make this observation: let’s assume that a three dimensional vector is an extension of one dimensional representation of a real number. The quaternion has the same meaning, for complex number: they are a three dimensional extension of the imagery part of a complex number, that is:

q=q0+iq1+jq2+kq3   1)

where i, j, k are three unitary pure imaginary number (in analogy with i, j, k versors of a real three dimensional reference system).

q0 is called the real or scalar part of the quaternion, while iq1+jq2+kq3 is called the imaginary or vector part of the quaternion.

Furthermore i, j, k obey to the following rules:

i2=1 j2=1 k2=1

but they are non commutative respect to multiplication. In fact:

ij=ji kj=jk ki=ik It is easy to show that

ij=k jk=i ki=j ji=k kj=i ik=j

The conjugate of quaternion 1) is

q~=q0iq1jq2kq3

Using the shown quaternion properties

qq~=q02+q12+q22+q32

which is called the length or norm of the quaternion

Now we know almost all we need for using quaternions: one additional rules will be demonstrated later concerning the derivative of a quaternion.

Let’s now consider a vector V in the real world whose components are X, Y, Z. Let’s now “transport” our vector from the “real world”, in the “quaternion world”. In this new world our vector assume the form of a pure imaginary quaternion, that is

V=iX+jY+kZ

Let’s now examine the operation

V'=q~Vq    2)

where q is a versor ( q02+q12+q22+q32=1 )

Equation 2) can be written as:

V'=(q0iq1jq2kq3)(iX+jY+KZ)(q0+iq1+jq2+kq3)   3)

Adopting the just learned quaternion rules, relation 3) becomes:

V'=i[X(q02+q12q22q32)+Y(2q0q3+2q1q2)+Z(2q1q32q0q2)]+

+j[X(2q1q22q0q3)+Y(q02q12+q22q32)+Z(2q0q1+2q2q3)]+

+k[X(2q0q2+2q1q3)+Y(2q2q3q0q1)+Z(q02q12q22+q32)]   4)

Relation 4) can be written as:

(X'Y'Z')=((q02+q12q22q32)(2q0q3+2q1q2)(2q1q32q0q2)(2q1q22q0q3)(q02q12+q22q32)(2q0q1+2q2q3)(2q0q2+2q1q3)(2q2q3q0q1)(q02q12q22+q32))(XYZ)   5)

which simply represents a coordinate transformation.

It is extraordinary important to note that relation 5) is identical to relation 3) of the post “Euler parameters”, when we pose:

q0=a1=cosμ2    q1=a2=cosαsinμ2   6)

q2=a3=cosβsinμ2q3=a4=cosγsinμ2

This means that operation 2) is equivalent to the rotation of the reference system around a vector represented by the imaginary (or vector) part of the quaternion, of an angle μ.

Furthermore, as anticipated in the post “Euler parameters”, it establishes an equivalence between the Euler parameters and the component of the quaternion representing the identical rotation.

Double rotations

The matter of two successive rotations may be easily handled. Consider the following transformation just seen above:

V'=q1~Vq1   7)

and apply to V' another rotation by means of quaternion q2.

V''=q2~V'q2=q2~q1~Vq1q2   8)

Let’s call q3=q1q2 and q4=q2~q1~

Expression 8) takes the form

V''=q4Vq3     9)

It’s easy to demonstrate that both q3 and q4 are versors and that q4=q3~ and thus expression 9)

V''=q3~Vq3     10)

This means that two subsequent rotation, the first described by quaternion q1, the second described by quaternion q2, is equivalent to a rotation described by quaternion q3 = q1 q2. This rule will be useful in the next paragraph

Quaternion differentiation

In this part we face the problem of quaternion differentiation which plays a fundamental role to find our solution. In the following I use a less formal mathematical approach, maybe not loved by mathematicians, but very effective for an engineer like me. Furthermore I’ve never seen in literature a similar approach. Let’s define the derivative of a quaternion as the limit of the incremental ratio when the increment going to zero, i.e.

dqdt=limΔt0q(t+Δt)q(t)Δt    11)

Rotation represented by quaternion q(t+Δt) can be thought as a rotation until time t, and a subsequent infinitesimal rotation during time Δt, that we call Δμ .Remembering what just learned in the previous paragraph this means:

q(t+Δt)=q(t)q(Δt)     12)

Let’s consider now the quaternion q(Δt) related to the infinitesimal rotation Δμ . According to the definition

q(Δt)=cosΔμ2+isinΔμ2cosα+jsinΔμ2cosβ+ksinΔμ2cosγ  13)

We recall that α,β and γ represent the three angles the rotation axis makes with the three axis X, Y and Z.

Being Δμ infinitesimal we can assume cosΔμ21 and sinΔμ2Δμ2

Relation 13) becomes

q(Δt)=1+iΔμ2cosα+jΔμ2cosβ+kΔμ2cosγ=1+ϵ   14)

where ϵ=iΔμ2cosα+jΔμ2cosβ+kΔμ2cosγ  15)

using 14), definition 12) becomes

dqdt=limΔt0q(t)q(Δt)q(t)Δt=limΔt0q(t)(1+ϵ)q(t)Δt  and finally

dqdt=limΔt0q(t)ϵΔt=q(t)limΔt0ϵΔt  16)

but limΔt0ϵΔt represent the derivative of ε respect to time and relation 16) can be written as

dqdt=q(t)dϵdt   17)

From 15) let’s calculate dϵ/dt

dϵdt=12(ìcosα+Jcosβ+kcosγ)dμdt=12(ìcosα+Jcosβ+kcosγ)ω

being the derivative of the angle of rotation around the axis of rotation equal to the angular velocity. Recalling that cosα,cosβ,cosγ are the cosines of the angles the axis of rotation forms with the X, Y and Z axis, we can affirm that

ωcosα=ωx=P  component of the angular velocity along X axis

ωcosβ=ωy=Q  component of the angular velocity along Y axis

ωcosγ=ωz=R  component of the angular velocity along Z axis

where we have used the classical aeronautical notation to identify the three angular velocities of roll, pitch and yaw around the X, Y, Z aircraft axis (P, Q, R).

Finally, adopting a synthetic notation

dqdt=12q(t)ω¯    q˙=12q(t)ω¯  18)

where

ω¯=ìωx+jωy+kωz=ìP+jQ+kR

is the pure imaginary quaternion representing the overall angular velocity around the rotation axis

Relation 18) represents the key to calculate the quaternion components. Solving the differential equation 18) we know the q0,q1,q2,q3 components of the quaternion and from these components we will show how to calculate the attitude angles psi, theta and fi of the aircraft.

We now need to open a parenthesis over relation 18). In all text related to quaternions the derivative of a quaternion respect to time can assume the following expression:

q˙=12ω¯q(t)

but in this case the considered rotation is related to a point around an axis of rotation identified by the quaternion, remaining in the same reference system, while expression 18) represent the rotation of the reference system around an axis of rotation identified by the quaternion, which is the case study we are interested on, as explained in the post “Euler parameters”.

Developing relation 18) we obtain:

q0˙+iq1˙+jq2˙+kq3˙=12(q0+iq1+jq2+kq3)(ìP+JQ+kR)

q0˙+iq1˙+jq2˙+kq3˙=12(iPq0+JQq0+kRq0Pq1+kQq1jRq1--kPq2Qq2+iRq2+jPq3iQq3Rq3)

q0˙+iq1˙+jq2˙+kq3˙=12(Pq1Qq2Rq3)+12i(Pq0+Rq2Qq3)++12j(Qq0Rq1+Pq3)+12k(Rq0+Qq1Pq2)   19)

if we adopt a matrix notation we can write 19) as

(q0˙q1˙q2˙q3˙)=12(0PQRP0RQQR0PRQP0)(q0q1q2q3)   20)

Equation 20) is the key mathematical relation that allows us, once solved, to determine the component of the quaternion when P, Q and R angular velocities are known. In the post LL_algo we focalize our effort in solving differential equation 20) with an optimize algorithm with the paramount characteristic to be immune from the “gimbal lock” problem.

Quaternion-Euler Angles relation

One more notion we will need in solving equation 20), is the definition of the initial value of the quaternion, giving the initial values of the Euler angles of the aircraft.

Let’s suppose that the initial attitude of the Aircraft is defined by the angles ψ, ϑ and φ.

Let’s start with ψ. We learned in the post “Euler Angles”, that ψ is the first rotation around the Z axis. Let’s try now to apply what we learned in this post about quaternions: how to express this rotation in terms of quaternions?

First af all we know the axis of rotation, the Z axis: this means that ɑ and β in 6) are π2 while γ is equal 0. In addition we know that the angle of rotation is ψ: so the generic quaternion

(cos(μ2)cos(α)sin(μ2)cos(β)sin(μ2)cos(γ)sin(μ2))  assumes the form  qψ=(cos(ψ2)00sin(ψ2))  21)

Repeating the same reasoning for , ϑ and φ we reach to the following :

qθ=(cos(θ2)0sin(θ2)0)     qϕ=(cos(ϕ2)sin(ϕ2)00)   22)

The 3 quaternions above can be written as:

qϕ=cos(ϕ2)+isin(ϕ2)    23)

qθ=cos(θ2)+jsin(θ2)    24)

qψ=cos(ψ2)+ksin(ψ2)   25)

In this post we have already learned how to face the issue of multiple rotation (see relation 9)). Applying the same concept, we can say that the resulting quaternion qr which takes into account the 3 rotations expressed by 23), 24) and 25) is

qr=qψqθqϕ    26)

substituting 23), 24), and 25) in 26)

qr=(cos(ψ2)+ksin(ψ2))(cos(θ2)+jsin(θ2))(cos(ϕ2)+isin(ϕ2))

The result of this operation (taking into account all the rules related to multiplication among i, j and k, as discussed at the beginning of this post) is:

qr=cos(ϕ2)cos(θ2)cos(ψ2)+sin(ϕ2)sin(θ2)sin(ψ2)+

+isin(ϕ2)cos(θ2)cos(ψ2)cos(ϕ2)sin(θ2)sin(ψ2)+

+jcos(ϕ2)sin(θ2)cos(ψ2)+sin(ϕ2)cos(θ2)sin(ψ2)+

+kcos(ϕ2)cos(θ2)sin(ψ2)sin(ϕ2)sin(θ2)cos(ψ2)

which can be written in quaternion notation as

qr=(cos(ϕ2)cos(θ2)cos(ψ2)+sin(ϕ2)sin(θ2)sin(ψ2)sin(ϕ2)cos(θ2)cos(ψ2)cos(ϕ2)sin(θ2)sin(ψ2)cos(ϕ2)sin(θ2)cos(ψ2)+sin(ϕ2)cos(θ2)sin(ψ2)cos(ϕ2)cos(θ2)sin(ψ2)sin(ϕ2)sin(θ2)cos(ψ2))   27)

Relation 27) will be used to initialize quaternion values once the 3 attitude angles are known

0
Andrea Del Bravo

Andrea Del Bravo

Aerospace industry, working in many international programs and international teams. Major programs: Project Manager for the development of Aircrew Synthetic Trainig Aids for the EF 2000 (Eurofighter Typhoon) Scientific responsible for the TCTUE (Time Critical Targeting in Urban Environment) project. A collaboration among German MoD, USA Air Force and Italina MoD to develop and evaluate algos and assets for detecting and suppressing terrorist un-armored vehicle using a swarm of UCAV in urban environment reducing collateral damages to a maximum extent. This project won the LEONARDO Innovation award in 2016. AMX aircraft: Flight Simulator development for testing FCS, Avionics: development of attack modes, navigation modes. EF 2000 (Eurofighter Typhoon). Flight Simulator development for fine tuning and testing of avionics system. C27J Spartan: Flight Simulator development for fine tuning and testing of avionics system and engine integration. ISR systems Detect and Avoid (ACAS) Menber of NATO RTO-TR-SAS-013 Aircrew Mission Training via Distributed Simulation Member of NATO Industry Advisory Group (NIAG) SG 128 Study on Airborne C-IED

Comments