How Quanternion works?

I’ve read a lot of documents about Quaternion and don’t even know what it is and how it works. Please help me understand it with your knowledge and experience.(easiest way)

Quaternions are the extension of complex numbers. Instead of just using the real number line (1) and imaginary number line (i), they use two more imaginary axes (j and k). All four of these are perpendicular to each other.

When normalized, they represent rotation as the projection of the surface of a four dimensional hypersphere onto our 3 dimensions.

If you are familiar with the fact that multiplying a complex plane by i will rotate that plane by 90 degrees, quaternions are like that but with 3 mystery numbers.


If you did not understand any of the above sentences, don’t worry, you are in good company. Quaternions are literally more complex than the complex numbers.

The important fact for you is that they accurately and compactly represent rotation in a way that can be easily added to and interpolated. The precise how and why is irrelevant to most of us, as unity abstracts and simplifies all this into digestible functions. (Quaternion.LookRotation(), Quaternion.Lerp()…)


Any time you could access Quaternions (e.g. through transform.rotation), you probably want to use transform.eulerAngles (or Quaternion.Euler(x,y,z)) instead, as it uses the much more intuitive 3 numbers from 0 to 360, one for each axis that we’re all used to.

The fact is that as 3-dimensional beings, it is virtually impossible to intuitively understand the ins and outs of an object with four spatial dimensions. However, a computer doesn’t care - it’s all just math - and quaternions offer a much more efficient and powerful system to them.


If you want to try changing the individual values and see what that effect they have, the docs contain a code sample which should allow you to do just that: Unity - Scripting API: Quaternion.z

But in the real world, you’ll never need to change the individual 1,i,j,k values of a quaternion (w,x,y,z in unity), as you can always convert to and use the intuitive x,y,z euler values instead.


TL;DR: Quaternions are black magic, use eulerAngles or the abstracted Quaternion functions instead (Quaternion.LookRotation(),…)

Hope this helps! :smiley:

Hello!

Quaternions are a way to calculate rotations. It is very usefull for games where you can freely move in 3 dimensions, like piloting spaceships. The main difference with Euler rotation vectors is that they do not have fix points.

In Euler, if you are looking at “the sky” lets say at 88º high (almost 90) and then want to torn left, your vision will make a small circle in the sky, because you are rotating towards vertical axis.

Quaternions does not have this limitation. But quaternions are hard to imagine, its full maths.

Bye!!

I can really recommend this short video with a clear explanation and visualisation: Basic Intro to Quaternions for 3D Rotations - YouTube


The main reasons for using quaternions is because you can interpolate smoothly between two angles, and to avoid gimbal lock where you would lose a degree of freedom.

However, since they are hard to understand (or at least to visualise), unity has implemented ways to easily transform Euler angles to quaternions, or the other way around, so I would suggest to use those.

thank y’all so much!!