Quaternions kicked my ass AGAIN.

Yeah, those things are a royal pain

It still bothers me that I have no real idea about what they are or how they work. All I think I know is that they are something to do fourth dimension projections and oh no I’ve gone cross eyed. I’m not bad at maths, in fact, when I put my mind to it, I’m quite good. The problem is that I’ve rarely really put my mind to it. When I did, I got A’s. Unfortunately, that was not very often! I have, however, now decided that I’m going to truly, and fully get to the bottom of what and how quaternions work.

So how you gonna do that then?

By the power and majesty of that which is called YouTube. No, I mean really. YouTube has videos for literally everything now. I had a quick search and started watching a few videos, and fully intend to watch them to completion on the bus at some point (namely https://www.youtube.com/watch?v=KdW9ALJMk7s, https://www.youtube.com/watch?v=uRKZnFAR7yw and https://www.youtube.com/watch?v=SCbpxiCN0U0).

What was the problem then?

Well, part of the problem was me fundamentally failing to understand rotations, and when challenged with the truth, it instantly became obvious. I was having trouble with projecting regular space onto a specific ship space, so that I could then work out where that ship was in relation to the ship that was doing the looking. So, I wrote a program that had two ships in it, with a couple of 3D views and controls for adjusting the position and orientation of the two ships. Not a big deal here. But, then I came to the issue of attempting to adjust the ships orientation. Now, the orientation was stored as a quaternion, in order to attempt to avoid gimbal lock and other associated problems. The problem is that I couldn’t find a sensible way of converting a quaternion back into its source pitch yaw and roll. Now, I’m still a little hazy on this whole thing, and I’m not actually convinced I’m right about what I’m wrong about, but it would seem that converting a quaternion back into the source yaw pitch roll just isn’t possible. I basically wrote a unit test around converting a quaternion back to yaw pitch roll that had just been generated, and found several examples of how to do this on the internet. The problem is that I couldn’t get any of them to work.

That doesn’t really sound like a quaternion problem.

You’re right, it isn’t really, but the point is, that it was a result of me not understanding the realtionship between yaw/pitch/roll and quaternions fully, and also, not being able to natively “read” quaternions. If I had, I’m quite sure that half the problems I was having with the roll/ pitch/ yaw conversions wouldn’t have been problems, and the whole program would have come together a lot more easily. Who knows, I might even have ditched the yaw pitch roll control and just had a quaternion control instead. The problem is that it seems to be basically impossible to consistently convert a quaternion back into the yaw pitch and roll that it came from.

So you didn’t actually get anything done then?

Well actually I did. When the unit testing showed that my current understanding/ implementation was flawed, I hacked it a little bit, which is to say that I just stored the yaw pitch roll as values and then create the quaternion each time. I know, I know, I’m opening up to gimbal lock et al, but for that example it was fine, as I wasn’t attempting to update an existing rotation as each scene was effectively static. In the end, it worked perfectly and I was able to see exactly which things were working and which weren’t. I had previously day dreamed a vague solution about using an inverse matrix of the quaternion on the target ship, and that seemed to work, except I was clearly getting some weird angles out. Adjusted the trig a little and all was fine, and that interception helper method now works!


Anyway, I think that’s quite enough for now. Still got plenty to talk about, including how I learned to stop worrying and love the bomb. I mean love the behavior pattern that I’ve previously mentioned.

This entry was posted in Project Icarus. Bookmark the permalink.

Leave a Reply