Live data from Hacker News

Avoiding Trigonometry (2013)

iquilezles.org

21–30 of 92 posts

Re: Avoiding Trigonometry (2013)

#21
post #8

Also see https://fgiesen.wordpress.com/2010/10/21/finish-your-derivat...

Ok, this is very interesting, as after pondering my code and the article's main pt, I independently came to the same conclusion that angles are what introduces trig. I agree that maybe people might be using angles as intermediates, but IMO there are cases where they're the most realistic abstraction. For example, how can I map a user's mouse movements, or button presses to a change in rotation without a scalar value? Without trig?

User moves cursor or stick a number of pixels/units. User holds key for a number of ms. This is a scalar: An integer or floating point. I pose this to the trig-avoiders: How do I introduce a scalar value into a system of vectors and matrices or quaternions?

Re: Avoiding Trigonometry (2013)

#22

OK I have a genuine question outside the topic of TFA. Do people really prefer "orientate" over "orient"? This pattern baffles me. You don't get out of the subway and "orientate" yourself, you "orient" yourself. I mean I'm perfectly aware that language is a descriptive cultural process etc etc but man this bugs the crap out of me for some reason

I think Americans tend to say "orient." I think English people tend to say "orientate."

Re: Avoiding Trigonometry (2013)

#23

I think this is more subjective than the author makes it out to be. I take a third approach: You can change out Matrices for Quaternions. Then do almost every operation using these two types, and a few operation between them. The operation implementations are a mix of dot products, quaternion multiplication, trig etc. I find this flow works well because it's like building arbitrarily complex transformation by composi…

Update with the big picture: I think the rotationAxisAngle example in the article is fine. The problem isn't that it exists and uses angles/trig: There are legit uses for that function! The problem is that it's not the best tool for aligning the spaceship. So: Problem is not that fn or angles/trig: It's using the wrong tool.

Re: Avoiding Trigonometry (2013)

#24
post #12

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…

[flagged]

I'd pretty much always store pitch/yaw for a first/third person controller. This makes it trivial to modify the values in response to input - `pitch += mouse_delta.y` and to clamp the pitch to a sane range (-90 to 90 deg) afterwards.

You can then calculate a quaternion from the pitch/yaw and do whatever additional transforms you wish (e.g. temporary rotation for recoil, or roll when peeking around a corner).

Re: Avoiding Trigonometry (2013)

#25
post #2

This has been some sort of a mix of peeve and a moment of enlightenment of mine when I understood this. I wholeheartedly agree with the point being made in the post. I had commented about this in the recent asin() post but deleted thinking it might not be of general interest. If you care about angles and rotations in the plane, it is often profitable to represent an angle not by a scalar such as a degree or a radian…

[deleted]

Re: Avoiding Trigonometry (2013)

#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 crusade in their production code.

Re: Avoiding Trigonometry (2013)

#27

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 optima…

citing the Wikipedia page for trigonometry makes this feel a lot like you just told an LLM the expected comment format and told it to write insightful comments

Re: Avoiding Trigonometry (2013)

#30
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…

Your response is well-grounded--trig is trouble. Angles are often fine, but many 3rd party library functions are not.

Have you ended up with a set of self-implemented tools that you reuse?

Post reply on HN