lol… I always giggle when I watch people try to chase down what a quaternion is… and there’s a reason.
Quaternions are high math, they’re complicated shit, you don’t learn about these until you’re years into your math studies. And there’s a reason, there’s a lot of foundation work that you MUST know to understand them… and even then they’re a trip to deal with.
You’ll see people with CS degrees and engineers pop around (edit: of course as I way typing this a couple popped in and did this very thing) and talk about how they’re really just necessary parts of math and attempt to explain them expecting the listener to have also taken the advanced math classes. We who have taken math seldom remember when we were young kids and sums and products were daunting things.
But math is most certainly one of those you can’t take a step until you’ve mastered the previous. You’ll never understand complex numbers, and 4 dimensional products until you’ve learned everything under it.
So I’ll go threw what foundations you need, what parts of said foundations, and why you need them.
- Algebra - you need to understand the abstract representational concepts taught here. The idea of what a variable is, the logic, the… it’s the foundation of all foundations… it’s also where you’ll first be introduced to numeric structures like Matrices and Vectors (a special kind of matrix). If you haven’t aced algebra… sorry, there is NOTHING I can do for you.
You may wonder why I said algebra and started so low… shit I could have started at arithmetic. But I start here because I know a lot of people entering the game-design field often only have a basic high school Algebra education, and even then only passed with a C.
- Trig Geometry - I usually like to lump trig and geometry together… geometry is the proofs and theories of angles and shapes, trig is the math, trig is the actual numbers of everything geometry. If you don’t understand your trig functions… you’ll be sccrewed. If I say “tangent curve” and you can’t see the tangent curves in your head… or if I say “sine of pi over 2” and you don’t immediately spit back “1”… well I can’t help you, you’re screwed. Go learn your math! Don’t forget your arc-trig functions, and your hyper-trig functions, and all your relationships. If you don’t know sin^2 + cos^2 = 1… well what the heck? Pythagoros!
You need the understanding of angular relationships to get why quaternions work… they have to do with rotations in imaginary space! Angles are like important!
-
Calculus - you actually probably don’t NEED anything from calculus. It’s not like quaternions have a lot to do with integration or anything. But Calc is still a basic tier stuff, and you’ll need it to do any of the higher stuff.
-
Complex/Imaginary Numbers - now we’re getting into the meat of it. The imaginary number is the square-root of -1, or ‘i’. Complex numbers are any numeric expansion of i, using i as the identity value.
a * i = imaginary a
thusly expanded all imaginary numbers can be described as:
c = ia + b
where a and b are any real numbers. Think about this from Algebra, when you learned the slope-intercept form of a line…
f(x) = mx + b
notice how they look similar? You essentially have a curve (lines are curves) with an imaginary slope… this means it gradients into non-space.
- Linear Algebra - now here’s where we get to start putting this stuff together. In linear algebra you learn about spacial transformations. This is where all that matrix arithmetic you learned in algebra pops up its head. And you learn how a matrix can be used to tranform multi-dimensional information.
You have a non-functional curve? Rotate it around the origin with a rotation matrix until its functional (line test), perform you math, then rotate back.
You have a 4 dimensional object that needs to be projected into 3-space for a real-world approximation? Use a projection matrix.
You have a 3 dimensional image that needs to be projected onto a 2-D monitor (like a video game)? Use a projection matrix.
This is linear algebra!
Matrices aren’t defined as representing any given thing. They’re just a numeric structure. You get to pick what it describes and shape it to your needs. Compare a colormatrix to a camera-projectionmatrix to a transform-matrix in video-games, all matrices, all do the same math, non alike in what they are designed to accomplish.
Now remember how I said vectors are a special kind of matrix. It’s just a matrix of a specific shape, used for specific things. And we use them in unity for things like translation (which is a transformation).
Well Quaternions are a special kind of vector, which means they’re also a special kind of matrix! The math is all the same. Cross products and scalar products (dot products) are all inherited from matrix math that you learned back in algebra.
Quaternions just have a more specific use, and rotating objects in 3-space isn’t the only use… it’s just the use WE use them for… just like vectors aren’t only for translation.
The design of a quat is that of complex numbers. It’s a transformation described in imaginary space. How this transformation appears in unity is as a rotation (a quat can actually do more, like scale and invert, but we always normalize our quaternions to avoid this as it’s look weird on screen).
Now… if you don’t know all that stuff up to there… well, you aren’t going to wrap your head around quaternions. As they’re still a bit of a ways off from here.
[EDIT]
At CrazySi - actually they are rather infamous amongst novices in the game-design world who never took Computer Science like you implied you did. If you had never seen a quat, and came into game design, saw that bad boy sitting there… what do you think your reaction would be?