r/programming • u/Iamsodarncool • Aug 19 '26
Turns are Better than Radians
https://www.computerenhance.com/p/turns-are-better-than-radians
614
Upvotes
r/programming • u/Iamsodarncool • Aug 19 '26
135
u/DavidJCobb Aug 20 '26
This feels very closely related to Inigo Quilez's observation that trigonometry is often just an abstraction over vector algebra, and that one can get more efficient code by expanding trig calculations and canceling things out.
361
u/tehpola Aug 19 '26
Nice! I tend to agree we make this more complicated than it needs to be.
I’m working on decompiling a classic game and my mind was blown about their angular units. It’s a 16-bit system, but let’s consider the high byte only for simplicity. They divided their unit circle into 256 units! Then if you overflow, you keep going around the circle. You can even look up sprites based on the angle with some simple shifts. Very elegant!
206
u/Roachmeister Aug 19 '26
Interesting. Reminds me of the time I needed to sort a list of points by their distance from another point, and I realized that I could eliminate all of the sqrt calls by just sorting by distance squared.
43
u/ProgramTheWorld Aug 20 '26
We can even get rid of turns entirely. In computer graphics, it’s often easier to just stay with vectors all the way through. If you are using an angle, you’re probably doing something wrong.
https://iquilezles.org/articles/noacos/
87
u/mccoyn Aug 20 '26 •
Early algorithms for calculating trig functions relied on the small angle approximations. For sin it is ‘sin(x) ≈ x’. If you aren’t using radians, you have to multiply by an extra factor. So, it was easiest to convert to radians before calculating the value.
57
u/Educational-Lemon640 Aug 20 '26
There are good pragmatic reasons to use turns instead of radians for many cs applications, but not ones that use calculus. The fact that the derivative of sin is cos, and cos is -sin, nails your feet to the ground when it comes to many advanced physics and engineering problems.
18
u/EntroperZero Aug 20 '26
That's interesting, because it's how I do trig functions in NES/SNES programming. I called it "bytians" in the source code because there are 256 in a full turn, but it's the same thing as turns with fixed-point.
45
u/Dwedit Aug 20 '26
When you use Turns instead of radians, you lose a few properties:
18
u/echodecision Aug 19 '26
Pico-8 stays winning
14
u/edgmnt_net Aug 20 '26
I guess symbolic calculations might care about radians because multiplying by irrationals is "cheap" there, but for numerical computation turns win. Well-known angles are far more likely to be expressed nicely in turns, while arbitrary measurements just won't care about pi.
I also don't think the comment on the linked post about derivatives matters much. You're not really going to compute derivatives, you're going to substitute stuff into formulas that are derived symbolically using regular sine functions to begin with. That substitution is the same everywhere.
9
u/HugoNikanor Aug 19 '26 edited Aug 20 '26
I agree. I already treat my angles as if they had the unit "𝜏 radians", meaning that half a rotation would be ¹/₂ (𝜏 radians). Eliminating the multiplication by the unit for all trig calls would just be convenient.
edit: Correct spelling of "treat"
3
u/RedEyed__ Aug 20 '26
Good read!
3
u/Cautious-Act-4487 Aug 20 '26
In graphics and physics it's high time to switch to [0, 1). All these constantly popping up epsilons and -4.37e-08 in transformation matrices after cos(pi/2) in float32 are annoying as hell, especially when running tests for exact matrix equality
3
u/Exepony Aug 20 '26
Wouldn't the compiler take care of this extra multiplication and division cancelling out? At least in the common case where you're doing
sin(2*pi*x)and the constant is right there for the compiler to see. It's always seemed to me like exactly the use case constant folding/propagation were thought up for, but I've never done enough trigonometry in my programs to care to check.3
u/_darth_plagueis Aug 20 '26
The original sin code the article presents uses
y=(4/pi)xandx=|x|throughout the sin(x) code. Using y does not eliminate the need to use pi.3
u/PandaWonder01 Aug 21 '26
This is ignoring that the reason we use radians is that many things are much simple in radians- ie the derivite of sin is only cos when using radians.
If you need to write any physics, for the love of god please use radians. Actually, use quaternions or mat3/4s like an adult
2
u/mrfrostee Aug 20 '26
I like it.
There are similar ideas in the Tau Manifesto: https://www.tauday.com
2
u/RobertTheTraveler Aug 20 '26
and every time you need to do trigonometry you would have to convert.
2
u/markt- Aug 20 '26 edited Aug 20 '26
I think π is the more natural fundamental constant for describing a circle because it directly relates the two most basic physical measurements of the circle itself: its diameter and its circumference.
If you have an actual circle in front of you and want to describe its size, the diameter is usually the most direct measurement to take. It gives the full width of the circle from one side to the other. The circumference is the other obvious whole-circle measurement: the length around its boundary.
The radius is extremely useful mathematically, but as a physical measurement it is simply half the diameter. You normally obtain it from the diameter rather than needing to treat it as a separate fundamental dimension.
That makes
> C= π d
a very natural relationship: π tells you how many diameters fit into the circumference.
I understand the argument for τ, especially in contexts involving radians, rotations, and formulas where the radius is the natural variable. But that is a question of mathematical convenience. If we are asking which constant most directly relates the basic measurable dimensions of a circle as a geometric object, I think π has the stronger claim.
2
u/flanger001 Aug 20 '26
I see click, I Casey.
1
u/metahivemind Aug 20 '26 edited Aug 22 '26
[removed] — view removed comment
1
u/snerp Aug 20 '26
I use turns(half turns actually) for exactly one api in my game engine. I found turns to be more intuitive for joint ranges, rather than say “this joint can rotate 30 degrees up and 45 degrees down” vs “this joint can rotate pi over 6 up and pi over 4 down”, we can just divide out the redundant pi using half turns and say “this joint can rotate 1/6 of its upwards range and 1/4th of its downwards range”. Something with range -1,1 can rotate in a full circle and I find turns are nice for rounding and modulo, but only because this context cares about number of turns and ends up written to human readable files
1
u/pfn0 Aug 20 '26
1 turn = 2 radians. yes, it maths. turns are better because they're equal to twice the radians!
1
u/SaltineAmerican_1970 Aug 21 '26
If I used turns, and I wanted to turn 0.83333 turn every time based unit, I wouldn’t be able to get back to where I was because of that last digit of rounding and floating point math.
What if we took a single turn, and instead of using a fraction, did something crazy like make it an easy to remember number with lots of factors. I think it would be easier to rotate by 30/360 instead of 0.83333 because I would be able to make a full turn without rounding errors.
1
u/fishheaddz Aug 20 '26
I've always been partial to units of pi-radians, or semi circles -- which in this parlance would be half turns.
1
u/sr105 Aug 20 '26
Recently made this discovery as well syncing two signals and realizing, I only need to know how out of phase the signals are in +/- 1.0 cycle units.
-9
u/jhill515 Aug 20 '26
If pi is a "half turn", then tau is a "full turn". Or, if you want to go based on twisting your wrist, then that means pi is a "turn".
TL;DR - This is the dumbest CS flame-war topic I've seen in a generation!
-19
u/dnabre Aug 20 '26
The extra multiple/divide is a poor API issue, not a unit issue.
You want me to have to google 'is a turn 180 or 360 degree' for the rest of my life?
To me a 'turn' is 90° or 180° depending on context. A 'twist' might be 360°. If a 'turn' is 360° such that it is a debug i fix once in code that will stick, so I'll end up looking it up to check every time I need trig functions (it's not often enough for me remember these things).