← Back to context

Comment by nwallin

4 days ago

My experience is that it's really easy to subtly fuck something up if you're doing a bunch of trig in code. If there's something subtly wrong somewhere, everything seems to work for a while, then one day you hit gimbal lock. Then you have to add a special case. Then you hit gimbal lock somewhere else in the code. Or you have tan spit out +/- infinity or NaN. Another special case. Or you have acos or asin in their degenerate regions where the minor imprecision isn't minor anymore, it's catastrophic imprecision. Another special case. Trig heavy code will work 0% of the time if you have an obvious bug, or will work 99% of the time if you a subtle bug, and once you start chasing that long tail you're just adding 9s and will never get to 100%. And if you have code that will run thousands/millions of times per frame, you need a lot of 9s to make sure a user can get through minutes or hours of using your software without hitting bugs.

Doing the same work sticking strictly to vectors and matrices tends to either not work at all or be bulletproof.

The other thing is that trig tends to build complexity very quickly. It's fine if you're doing a single rotation and a single translation, but once you start composing nested transformations it all goes to shit.

Or maybe you're substantially better at trig than I am. I've only been doing trig for 30 years, so I still have a lot to learn before I stop making the same sophomore mistakes.