PI2
A high-precision floating-point constant representing the mathematical constant 2π (approx. 6.283), equivalent to a full circle (360°) in radians, commonly used in periodic calculations.
Core Advantages
Its core advantage is enhancing code readability and clarity of intent. Seeing `PI2` immediately signals 'a full cycle' or 'a 360-degree rotation' to a developer, which is more semantic than `PI * 2`. It also offers convenience and avoids a runtime multiplication.
Common Uses
Full Cycle Mapping: Mapping a [0, 1] range input (like UV coordinates) to a full wave cycle, e.g., `sin(uv.x * PI2)`.
Polar Coordinate Conversion: Multiplying a normalized angle by `PI2` to get the full rotational radian value when converting from polar to Cartesian coordinates.
Angle Normalization: Using `mod(angle, PI2)` to wrap any angle into the [0, 2π) range for cyclic processing.
Procedural Rotation & Patterns: Used to create full rotational animations around a point or to generate complete circular or ring-like patterns.
How to adjust
PI2 is a mathematical constant derived from PI. Its value is fixed and should not and cannot be adjusted. It precisely represents one full circle in radians.
Code Examples
1// Map the UV.x coordinate from a [0, 1] range to a full sine wave cycle
2const wave = TSL.sin( uv.x.mul( TSL.PI2 ) );