Discussion
storus: In principle, wouldn't a change of basis be all that is needed?
srean: It's a little more than change of basis, although change of basis is an important part of it. It converts many apparently trigonometric operations into algebraic ones.
GistNoesis: I think it boils down to the alternate view of rotations as two successive reflections.You can then use householder matrix to avoid trigonometry.These geometric math tricks are sometimes useful for efficient computations.For example you can improve Vector-Quantization Variational AutoEncoder (VQ-VAE) using a rotation trick, and compute it efficiently without trigonometry using Householder matrix to find the optimal rotation which map one vector to the other. See section 4.2 of [1]The question why would someone avoid trigonometry instead of looking toward it is another one. Trigonometry [2] is related to the study of the triangles and connect it naturally to the notion of rotation.Rotations [3] are a very rich concept related to exponentiation (Multiplication is repeated addition, Exponentiation is repeated multiplication).As doing things repeatedly tend to diverge, rotations are self stabilizing, which makes them good candidates as building blocks for the universe [4].Because those operations are non commutative, tremendous complexity emerge just from the order in which the simple operations are repeated, yet it's stable by construction [5][6][0]https://en.wikipedia.org/wiki/Householder_transformation[1]https://arxiv.org/abs/2410.06424[2]https://en.wikipedia.org/wiki/Trigonometry[3]https://en.wikipedia.org/wiki/Matrix_exponential[4]https://en.wikipedia.org/wiki/Exponential_map_(Lie_theory)[5]https://en.wikipedia.org/wiki/Geometric_algebra[6]https://en.wikipedia.org/wiki/Clifford_algebra
djmips: Also see https://fgiesen.wordpress.com/2010/10/21/finish-your-derivat...
dxuh: I agree that use of trigonometry is almost always a smell, but e.g. in games there are so many cases where angles are just more useful and intuitive. I just grep-ed for "angle" in a game of mine and I find it for orienting billboard particles (esp. for particles a single angle is much better than a quat for example). Also for an FPS camera controller. It's much simpler to just store a pitch and a yaw and change that with mouse movement, than storing a quat. You can't really look at a quat and know what kind of rotation it represents without opening a calculator. And I also use it for angle "fudging" so if you want to interact with something if you are roughly looking at it, you need to configure an angle range that should be allowed. It just makes sense to configure this as an angle, because we have some intuition for angles. So I guess for computations angles are probably usually wrong, but they are great for intuition (they are low-dimensional and linear in amount of rotation). That makes them a better human interface for rotations. And as soon as you computations start with angles, of course they find their way into the rest of the code.
20k: >poorly designed third party APIsI think this is missing the reason why these APIs are designed like this: because they're convenient and intuitiveIts rare that this kind of performance matters, or that the minor imprecisions of this kind of code matter at all. While its certainly true that we can write a better composite function, it also means that.. we have to write a completely new function for itBreaking things up into simple, easy to understand, reusable representations is good. The complex part about this kinds of maths is not the code, its breaking up what you're trying to do into a set of abstracted concepts so that it doesn't turn into a maintenance nightmareWhere this really shows up more obviously is in more real-world library: axis angle rotations are probably a strong type with a lot of useful functions attached to it, to make your life easier. For maths there is always an abstraction penalty, but its usually worth the time saved, because 99.9999% of the time it simply doesn't matterAdd on top of this that this code would be optimised away with -ffast-math, and its not really relevant most of the time. I think everyone goes through this period when they think "lots of this trig is redundant, oh no!", but the software engineering takes priority generally