What happened
Developers often encounter trigonometric functions like sin and cos in game development—for things like calculating the angle of a projectile, or animating rotating objects. The article highlights an instance where code was written using radians as the input to the sin function, when the code could have used a domain representing angles from 0 to one, with that domain’s values being referred to as 'turns'.
Specifically, the example shows Godot Engine using the tau constant for trigonometric calculations. This results in multiplication by pi or tau, which are then immediately divided back out again – creating an inefficient conversion from radians to degrees and back. The article demonstrates this using a common AVX2 implementation of sin, showing that sin(h 2 pi) is actually equivalent to (4 / pi) * x.
Why it matters
The issue isn’t just about writing slightly cleaner code. The inefficiency comes from the fundamental representation of angles. Radians are continuous values measured in circular turns, extending infinitely from zero to two pi.
However, practically, most angle calculations relate to specific, discrete orientations like 90 degrees or 45 degrees. Representing these as radians introduces a level of approximation and loss of precision that can accumulate over repeated computations—especially in performance-critical game code. The article emphasizes the cost associated with this continuous representation.
But, but, but…
The argument for using radians stems from their natural fit within calculus and other mathematical contexts where angles are routinely expressed as multiples of pi.
However, the author correctly points out that this requirement doesn't dictate a necessary choice for game development or any practical application that relies heavily on discrete angular measurements. The author acknowledges the familiarity (and perhaps ingrained fear) associated with using radians, but argues there’s no fundamental mathematical reason to insist upon them.
“it’s literally a conversion to radians and back for no reason.”
— Dr Non
The counter-take
The prevalent use of radians stems from a historical legacy in calculus and physics, despite its inefficiency for many discrete applications like game development. This reliance on radians represents a deeply embedded convention that’s often questioned only later in the software development lifecycle.
The AI angle
With greater computational precision and efficiency achieved through the turn-based approach, AI systems handling robotics or simulations can optimize movement algorithms and reduce energy consumption—essentially, upgrading control systems with an asymmetry of performance.
