- Home /
Explanation of Quaternion.ToAngleAxis(), what it does, when to use.
Hi,
Just wondering if anyone can provide a little more information on what this function does and when to use it. Also, what exactly is an 'angle-axis representation of the rotation'?
Thanks
Answer by Bunny83 · Sep 04, 2016 at 09:40 PM
A lot people seem to have problems to understand what a quaternion actually is. I always suggest to first watch this Numberphile video. It should cover the basics in the most understandable way I've ever seen.
A quaternion actually represents a vector \ axis and an angle around that axis but as a 4 dimensional complex number.
ToAngleAxis just extracts the angle as well as the axis that this quaternion represents
I ended up finding that Quaternions were based on complex numbers months ago (I discovered then that complex numbers existed as well). In any case, the link you posted might be useful for a better understanding of how the quaternions work.
Answer by Anxo · Jan 27, 2013 at 09:29 PM
It just converts your rotation to a different format. For instance if you are not looking for a Quaternion.Euler Vector 3 but your code is calculating some Axsis instead you can use this to get the axis and angle.
What the example in the documentation does is it sets up to variables and then populates them with the angle and axis of the current transform.
Oh I see, that makes more sense now :)
So say for example, my transform has rotation (30, 45, 0). The Angle that's extracted is: 53.65 and Axis: (0.5, 0.8, -0.2). How might I go about interpreting these values, or what can I then go on to use to plug them into?
Thanks
Good answer, but I still have a critical doubt about it that haven't been properly explained yet (not in this answer, neither in the docs:
The input args are both "out" flagged (I know what this means). The point is: can I input any crosswise axis, and obtain it's relative angle from the angle arg?
Reading the docs I can guess "well, it seems so... doesn't it?". However, the fact that axis is also out flagged is kinda confusing; I mean, what's the point for it at all?
I've posted an answer that might clear up some confusion. Out parameters don't pass in any values. Out parameters can only be used to return values. Those parameters can't be read inside the method.
Out parameters are usually used when a method need to return more than one value.
@Bunny83 Due to quaternions mathematics are beyond my current level, I'd rather use them through their methods... Anyway, looking at your comment, quoting: "out parameters don't pass in any values"...
The reason I was interested in this method is because I needed some kind of function that, having a Quaternion and a normalized Vector3 acting as axis, could output the Euler angles relative to the axis. I thought`Quaternion.ToAngleAxis()` might be what I needed, but it seems that it isn't...
Before I thought out args were useful for both input and output, but it seems I was wrong.
"out" parameters only "output" a value. Even more: they are required to be set inside the method. What you have in $$anonymous$$d is a "ref" parameter. It's simply passed by reference so the method can read it's content and change it if it wants to.
Eulerangles specify a complete rotational space (no translation). A single axis doesn't specify a space as the orientation of the other axis isn't clear.
Feel free to post a seperate question on your actual problem. $$anonymous$$ake sure you provide more context of what you want to do and what you need those values for.