Live data from Hacker News

Avoiding Trigonometry (2013)

iquilezles.org

61–70 of 92 posts

Re: Avoiding Trigonometry (2013)

#61
post #14

>poorly designed third party APIs I think this is missing the reason why these APIs are designed like this: because they're convenient and intuitive Its 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 it Breaking thin…

> I think this is missing the reason why these APIs are designed like this: because they're convenient and intuitive Agreed. In my view, the method the author figured out is far from intuitive for the general population, including me.

I guess the point is: How often do we really need actual angles in the code? Probably only at the very ends: input from users and output to users. Everywhere else, we should just be treating them as sin/cos pairs or dot/cross pairs. So when the user inputs an angle, immediately convert it to what the computer actually needs, store it that way throughout the computation, and then only if/when the user needs to see an actual angle would you need to convert it back.

Re: Avoiding Trigonometry (2013)

#62

Norman Wildberger takes this to the extreme with Rational Trigonometry https://en.wikipedia.org/wiki/Divine_Proportions:_Rational_T... It eschews angles entirely, sticking to ratios. It avoids square roots by sticking to "quadrances" (squared distance; i.e. pythagoras/euclidean-distance without taking square roots). I highly recommend Wildberger's extensive Youtube channels too https://www.youtube.com/@njwildberger a…

he sounds awesome. even though i’m sure i would view him as a total kook, he’s the kind of kook that life is brighter for everyone with his existence.

Re: Avoiding Trigonometry (2013)

#63
post #26
post #14

>poorly designed third party APIs I think this is missing the reason why these APIs are designed like this: because they're convenient and intuitive Its 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 it Breaking thin…

Based on my experience writing many games that work great barring the occasional random physics engine explosion, I suspect that trigonometry is responsible for a significant proportion of glitches. I think over the years I subconsciously learned to avoid trig because of the issues mentioned, but I do still fall back to angles, especially for things like camera rotation. I am curious how far the OP goes with this cru…

Yes, for physics engines I think that's a very good use case when its worth the extra complexity for robustness. Generally I think if errors (or especially nan's) can meaningfully compound, ie if you have persistent state, that's when its a good idea to do a deeper investigation

Re: Avoiding Trigonometry (2013)

#64
post #14

>poorly designed third party APIs I think this is missing the reason why these APIs are designed like this: because they're convenient and intuitive Its 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 it Breaking thin…

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.

Re: Avoiding Trigonometry (2013)

#65
post #10
post #7

This is just https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula

This is avoiding an common but unnecesary round trip. When your inputs are vectors, angles are an unnecessary intermediate representation. You can substitute the geometric meaning of dot and cross product directly into the Rodrigues matrix and get by with less operations overall. It's more elegant, uses less instructions.

That’s exactly what I mean, there are no inverse trig that needs to be involved anywhere, see the matrix section in the article. It is trivial to recognize that vector inputs are pretty much the same space the k coefficients and mentally treat cos and sin as a shorthand symbol in terms of vector products.

And in any case inverse trig functions are just components of logarithms of quaternions, and trig is components of exponentiating half-axis-angle into quaternions.

Re: Avoiding Trigonometry (2013)

#66

Norman Wildberger takes this to the extreme with Rational Trigonometry https://en.wikipedia.org/wiki/Divine_Proportions:_Rational_T... It eschews angles entirely, sticking to ratios. It avoids square roots by sticking to "quadrances" (squared distance; i.e. pythagoras/euclidean-distance without taking square roots). I highly recommend Wildberger's extensive Youtube channels too https://www.youtube.com/@njwildberger a…

I also invented this! There is cool stuff like angle adding and angle doubling formulas, but the main downside is that you can only directly encode 180 degrees of rotation. I use it for FOV in my games internally! (With degrees as user input of course.) In order to actually use it to replace angles, I assume you'd want to use some sort of half angle system like quaternions. Even then you still have singularities, so it does have its warts.

Re: Avoiding Trigonometry (2013)

#68
The other thing it can give you is computationally exact results since rationals are closed over division. Sine is interesting because where the input is rational the output is almost always irrational and where the output is rational the input is almost always irrational. In computation the first time you use sine in a program you have injected approximation. If you want to build things like reproducible code and geometric caching it can be interesting to compare using a purely rational computation system to an approximative system.

Re: Avoiding Trigonometry (2013)

#69

Norman Wildberger takes this to the extreme with Rational Trigonometry https://en.wikipedia.org/wiki/Divine_Proportions:_Rational_T... It eschews angles entirely, sticking to ratios. It avoids square roots by sticking to "quadrances" (squared distance; i.e. pythagoras/euclidean-distance without taking square roots). I highly recommend Wildberger's extensive Youtube channels too https://www.youtube.com/@njwildberger a…

Stuff like this is what really interests me in trying to imagine how differently aliens might use things that we consider to be immutable fundamentals.

I had this feeling of alien math when I went thru his videos on ancient Babylonian math. They were very serious about the everything divided by sixty stuff. Good times.

Re: Avoiding Trigonometry (2013)

#70
post #55

Earlier quoted context omitted.

Stuff like this is what really interests me in trying to imagine how differently aliens might use things that we consider to be immutable fundamentals.

personal theory: I think there's going to turn out to be a parallel development of math that is basically strictly finitist and never contends with the concept of an infinite set, much less the axiom of choice or any of its ilk. Which would require the foundation being something other than set theory. You basically do away with referring to the real numbers or the set of all natural numbers or anything like that, and…

How would you do limits or analysis?
Post reply on HN