Skip to content

Audit and replace internal trigonometry with vector operations #5

@JnyJny

Description

@JnyJny

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions