HN
Today

Avoiding Trigonometry (2013)

This seminal 2013 article by Inigo Quilez argues that 3D graphics algorithms are often unnecessarily complex and error-prone due to over-reliance on trigonometry. He demonstrates how vector operations, like dot and cross products, can replace sin, cos, and acos calls for better performance, stability, and mathematical elegance. It's a foundational text for graphics programmers seeking deeper optimization and a more intuitive, vector-centric approach to common problems.

11
Score
1
Comments
#2
Highest Rank
9h
on Front Page
First Seen
Mar 12, 10:00 AM
Last Seen
Mar 12, 6:00 PM
Rank Over Time
725587111423

The Lowdown

Inigo Quilez, a renowned figure in computer graphics, challenges the common practice of embedding trigonometric functions (like sin, cos, acos, atan) deep within 3D graphics algorithms. He posits that such usage often indicates an inexperienced approach, leading to code that is unnecessarily complex, error-prone, and lacks elegance. Instead, Quilez advocates for a purely vector-based approach, leveraging the inherent geometric information encoded in dot and cross products to achieve superior results.

  • The Suboptimal Approach: Quilez illustrates the problem with a typical scenario: orienting an object by rotating its Z-axis to align with a target direction. A common, yet flawed, method involves calculating the rotation angle using acos(dot(z, d)) and the rotation axis via cross(z, d), then feeding these into a rotationAxisAngle function.
  • Critique of Trigonometry: This method introduces computationally expensive and numerically unstable operations like acos, cos, sin, clamp, and normalize. Quilez highlights the redundancy of computing acos(x) only to immediately apply cos to the result (which simplifies to x), exposing inefficient mathematical patterns.
  • The Vectorial Insight: The core idea is that dot products inherently represent cosines, and the length of cross products (for normalized vectors) represents sines. This means all necessary angular information can be extracted directly from vector operations without needing explicit trigonometric functions.
  • The Elegant Solution: By refactoring the rotation alignment, Quilez develops a new function that utilizes only dot and cross products. This eliminates the need for normalize(), acos(), clamp(), and even sqrt() operations through clever algebraic simplification, culminating in a compact and efficient matrix construction.

Ultimately, Quilez demonstrates that vector-related problems can and should be solved using only vectors. This approach not only yields significant benefits in terms of performance and numerical stability but also offers a more intuitive and mathematically pure way of understanding and implementing 3D graphics algorithms, challenging developers to rethink their reliance on abstract angular representations.