Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the common name for the inverse of the lerp function?

The function lerp() is a common function in programming languages:

lerp(a, b, t) = a + t * (b - a).

Now for very many situatons I have an inverse function:

fraction(x, a, b) = (x - a) / (b - a).

This function is built so that

lerp(a, b, fraction(x, a, b)) == x

and

fraction(lerp(a, b, t), a, b) == t

However I'm not happy with the name "fraction". Is there a common name for this function?

like image 670
Erik Leppen Avatar asked May 13 '14 18:05

Erik Leppen


Video Answer


1 Answers

GLSL

GLSL's built-in functions include:

mix(), which works like your lerp() function.
smoothstep(), which works like your inverse-lerp function combined with hermite smoothing and a x = clamp(x, 0.0, 1.0).

You could consider the name linearstep() for your implementation.

Unity Engine

Unity's API includes:

Lerp()/LerpUnclamped()
InverseLerp(), which does exactly what your inverse-lerp function does.


Note: I wouldn't use the name fraction()— it seems that it would be easily confused with fract()/frac(), which do something completely different.

like image 88
Slipp D. Thompson Avatar answered Sep 22 '22 11:09

Slipp D. Thompson