PROWAREtech

articles » current » c-plus-plus » procedures » lerp

C/C++: LERP - Linear Interpolation Function

A useful function for easing the transition between two values over time.

Two versions for reference:


double lerp(double a, double b, double t)
{
	return a + (b - a) * t;
}

double lerp(double a, double b, double t)
{
	return a * (1 - t) + b * t;
}

See the JavaScript LERP article for examples of using LERP and vector LERP (VLERP).


PROWAREtech

Hello there! How can I help you today?
Ask any question

PROWAREtech

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
ACCEPT REJECT