Getting a Designer's Degrees into Code That Wants Radians
Almost every angle that reaches a codebase arrives in degrees. A designer asks for a card that tilts 12°, a level file stores a spawn heading of 135°, a UI spec says the needle sweeps 270°. Almost every function that will consume it — Math.sin, atan2, a rotation matrix, a mesh's rotation.z, a GLSL rotate helper — is defined in radians. The gap between those two facts is where a surprising number of rendering bugs live.
Where the Mismatch Bites
Scene graph rotations
Trigonometry in gameplay logic
Shader uniforms
Config files and design tokens
Turning a Spec Value into a Radian Literal
Reach for this when you want the exact number to paste into a constant, a shader uniform or a unit-test expectation, rather than leaving another multiply-by-pi-over-180 scattered through the file.
Type the degree value from the spec
Put the number in the left field — 12, 45, 137.5, whatever the design or level file says. The radian value updates on every keystroke, and a comma works as the decimal mark just as a dot does.
Copy the bare number into the constant
The copy button on the radian field hands over the digits only — no unit, no thousands spacing — so it drops straight into a declaration without cleaning up. Selecting inside the field and pressing Ctrl + C does the same.
Reverse it to read a runtime value
When the number is coming out of the engine instead — a logged Euler angle, an atan2 result — press the swap button (↔) to run rad → ° and see what the object is actually doing. By hand that direction is a multiply by 180/π.
Reach for turns when the value is a whole spin
Both dropdowns are searchable and carry every angle unit in the app, so an animation described as 1.5 turns can be entered as turns and read out as radians without doing the 360 multiplication first.
Rotation Angles as Your Code Sees Them
The angles that actually recur in graphics work, with the exact π expression next to the float literal you would paste in. Anything that is a clean fraction of π is worth writing as a division of the language's pi constant rather than a decimal — it reads better in review and survives a change of language.
| Angle in the spec | Exact value | Radian literal | What it does to a sprite or mesh |
|---|---|---|---|
| 1° | π/180 | 0.017453293 | The nudge step for an arrow-key rotate control |
| 15° | π/12 | 0.261799388 | One hour mark on a clock face |
| 30° | π/6 | 0.523598776 | The row offset of an isometric hex grid |
| 45° | π/4 | 0.785398163 | A diagonal; sine and cosine are both 0.7071068 |
| 60° | π/3 | 1.047197551 | A common vertical field of view for a perspective camera |
| 90° | π/2 | 1.570796327 | A quarter turn — the most-typed constant in any 2D renderer |
| 180° | π | 3.141592654 | A flip; equivalent to negating both axes |
| 360° | 2π | 6.283185307 | One full loop of a spin animation |
What Makes This Quick During Development
A radian value while you are still typing
Conversion happens on each keystroke with no button to press, so trying 10, then 12, then 12.5 to see which tilt reads best takes seconds rather than a rebuild.
Paste-ready digits with no unit attached
Copy returns the number on its own, so it goes into source, JSON or a test expectation without a stray degree sign or space to strip out first.
Read a logged value back as degrees
Swap flips the direction, which is what you need when the console prints 2.0944 and you want to know whether the object landed where the artist expected.
Enough digits for double precision
Results carry up to eight decimals and fall back to exponential form below one millionth, so tiny per-frame increments stay legible instead of showing as a row of zeros.
Questions from Graphics and Game Code
Why does Math.sin(45) return 0.8509 instead of 0.7071?
Because the argument is read as 45 radians, not 45 degrees. Forty-five radians is a little over seven full turns — 2578.31° — and the sine of what remains after those turns happens to be 0.8509. Nothing warns you, since 45 is a perfectly legal radian value. Writing the argument as 45 × π/180 gives 0.7071067811865476 as expected. The same trap exists in Python's math.sin, C's sin() and every shading language.
Should a project store rotations in degrees or radians?
Store radians and show degrees. Radians are what every consumer of the value expects — trigonometric functions, quaternion constructors, matrix builders — so keeping them internally means no conversion sits between your data and the maths. Degrees are what humans reason about, so convert on the way into an inspector field, a tooltip or a saved authoring file. The failure mode to avoid is a codebase where the unit depends on which module last wrote the field.
Do all engines and libraries expect the same unit?
No, and it is worth checking per API rather than assuming. three.js Euler angles, Godot's rotation property and every shading language work in radians. Unity's inspector and Unreal's rotators are exposed in degrees, while their underlying sine and cosine helpers still take radians — so even inside a degree-facing engine, the moment you call trigonometry directly you are back in radians. CSS goes the other way and demands an explicit unit, which is why a bare number in a rotate transform is rejected rather than treated as radians.
How many digits of 0.017453292519943295 do I actually need?
A 64-bit double holds roughly 15 to 17 significant digits, so the full literal above is exactly what a JavaScript number or a C double can carry. A 32-bit float in a shader or a vertex buffer keeps only about seven, which means anything past 0.01745329 is discarded there anyway. Truncating to 0.0175 is the one to avoid: that is a 0.27 per cent error, and applied to a 90° rotation it lands you about a quarter of a degree off — enough to show as a seam where two tiles should meet.
What does atan2 give back, and how do I show it in the UI?
atan2(y, x) returns radians in the range −π to +π, measured counter-clockwise from the positive x-axis. To display a heading, multiply by 180/π and then normalise: adding 360 and taking the remainder against 360 turns −2.35619 rad, which is −135°, into 225° — what a compass-style readout should show. Keep the raw radian value for any further maths and convert only at the point of display, otherwise the rounding done for the label starts feeding back into the simulation.
No comments yet. Be the first to comment!