Description
The Vector3.InverseLerp
method calculates the linear parameter t
that produces the interpolant value within a specified range. It is the inverse operation of the Lerp
method. This method is useful for determining how far a point pos
is between two other points a
and b
in 3D space.
Usage
To use the InverseLerp
method, provide the position pos
you want to evaluate, the start point a
, the end point b
, and a boolean clamp
to indicate whether the result should be clamped between 0 and 1. The method returns a float
representing the parameter t
where pos
lies between a
and b
.
Example
Vector3 pointA = new Vector3(0, 0, 0);
Vector3 pointB = new Vector3(10, 10, 10);
Vector3 position = new Vector3(5, 5, 5);
float t = Vector3.InverseLerp(position, pointA, pointB, true);
// t will be 0.5, as position is halfway between pointA and pointB.