Comments and answers for "Please explain Quaternions!"
http://answers.unity.com/questions/645903/please-explain-quaternions.html
The latest comments and answers for the question "Please explain Quaternions!"Answer by Roobubba
http://answers.unity.com/answers/1654688/view.html
I hope this isn't too much of a necro, but I came here while on the search for a better understanding of quaternions and later found several resources which earlier me would have benefited from at the point I was reading this page.
3Blue1Brown is a **fantastic** youtube channel explaining so many areas of mathematics in a brilliant, visual style. Grant Sanderson and Ben Eater put together an absolutely excellent tutorial series with interactive applet on this. Honestly, if you've any questions about quaternions and particularly if you're into game design (so you're probably a very visual learner), go check it out:
https://eater.net/quaternions/
This gave me a much better understanding of what quaternions are, and why you multiply them in Unity (and why order matters).
For reference (and because the unity documentation is coy about this), the w component is the real component and x, y and z are the imaginary i, j, and k factors in unity's implementation.Mon, 05 Aug 2019 09:34:17 GMTRoobubbaAnswer by guy123
http://answers.unity.com/answers/1244054/view.html
Everything is simple when you know how, so don't let Quaternions be any different.
One of the main reasons people don't understand Quaternions is because they can't visualise them, or the effect they have on a rotation. There are many suggested reasons as to why Quaternions are hard to visualise, but my theory is that natural mathematicians aren't great visual explainers - it's not that they're holding back information, simply don't know how to explain it in a way us more visual learners can comprehend.
So, the best way to 'visualise' a quaternion is this:
Imagine you have a small lump of clay and a load of tooth pics.
Slide a tooth pick through the clay on each of it's individual axis, X, Y and Z.
Rotate the tooth picks, notice how the clay is being rotated on one of it's axis at a time. This is how normal Euler axis work, and how most people understand rotation.
Now, grab another tooth pick and jam it into the clay at any angle you want!
Rotate the new tooth pick on it's own axis, notice it isn't constrained to the x, y or z axis but is rotating on it's own 'new' and unique axis.
This ^ is a quaternion, whenever you are reading up on them from now on, think of this example and hopefully it should make a little more sense.Thu, 15 Sep 2016 13:18:12 GMTguy123Comment by KdRWaylander on KdRWaylander's answer
http://answers.unity.com/comments/1162969/view.html
Double complex rotation it is:
https://www.youtube.com/watch?v=3BR8tK-LuB0Wed, 30 Mar 2016 08:02:48 GMTKdRWaylanderComment by whydoidoit on whydoidoit's comment
http://answers.unity.com/comments/1161752/view.html
Well a quaternion is a vector and a spin. Just the mathematical representation of that is the vector and a variety of sines and cosines of the angle of spin.
![Quaternion](https://www.dropbox.com/s/3y2cwlh738c6lsm/Screenshot%202016-03-27%2022.51.45.png?raw=1)Sun, 27 Mar 2016 21:19:37 GMTwhydoidoitComment by Owen-Reynolds on Owen-Reynolds's answer
http://answers.unity.com/comments/1161748/view.html
This explanation is wrong. Print a vector, then print the quaternion you get from LookRotation -- they are different.
You can _think of_ a Quaternion as an y,x,z rotation, or as a vector3 plus a spin, or as a rotation matrix, or as a single rotation around some axis. And that's the point -- think of rotations however you like, them let the system handle them through Quaternions.
Quats aren't a Unity thing -- they're standard in game engines. The reason is they handle combining or (s)lerping or angle-between well. Other methods of representing orientation aren't as good at performing those operations.Sun, 27 Mar 2016 21:15:22 GMTOwen-ReynoldsAnswer by deCalle
http://answers.unity.com/answers/1161477/view.html
**Well actually it seems, I must be genius or utterly retarded, I don't know yet, but as whydoidoit said, it would be a nice approach to have, still the quaternions seem to be more complicated than i would like to accept. yo then i finally have to pose a question^^**
Could you all please stop saying this all "You don't need to understand this" bullshit. Of course you need to. quaternions are part of the basics in all of unity and actually I don't understand why xyz rotation is used when you could simply use quaternions. Because they aren't much different but have an additional angle value.
So here's the deal: quaternions are vector3s with an additional rotation angle. The direction the vector points actually IS the rotation. So think of it as a rotation not based on its personal xyz dimension but on the unified global xyz dimension. This additional rotation angle actually is the personal 'roll' ( like rolling the vector like a cigarette. Smoking sucks btw) and is the last component of having maximal rotation freedom.
The reason why you think it's complicated is because mathematicians tend to be unable to explain shit. So they keep the obvious mystical, especially when they keep the benefit of knowledge from you to make themselves a necessary evil. Or because of their organizational blindness. But I stick with the first reason ,because the second is just an excuse. ;-)Sun, 27 Mar 2016 20:18:03 GMTdeCalleComment by whydoidoit on whydoidoit's answer
http://answers.unity.com/comments/1161657/view.html
You know the more I think about @deCalle's point the more I think it would be really nice if we had a rotation component that was X,Y,Z,W where each was the rotation in degrees around world X,Y,Z axes and the direction entailed. Would be really nice to use that :) Internally it would have to form a quaternion, but could provide such an interface - would make life much clearerSun, 27 Mar 2016 16:15:03 GMTwhydoidoitComment by IAMBATMAN on IAMBATMAN's comment
http://answers.unity.com/comments/1161655/view.html
Is it just me or does unitygems not work?
I'm just getting "page ok" from that link.Sun, 27 Mar 2016 16:13:55 GMTIAMBATMANComment by whydoidoit on whydoidoit's answer
http://answers.unity.com/comments/1161651/view.html
I think the need for quaternions is sometimes not well understood. I see it like this. A set of Euler angles can easily represent a line pointing in any possible direction. However we are rarely dealing with lines, our objects have volume. As soon as an object has volume then that shape can also be rotated around the direction it's facing. Hence the need for 4 values to describe the exact rotation of something which isn't a line.
Now it so happens that in many orientations you could represent all four of these axes of rotation using 3 world axes - however it's clear that there must be places where we run out of dimensionality using just 3 values to represent 4 things. Hence the need for quaternions.
I see @deCalle's point - as soon as you realise that a Euler angle misses a dimension of rotation that clearly always exists, then you start to wonder why the hell you'd use any other representation which is clearly flawed.
So a quaternion is a representation of a vector and a rotation around that vector. **BUT** the individual elements are interdependent, you can't just go around modifying them individually without screwing everything up. Quaternions are considered a "thing" that can be used as a value in a calculation, but unlike vectors or Euler angles you can't just go and change one component to get a simple expected effect.
Basically if a quaternion was just a normalized direction and a number which was the rotation around that direction then it would all be super simple. But they aren't that. Each element of a quaternion is multiplied by the sin or cos of the angle of rotation.
Avoiding gimbal lock is important and you can trivially use "whole" quaternions to point anything at anything else. Changing the individual values - err, well, can't say I ever do :)Sun, 27 Mar 2016 16:06:21 GMTwhydoidoitComment by meat5000 on meat5000's answer
http://answers.unity.com/comments/1161617/view.html
Quaternions are counter intuitive. They are also complicated for beginners and non-mathematicians. (Despite being an engineer and understanding them) Ive never once needed to actually know the workings of a Quaternion to use them in Unity. The methods provided actually take out a lot of the need to know how they work. In that sense they become some intermediate block that just gets converted from and to and not worried about beyond that.
*Of course, everyone should eventually learn it*, but it is certainly true that you dont need to to use them in Unity and its a bit of a waste of time, to be honest (with so much other stuff that you need to learn to simply operate Unity and there not being enough time in the day).Sun, 27 Mar 2016 14:11:48 GMTmeat5000Comment by johnbangla
http://answers.unity.com/comments/1064436/view.html
I don't think so. IT it very much important to know how it works.If someone want to implement something advance it is required. Isthere anyone who will explain using graphical presentation.Thu, 10 Sep 2015 18:14:42 GMTjohnbanglaComment by rocket350 on rocket350's answer
http://answers.unity.com/comments/658791/view.html
@Scribe thanks so much for this great answer.Sat, 08 Mar 2014 18:06:56 GMTrocket350Comment by Scribe on Scribe's answer
http://answers.unity.com/comments/646298/view.html
@whydoidoit nice stuff! keep up the great work on the tutorials!Fri, 21 Feb 2014 23:49:59 GMTScribeComment by zombience on zombience's answer
http://answers.unity.com/comments/646071/view.html
ah, thanks for the reply. i'm afraid there was some confusion surrounding my account when unity switch to the new qato back end some time ago, so i have two accounts. i uh, tried to sort it out, and though it was sorted. i'll go back and email them again.Fri, 21 Feb 2014 18:45:23 GMTzombienceComment by whydoidoit on whydoidoit's answer
http://answers.unity.com/comments/646026/view.html
Appended to article, here for your reference: http://unitygems.com/quaternions-rotations-part-1-c/#appendixFri, 21 Feb 2014 17:25:52 GMTwhydoidoitComment by whydoidoit on whydoidoit's answer
http://answers.unity.com/comments/646021/view.html
The Quaternions tutorial is about how to use them - almost explicitly the opposite of what you explained here - which I did not feel qualified to write :)Fri, 21 Feb 2014 17:16:39 GMTwhydoidoitComment by Scribe on Scribe's answer
http://answers.unity.com/comments/646014/view.html
@whydoidoit - Of course! I haven't seen your tutorial but if you think I've missed anything that you've explained there feel free to add it, or put it as a link under 'Links' :)
@zombience glad I could help! I feel like I should be quoting J. R. R Tolkien - "May it be a light to you in dark places, when all other lights go out."
P.S how do I @ you zombience :'(Fri, 21 Feb 2014 17:06:31 GMTScribeComment by zombience
http://answers.unity.com/comments/645991/view.html
Women explained: yes and no, at the same time.Fri, 21 Feb 2014 16:40:38 GMTzombienceComment by zombience on zombience's answer
http://answers.unity.com/comments/645989/view.html
awesome! Thank you for the explanation. Quaternions are one of those dark corners of Unity coding that I've used and been very curious about, but mostly have just left alone in a box marked "Black Magic -- Do Not Open". While I still am going to leave it in that box, this has helped shine a small light on it for a moment, so I can be a little less afraid
^_^Fri, 21 Feb 2014 16:39:19 GMTzombienceComment by whydoidoit on whydoidoit's answer
http://answers.unity.com/comments/645986/view.html
Would like permission to add this to the Unity Gems quaternions tutorial as a reference if you don't mind.Fri, 21 Feb 2014 16:36:26 GMTwhydoidoitComment by whydoidoit
http://answers.unity.com/comments/645984/view.html
Check out http://unitygems.com/quaternionsFri, 21 Feb 2014 16:34:29 GMTwhydoidoitAnswer by Scribe
http://answers.unity.com/answers/645970/view.html
Hello!
Firstly I should point out that you will probably never need to know any of this to successfully code in Unity and, unless you become very knowledgeable about Quaternions, should probably never set them directly. That is not to say you can't, but it is generally advised against unless you know what you are doing!
Secondly, there is a heck of a lot of information out there on the internet on the subject of quaternions and/or converting them to Euler angles (and other rotation representations).
Thirdly, for anyone who is looking for just the function to handle all this for you checkout:
1. [Quaternion.eulerAngles][1]
2. [Quaternion.Euler][2]
## The Basics ##
A quaternion rotation is made up of 4 numbers, whose values all have a minimum of -1 and a maximum of 1, i.e (0, 0, 0, 1) is a quaternion rotation that is equivalent to 'no rotation' or a rotation of 0 around all axis.
Quaternions are widely used in coding as:
1. They are almost always unique, as opposed to Euler angles where 360 degrees around an axis is the same as 0 around the same axis, is the same as 720.. etc, this confusion does not exist with quaternions, where every orientation is related to 2 quaternion, q and -q.
2. They are simple to create/compose
3. They are 'easy' to interpolate between (as they are not commutative i.e a*b =/= b*a), whereas Euler Angle representation suffers from 'gimbal lock'.
**Note:**
All rotation quaternions are unit quaternions (their length is 1).
## Conversions ##
**Angle-Axis to Quaternion**
Given a normalized (length 1) axis representation (x, y, z) and an angle A.
The corresponding quaternion is equal to:
Q = [sin(A/2)*x, sin(A/2)*y, sin(A/2)*z, cos(A/2)] (corresponding to [x, y, z, w])
**Euler angle to Quaternion**
Given an Euler rotation (X, Y, Z) [using orthogonal axes]
x = sin(Y)sin(Z)cos(X)+cos(Y)cos(Z)sin(X)
y = sin(Y)cos(Z)cos(X)+cos(Y)sin(Z)sin(X)
z = cos(Y)sin(Z)cos(X)-sin(Y)cos(Z)sin(X)
w = cos(Y)cos(Z)cos(X)-sin(Y)sin(Z)sin(X)
Q = [x, y, z, w]
## Slerp (Spherical linear interpolation) ##
To interpolate between two quaternions is very simple:
Let t be a value that increases from 0 to 1.
The angle (A) between the two quaternions can be found using the dot product:
Q1*Q2 = Q1.x*Q2.x+Q1.y*Q2.y+Q1.z*Q2.z+Q1.w*Q2.w = A
then the **un-normalized** interpolation (Q3) is `(sin((1-u)A)/sin(A))*Q1 + (sin((uA)/sin(A))*Q2`
to find the normalized quaternion you need to divide by Q3's length.
Q3/|Q3| = Q4
Hence, Q4 is a Quaternion rotation between Q1 and Q2 based on t.
## Links/Extra reading ##
1. [Euler to Quaternion][3]
2. [Quaternion To Euler][4]
3. [AngleAxis to Quaternion][5]
4. [Quaternion to AngleAxis][6]
On these pages heading is the rotation around y, attidue around z, and bank around the x axis.
## Disclaimer ##
I am nowhere close to an expert at quaternions, so I apologise if anything I have written is incorrect. I marking this as a community wiki, so feel free to change something if its incorrect!
Scribe
[1]: http://docs.unity3d.com/Documentation/ScriptReference/Quaternion-eulerAngles.html
[2]: http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.Euler.html
[3]: http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm
[4]: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm
[5]: http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
[6]: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htmFri, 21 Feb 2014 16:16:08 GMTScribeAnswer by tdev
http://answers.unity.com/answers/645933/view.html
You don't need to understand Quaternions directly, just how you should use them. Been using Unity for years and you just need to understand they are a representation of an angle, not how they work. it's wasted effort most likely.
Why do you want to understand them and then maybe we can work out what you really want to know :) If you're just worried that they are mysterious, don't worry, I was like that too but unless you're deep into a 3D math problem I'd ignore them for now.Fri, 21 Feb 2014 15:35:21 GMTtdevComment by Linus
http://answers.unity.com/comments/645934/view.html
Should convert to answer. Explain Quaternions, Ill do that if you explain women.Fri, 21 Feb 2014 15:31:53 GMTLinusComment by unimechanic
http://answers.unity.com/comments/645925/view.html
You need to understand the maths behind Quaternions, have you checked this article on the matter?
http://3dgep.com/?p=1815Fri, 21 Feb 2014 15:24:02 GMTunimechanic