static float InverseLerp( Vector3 pos, Vector3 a, Vector3 b, bool clamp )

book_4_sparkGenerated
code_blocksInput

Description

The InverseLerp method calculates the linear parameter t that produces the position pos within the range defined by vectors a and b. This is essentially the inverse operation of linear interpolation (Lerp). The method returns a value between 0 and 1 if pos is within the range of a and b. If clamp is set to true, the result will be clamped between 0 and 1.

Usage

Use this method when you need to determine the relative position of a point along a line segment defined by two vectors. This can be useful in animations, physics calculations, or any scenario where you need to map a position to a normalized range.

Example

Vector3 point = new Vector3(5, 5, 5);
Vector3 start = new Vector3(0, 0, 0);
Vector3 end = new Vector3(10, 10, 10);

float t = Vector3.InverseLerp(point, start, end, true);
// t will be 0.5 if point is exactly in the middle of start and end.