GLSL built-in function
tan()
Returns the tangent of an angle in radians, sin / cos. It shoots off to infinity near 90 degrees.
Syntax
float tan(float angle)
vec2 tan(vec2 angle)
vec3 tan(vec3 angle)Parameters
- angle
- The angle in radians.
Return value
sin(angle) / cos(angle). Unbounded: very large near PI/2 + k * PI.
Live example
Edit the code and the preview updates as you type.
How it works
tan(a) is sin(a) / cos(a). Around 0 it behaves almost like a straight line, but as the angle approaches 90 degrees (1.5708), cos approaches 0 and the result explodes toward infinity. Then it jumps to minus infinity and starts climbing again. The example shows these repeating branches.
Typical uses
- Camera field of view:
tan(fov * 0.5)tells how wide the view is one unit in front of the camera, used to build ray directions. - Stylized distortions:
tanon coordinates produces stretched, accelerating patterns.
Common mistakes
- Evaluating it right at 90 degrees, where it divides by zero. Keep inputs away from
PI/2 + k * PIor clamp the result. - Expecting a value between -1 and 1 like
sin.tanhas no limit, so clamp before using it as a color.
Related functions
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.
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.