Description
The LerpRadians
method performs a linear interpolation between two angles, specified in radians, and returns the interpolated angle. This method is particularly useful for smoothly transitioning between two angles, taking into account the shortest path around the circle.
Usage
To use the LerpRadians
method, provide the starting angle from
, the target angle to
, the interpolation fraction frac
, and a boolean clamp
to determine if the result should be clamped between the start and end angles. The frac
parameter should be a value between 0 and 1, where 0 returns the start angle and 1 returns the end angle. If clamp
is set to true
, the result will be clamped to the range defined by from
and to
.
Example
// Example usage of LerpRadians
float startAngle = 0.0f; // Start angle in radians
float endAngle = MathF.PI; // End angle in radians (180 degrees)
float fraction = 0.5f; // Halfway between start and end
bool shouldClamp = true;
float interpolatedAngle = MathX.LerpRadians(startAngle, endAngle, fraction, shouldClamp);
// interpolatedAngle will be approximately 1.5708 radians (90 degrees)