GLSL built-in function
degrees()
Converts an angle from radians to degrees. Handy when you want to reason about an angle like 45 or 90.
Syntax
float degrees(float radians)
vec2 degrees(vec2 radians)
vec3 degrees(vec3 radians)Parameters
- radians
- The angle in radians.
Return value
The angle in degrees: radians * 180 / PI.
Live example
Edit the code and the preview updates as you type.
How it works
degrees is the reverse of radians: degrees(3.1416) is 180.0.
The example takes the angle from atan, which is in radians, converts it to degrees and adds 180 so it runs from 0 to 360. After that, cutting the circle into 45-degree slices is simple arithmetic: floor(angle / 45.0) gives 8 slices.
Typical uses
- Angle-based patterns in round numbers: pie slices, clock faces, compass directions.
- Debugging: converting an angle to degrees makes it easier to check against what you expect.
Common mistakes
- Feeding the result back into
sinorcos. Those still need radians. - Forgetting the range of
atan. It returns -PI to PI, which becomes -180 to 180 degrees, not 0 to 360.
Related functions
radians()
Converts an angle from degrees to radians, the unit that sin, cos and the other trigonometric functions expect.
atan()
Returns the angle in radians whose tangent is y / x. The two-argument form atan(y, x) gives the full angle of a point around the origin, from -PI to PI.
floor()
Rounds x down to the nearest whole number that is less than or equal to x.