Inigo Quilez makes a compelling case for eliminating trigonometry from the internals of geometry code: https://iquilezles.org/articles/noacos/
Summary
The dot product encodes cosine, the cross product encodes sine. When geometry code converts vectors to angles (via acos, atan2) and then back to vectors (via sin, cos) to build rotation matrices or compute orientations, it's doing an unnecessary and lossy round-trip.
Problems with the trig approach:
- Precision loss at edge cases (
acos near 0 and pi)
- Unnecessary computation -- two transcendental function calls where none are needed
- Conceptual indirection -- angles are abstractions; vectors are the actual geometric objects
The fix: work directly with dot and cross products. Build rotation matrices from vector relationships, not angle measurements.
Relevance to twod
Audit twod for any internal use of acos, atan2, sin, cos in rotation/orientation logic. If angles appear in the internals (not the public API where users might naturally think in degrees/radians), they can likely be replaced with direct vector operations.
The public API can still accept angles as input -- the point is that the implementation shouldn't need them.
Authored by Jny
Inigo Quilez makes a compelling case for eliminating trigonometry from the internals of geometry code: https://iquilezles.org/articles/noacos/
Summary
The dot product encodes cosine, the cross product encodes sine. When geometry code converts vectors to angles (via
acos,atan2) and then back to vectors (viasin,cos) to build rotation matrices or compute orientations, it's doing an unnecessary and lossy round-trip.Problems with the trig approach:
acosnear 0 and pi)The fix: work directly with dot and cross products. Build rotation matrices from vector relationships, not angle measurements.
Relevance to twod
Audit twod for any internal use of
acos,atan2,sin,cosin rotation/orientation logic. If angles appear in the internals (not the public API where users might naturally think in degrees/radians), they can likely be replaced with direct vector operations.The public API can still accept angles as input -- the point is that the implementation shouldn't need them.
Authored by Jny