Skip to content
Tech News
← Back to articles

Turns are Better than Radians (2022)

read original more articles
Why This Matters

This article highlights a subtle yet impactful optimization in computational geometry and graphics: removing the need for pi or tau constants by restructuring code to work directly with normalized values. This approach simplifies calculations, reduces computational overhead, and can improve performance in a wide range of applications, from game engines to scientific computing.

Key Takeaways

Some time ago, much effort was expended to convince people to replace approximations of “pi” (3.14159…) with approximations of “tau” (6. 28318…). The idea, according to numerous blog posts and YouTube videos, was that common formulas become simpler, and it’s easier to work with a constant describing an entire circle instead of half a circle.

Generally, I agree. While it’s a minor point, it’s worth making. Most code does get slightly better if you replace pi with tau.

However, in all the fanfare, a far more impactful opportunity was overlooked. Instead of replacing pi with tau, most of the time pi can be removed entirely.

Here’s how that works.

First, consider the common case for pi and tau in code: converting things to and from radians for calls to trigonometric functions. If you’ve ever used these constants, the vast majority of what you wrote probably did something like this:

y = center.y + (center.y * Math::sin(h * Math_TAU) * s) - (cursor->get_height() / 2);

That’s not me constructing an example, that’s me randomly opening the source code for the Godot Engine on github and searching for “tau”. The piece of code above, and dozens of similar uses, is what comes up.

There is nothing special here about Godot. If you opened any random game engine codebase, you could do the exact same search and see the exact same kind of usage.

Notice what is going on here: the programmer has a value h which is already periodic on the range 0 to 1, but they multiply by tau because they need to call sin.

This may seem very sensible if that’s as far as you look. But what about the implementation of sin?

... continue reading