Language
English English Vietnamese (Tiếng Việt) Vietnamese (Tiếng Việt) Chinese (简体中文) Chinese (简体中文) Portuguese (Brazil) (Português do Brasil) Portuguese (Brazil) (Português do Brasil) Spanish (Español) Spanish (Español) Indonesian (Bahasa Indonesia) Indonesian (Bahasa Indonesia)
Degrees to Radians

Degrees to Radians

Turn a degree value from a design spec or level file into the radian literal that Math.sin, shader code and scene-graph rotations expect.

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.

Conversion factor: 1° = π/180 rad = 0.017453292519943295 rad. So a 12° tilt is 12 × π/180 = 0.20943951 rad, and the classic quarter turn of 90° is exactly π/2 = 1.5707963267948966 rad — the number worth baking into a constant rather than typing from memory.

Where the Mismatch Bites

Scene graph rotations

A three.js object keeps its Euler angles in radians, and Godot stores node rotation the same way even though its inspector shows degrees. Assigning a raw 45 spins the object roughly seven full turns instead of an eighth of one.

Trigonometry in gameplay logic

Line-of-sight cones, projectile spread and orbit maths all call sine and cosine on a heading. Feed them a degree value and nothing throws — you simply get a plausible-looking wrong number that is painful to trace back.

Shader uniforms

GLSL, HLSL and WGSL trigonometry is radian-only, so an angle pushed into a uniform has to be converted on the CPU side before upload. Doing the divide per fragment instead is wasted work in the hot path.

Config files and design tokens

CSS transforms, SVG attributes and most authoring tools speak degrees, so any pipeline that reads those assets into a WebGL or canvas renderer needs exactly one conversion step at the boundary.

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.

1

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.

2

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.

3

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/π.

4

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.

Convert once, at the boundary. Holding the same rotation as degrees in one struct and radians in another is how a project ends up with a helper nobody trusts. Pick radians as the internal representation, convert on input from authoring tools and on output to a human-facing label.

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
π/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° 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.

°
rad

Rotation Angles in Code

1 °=0.01745329 rad
15 °=0.26179939 rad
30 °=0.52359878 rad
45 °=0.78539816 rad
90 °=1.57079633 rad
360 °=6.28318531 rad

Degree (°)

The unit authoring tools speak: CSS transforms, SVG attributes, level editors and design specs all hand angles over in degrees, 360 to a full turn.

Radian (rad)

What the maths library actually reads. Sine, cosine and atan2 are defined on radians, and a full turn is 2π ≈ 6.283185307 of them.

Type the degree value from the design spec and read the radian literal as you type
The copy button returns the bare number, ready to paste into a constant or test
Press swap (↔) to read a logged Euler angle or atan2 result back in degrees
Nothing leaves the browser — the maths runs locally on your device
Want to learn more? Read documentation →
1/5
Start typing to search...
Searching...
No results found
Try searching with different keywords