GLSL built-in function
radians()
Converts an angle from degrees to radians, the unit that sin, cos and the other trigonometric functions expect.
Syntax
float radians(float degrees)
vec2 radians(vec2 degrees)
vec3 radians(vec3 degrees)Parameters
- degrees
- The angle in degrees (360 is one full turn).
Return value
The angle in radians: degrees * PI / 180.
Live example
Edit the code and the preview updates as you type.
How it works
Shaders measure angles in radians, where a full turn is about 6.2831 (2 * PI) instead of 360. Most people think in degrees, so radians does the conversion:
| degrees | radians(degrees) |
|---|---|
| 0.0 | 0.0 |
| 90.0 | 1.5708 |
| 180.0 | 3.1416 |
| 360.0 | 6.2831 |
The example writes the rotation angle in degrees, swinging between 0 and 90, and converts it with radians before building the rotation matrix.
Typical uses
- Readable angles:
rotate(radians(30.0))says "30 degrees" more clearly thanrotate(0.5236). - Field of view: camera code often stores the field of view in degrees and converts it once.
Common mistakes
- Converting twice. If an angle already comes from
atanoru_time, it is already in radians. - Writing integer literals:
radians(90.0), notradians(90).
Related functions
degrees()
Converts an angle from radians to degrees. Handy when you want to reason about an angle like 45 or 90.
sin()
Returns the sine of an angle in radians, a smooth wave that repeats every 2 * PI and stays between -1.0 and 1.0.
cos()
Returns the cosine of an angle in radians: the same wave as sin, shifted a quarter turn ahead.