Live data from Hacker News

Avoiding Trigonometry (2013)

iquilezles.org

41–50 of 92 posts

Re: Avoiding Trigonometry (2013)

#42
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?…

My take as a graphics programmer is that angles are perfectly fine as inputs. Bring 'em! And we'll use the trig to turn those into matrices/quaternions/whatever to do the linear algebra. Not a problem.

I'm a trig-avoider too, but see it more as about not wiggling back and forth. You don't want to be computing angle -> linear algebra -> angle -> linear algebra... (I.e., once you've computed derived values from angles, you can usually stay in the derived values realm.)

Pro-tip I once learned from Eric Haines (https://erich.realtimerendering.com/) at a conference: angles should be represented in degrees until you have to convert them to radians to do the trig. That way, user-friendly angles like 90, 45, 30, 60, 180 are all exact and you can add and subtract and multiply them without floating-point drift. I.e., 90.0f is exactly representable in FP32, pi/2 is not. 1000 full revolutions of 360.0f degrees is exact, 1000 full revolutions of float(2*pi) is not.

Re: Avoiding Trigonometry (2013)

#43
I don't disagree with the "use linear algebra" assertion the author makes.

The most impressive math I've seen done during a real-time technical conversation was by someone leveraging comprehensive command of trig identities.

Re: Avoiding Trigonometry (2013)

#44
post #31
post #4

Earlier quoted context omitted.

He maybe considered contrarian but his math is sound.

With all due respect, no, it isn't. His drivel against set theory shows that he didn't even read the basic axiomatic set theory texts. In one of his papers, he is ranting against the axiom of infinity saying that 'there exists an infinite set' is not a precise mathematical statement. However, the axiom of infinity does not say any such thing! It precisely states the existence of some object than can be thought of as…

Almost every critique of the axiom of infinity is philosophical. I don't think you can just say "the axiom is sound, so what's your point". And you don't even get to claim that because of Godel's incompleteness theorem.

The axioms were not handed to us from above. They were a product of a thought process anchored to intuition about the real world. The outcomes of that process can be argued about. This includes the belief that the outcomes are wrong even if we can't point to any obvious paradox.

Re: Avoiding Trigonometry (2013)

#45
post #42

Earlier quoted context omitted.

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

My take as a graphics programmer is that angles are perfectly fine as inputs . Bring 'em! And we'll use the trig to turn those into matrices/quaternions/whatever to do the linear algebra. Not a problem. I'm a trig-avoider too, but see it more as about not wiggling back and forth. You don't want to be computing angle -> linear algebra -> angle -> linear algebra... (I.e., once you've computed derived values from angles…

Hah. I think we're and the author of both articles on the same page about this. (I had to review my implementations to be sure). I'm a fan of all angles are radians for consistency, and it's more intuitive to me. I.e. a full rot is τ. 1/2 rot is 1/2 τ etc. Pi is standard but makes me do extra mental math, and degrees has the risk of mixing up units, and doesn't have that neat rotation mapping.

Very good tip about the degrees mapping neatly to fp... I had not considered that in my reasoning.

Re: Avoiding Trigonometry (2013)

#46
post #34

Earlier quoted context omitted.

[flagged]

Quaternions break down for other situations. They cannot represent a rotation greater than 360 degrees. In an engine like Unity (which stores rotation as quats), you can use arbitrary Euler angles in the editor and it will work fine, but the scene file has to store 2 things. There is an additional m_LocalEulerAnglesHint property that covers this edge case.

You're right that quaternions don't work for those. Vec3 is the move IMO. Direction is axis; len is magnitude.

Re: Avoiding Trigonometry (2013)

#47

Earlier quoted context omitted.

[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).

Interesting. I do it in quaternion, but mostly work in unclamped 6DOF systems.

Re: Avoiding Trigonometry (2013)

#48
He's still computing cross(z, d) and dot(z, d) separately. that looks like a code smell to me. with quaternions this would be easier: just calculate the quotient between z and d and take the square root (which means adding 1 and renormalising). the square root is necessary if one is dealing with vectors, which live in a kind of square-y space. finding the rotation between two spinors is even simpler: it's just the quotient of the the spinors as quaternions. unfortunately hamilton's view that quaternions are the quotient of vectors has never been quite abandoned. it's much more natural to think of them as quotients of spinors.

Re: Avoiding Trigonometry (2013)

#49
post #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."

I vote for "eastify".

Re: Avoiding Trigonometry (2013)

#50

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

I had to check the precise definition for trigonometry while writing my comment, found it interesting so I added a reference.

As with many subject that we learn early in school, it's often interesting revisiting them as adult to perceive additional layer of depth by casting a new look.

With trigonometry we tend to associate it with circle. But fundamentally it's the study of tri-angles.

What is interesting is that the whole theory is "relative". I would reference the wikipedia page for angle but it may make me look like an LLM. The triangle doesn't have positions and orientation baked-in, what matters is the length of the sides and the angle between them.

The theory by definition becomes translation and rotation invariant. And from this symmetry emerge the concept of rotations.

What is also interesting about the concept of angle is that it is a scalar whereas the original objects like lines live in an higher dimension. To avoid losing information you therefore need multiple of these scalars to fully describe the scene.

But there is a degree of redundancy because the angles of a triangle sums to pi. And from this degree of freedom results multiple paths to do the computations. But with this liberty comes the risks of not making progress and going in circles. Also it's harder to see if two points coming from different paths are the same or not, and that's why you have "identities".

Often for doing the computation it's useful to break the symmetry, by picking a center, even though all points could be centers, (but you pick one and that has made all the difference).

Similar situation arise in Elliptic Curve Cryptography, where all points could have the same role, but you pick one as your generator. Also in physics the concept of gauge invariance.

Post reply on HN