AHHHHHH I finally understand quaternions!! XDD :DD
I always thought they were neat fun thing in abstract algebra and a neat but arbitrary way of representing rotations with unnecessarily extra numbers.
If someone had just said to me this sentence I would have seen how insanely perfect they are!! :D
As rotations, the i/j/k coefficients are the x/y/z components of the axis-of-rotation vector, and the fourth lone number is the amount of the rotation in radians!
@codepuppy Way to go, its great to learn a new thing...
Here is the catch to really understanding Quaternions and how to use them though... do you understand what a quaternion can accomplish and why one might use it over the simpler to understand and more generally useful vector math? Afterall if you use vectors you can work in any number of dimensions whereas quaternions are limited 3D rotations or 4D points. So understanding why quaternions are superior for specific situations is really the key to getting them and using them.
@freemo Ahh I see, like how the cross product is dimensionally-limited :3
Well I'm mostly focused on writing 3D computational geometry code right now, and mostly I'm just excited that I already basically understand this thing everyone's talking about XD
I thought quaternions had some insanely arbitrary arcane set of formulas for transforming the x/y/z of a 3D vector into the rotated vector and I should learn them someday when I had time to spare (haha) but they weren't essential.
@freemo OH WAIT
Attention everyone who saw this post! This is totally wrong!! XD'''
Quaternions *are* strange formulas for transforming coordinates!!
And here they are!
It still annoys me that they don't appear *anywhere on the actual wikipedia page for quaternions*!! X'D
But on this page! https://en.wikipedia.org/wiki/Euler%E2%80%93Rodrigues_formula
for quaternion = a + bi + cj + dk
a = cos(θ/2)
b = x sin(θ/2)
c = y sin(θ/2)
d = z sin(θ/2)
where x/y/z are the axis of rotation and θ is the amount in radians!
@freemo that's still super useful :>
for me, largely for the eternal quest of avoiding actually computing trig functions in code! XD :D
but it's wrong to say that the quaternion coefficients match up bijectively, since the vector ones are indeed the axis of rotation, but are still dependent of θ, so you can't separate so neatly them!
the quaternion vector is the axis of rotation *scaled* by a function of θ, not as a unit vector! ;D
@codepuppy Your actually getting super close to realizing why their so powerful by realizing they arent using unit vectors... do yo uwant the answer?
@freemo Yeah sure, let me have it! :D
@codepuppy Two reasons..
1) they are computationally more efficient for 4D rotations than their equivalent matrix/vector representation
2) this one is actually more important since #1 can be corrected for with parallelization... They are not susceptible to gimbal lock when calculating rotations.
1) I get it :D
2) You'll have to run that by me again. Surely parallelizing the three or so formulas of a single vector's rotation isn't really a thing that's fruitfully done so I must be missing something! (I'd figure one would parallelize the same rotation for many points on say a big polyhedron, regardless of whether quaternions or etc. are used for it. Like one CPU core would take a quarter of the vertices to be rotated and another core another fourth, etc.)
@codepuppy there are only a few equations to rotate a single point yes, but you are rarely rotating a single point are you? Typically a rotation is of some shape in 3D space, that is represented of tens or hundreds of thousands of points that makeup the surface of that shape all of which are rotated by the same set of formula.
@freemo Ohhhhhh I see :D
You mean compared to running the trig function for every point!
Factorizing the rotation into values that can be kept the same for all points means the parallelized part need only apply a simple addition/multiplication formula for each point and the threads can share those factorized numbers across them :>
And if you store and pass around *just* those numbers across functions instead of the axis x/y/z and θ, you'd basically end up recreating quaternions! :D
Right?
@codepuppy mostly yes.. keep in mind on a GPU when it parallelizes a problem it isnt like a CPU, it has what is called a SIMD architecture, this stands for "Single Instruction, Multiple data". It basically means for it to be efficient at using all its cores (which tends to be hundreds) at solving a problem the instruction set must be singular (and before you think of cheating, no it cant have a bunch of if-then branches either) but the data it operates on can be many and varied.
Rotations fit this description, you have a ton of points but the instructions on how to rotate them are all the same. so you can trivially parallelize it.
What I am saying though is not that the quaternions are better for this what i am saying is the computational effiency of quaternions over vector math is **negated** by this... using vector match to rotate 100,000 points would be much slower than quaternions if we were using a single CPU to sequentially do each one, so quaternions would be the clear choice. However when we are able to do the rotations on a GPU and parallelize it across hundreds or even thousands of SIMD cores then the vector math while computationally inefficient on a rotation-by-rotation basis is so easily parallelized that the computational advantage of a quaternion isnt really needed anymore.
The gimbal lock advantage of quaternions however is valid regardless of any of this.
@freemo ohhhhkay I think I get it :>
so you're saying if you start with axis-angle representation or euler angle representation and calculate a matrix for rotation, then parallelize the application of that matrix to all the points like normal, that's hardly more efficient than computing the matrix from a quaternion and applying the same matrix to all the points? that makes tons of sense yes :3
I wonder if there's a simpler way than computing a matrix from a quaternion though? :>
@codepuppy the matrix form is the same physical calculations as trigonometry basically.