Post A3PfDRdv64GuZwtA5Q by codepuppy@mathstodon.xyz
(DIR) More posts by codepuppy@mathstodon.xyz
(DIR) Post #A3PczUQNl4OrF9m520 by codepuppy@mathstodon.xyz
2021-01-20T00:42:16Z
1 likes, 1 repeats
AHHHHHH I finally understand quaternions!! XDD :DDI 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!! :DAs 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!#Math #Geometry #Quaternions
(DIR) Post #A3PdNH9ik6UX2cK6LI by freemo@qoto.org
2021-01-20T00:47:56Z
1 likes, 0 repeats
@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.
(DIR) Post #A3Pe6jF9A1EpBUXE2K by codepuppy@mathstodon.xyz
2021-01-20T00:56:13Z
0 likes, 0 repeats
@freemo Ahh I see, like how the cross product is dimensionally-limited :3Well 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 XDI 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.
(DIR) Post #A3Pf0xvXkmTIwTBJ68 by freemo@qoto.org
2021-01-20T01:06:18Z
0 likes, 0 repeats
@codepuppy they are just complex numbers taken out to 4D instead of 2D, you can extend this to even higher dimensions with things like octonians and sedenions. Each level looses something though for example quaternions loose commutativity. but otherwise they arent that obscure when you think about it.
(DIR) Post #A3PfDRdv64GuZwtA5Q by codepuppy@mathstodon.xyz
2021-01-20T01:03:42Z
0 likes, 0 repeats
@freemo OH WAITAttention 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'DBut on this page! https://en.wikipedia.org/wiki/Euler%E2%80%93Rodrigues_formulafor quaternion = a + bi + cj + dka = 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!
(DIR) Post #A3PfDRpyNFufBKWmsC by freemo@qoto.org
2021-01-20T01:08:36Z
0 likes, 0 repeats
@codepuppy They are just complex numbers more or less, really nothing too complex... The magic that you seem to be missing though is still why they are useful, special and prefered for certain situations.
(DIR) Post #A3PfFRYYODeqtDKcwC by codepuppy@mathstodon.xyz
2021-01-20T01:07:38Z
0 likes, 0 repeats
@freemo that's still super useful :>for me, largely for the eternal quest of avoiding actually computing trig functions in code! XD :Dbut 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
(DIR) Post #A3PfFRwIxuem4sRaxU by freemo@qoto.org
2021-01-20T01:08:59Z
0 likes, 0 repeats
@codepuppy Your actually getting super close to realizing why their so powerful by realizing they arent using unit vectors... do yo uwant the answer?
(DIR) Post #A3PfQaYnFnQi03l4kK by codepuppy@mathstodon.xyz
2021-01-20T01:10:52Z
0 likes, 0 repeats
@freemo well they did seem obscure to me in that 2D complex numbers come from negative square roots and logarithms,whereas quaternions just seemed arbitrary and "made up"—like that the multiplication table could have been different and would have been a different extension of complex numbers to 4D!is that not true? is there something about it that makes it a unique extension of complex numbers in 4D? :>
(DIR) Post #A3PfR6DHZJEkAbwLey by codepuppy@mathstodon.xyz
2021-01-20T01:11:05Z
0 likes, 0 repeats
@freemo Yeah sure, let me have it! :D
(DIR) Post #A3PfgFJnzvOMklDJh2 by freemo@qoto.org
2021-01-20T01:13:47Z
0 likes, 0 repeats
@codepuppy Two reasons..1) they are computationally more efficient for 4D rotations than their equivalent matrix/vector representation2) this one is actually more important since #1 can be corrected for with parallelization... They are not susceptible to gimbal lock when calculating rotations.
(DIR) Post #A3Pg7oHm6AE31MPKIS by codepuppy@mathstodon.xyz
2021-01-20T01:18:47Z
0 likes, 0 repeats
@freemo 1) I get it :D2) 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.)
(DIR) Post #A3Pgh6XiD92rmOgwuO by freemo@qoto.org
2021-01-20T01:25:09Z
0 likes, 0 repeats
@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.
(DIR) Post #A3PhBg0ytJQwTvxa7c by codepuppy@mathstodon.xyz
2021-01-20T01:30:43Z
0 likes, 0 repeats
@freemo Ohhhhhh I see :DYou 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! :DRight?
(DIR) Post #A3PhhK9Jipt5vwwwVc by freemo@qoto.org
2021-01-20T01:36:22Z
0 likes, 0 repeats
@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.
(DIR) Post #A3PiaoRgmaZTp60Bjk by codepuppy@mathstodon.xyz
2021-01-20T01:46:29Z
0 likes, 0 repeats
@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 :3I wonder if there's a simpler way than computing a matrix from a quaternion though? :>
(DIR) Post #A3PioLulenLnOF3l2m by freemo@qoto.org
2021-01-20T01:48:51Z
0 likes, 0 repeats
@codepuppy yes thats pretty much the jist of it. though it doesnt have to be matrix math itslef. we are really talking any arbitrary computer instruction executed across a large set of data simultaneous. No reason matrix math needs to be part of that discussion other than the fact that vectors are analogous with matrix math.
(DIR) Post #A3PiyZdfUANsqnw3Pc by codepuppy@mathstodon.xyz
2021-01-20T01:47:24Z
0 likes, 0 repeats
@freemo also I've never used Euler angles in practice, so I didn't know gimbal lock was a thing until just now—I thought you meant a kind of concurrency locking thing XD'
(DIR) Post #A3PiyZoIqctJNmuXzM by freemo@qoto.org
2021-01-20T01:50:43Z
0 likes, 0 repeats
@codepuppy oh no, nothing to do with concurrency. its about the axis getting aligned through rotation and thus loosing a degree of freedom and thus can not achieve certain combinations of rotations with vectors unless you add in an extra computation to check for an correct for gimbal lock.
(DIR) Post #A3Pj5fL6gmyeYedRZI by codepuppy@mathstodon.xyz
2021-01-20T01:51:08Z
0 likes, 0 repeats
@freemo since if there's a simpler formula to go straight from a quaternion and vector to the transformed vector than the number of operations involved in matrix multiplication, then even the GPU/parallelized code would benefit! :DI mean you could just write it out, but if that's the same number of additions/multiplications as matrix multiplication would be, there's no point X3
(DIR) Post #A3Pj5flh5wFDt74g0e by freemo@qoto.org
2021-01-20T01:51:58Z
0 likes, 0 repeats
@codepuppy the matrix form is the same physical calculations as trigonometry basically.
(DIR) Post #A3Pj8Nar7nOiO9IORM by codepuppy@mathstodon.xyz
2021-01-20T01:52:03Z
0 likes, 0 repeats
@freemo ohhhhhh I see! the normal way of using Euler angles involves an if/then branch?well then yes that's not good for SIMD/etc. XD
(DIR) Post #A3PjSFCK37o28pICFE by codepuppy@mathstodon.xyz
2021-01-20T01:56:07Z
0 likes, 0 repeats
@freemo and yes definitely! there's no matrix multiply primitive in machine cores (at least not yet XD )just things like FMA—floating-point-multiply-and-add, which is useful for matrix multiplication but can be used for other things :>(I once made a parallel thing in C that used it and numerically computed ordinary differential equations without actual "matrices")but it's very nice and convenient codewise to reuse mmul()/etc., esp. if there's no computational benefit from another formula :3