Oihana PHP

lerp.php

Table of Contents

Functions

lerp()  : float
Linearly interpolates between two values.

Functions

lerp()

Linearly interpolates between two values.

lerp(float $a, float $b, float $t) : float

Computes $a + ( $b - $a ) * $t. The factor $t is not bounded: values outside the [0, 1] range extrapolate beyond the [$a, $b] segment.

Parameters
$a : float

The start value (returned when $t === 0.0).

$b : float

The end value (returned when $t === 1.0).

$t : float

The interpolation factor, typically in [0, 1].

Tags
example
use function oihana\core\numbers\lerp;

lerp( 0.0 , 10.0 , 0.0 ) ;  // 0.0
lerp( 0.0 , 10.0 , 0.5 ) ;  // 5.0
lerp( 0.0 , 10.0 , 1.0 ) ;  // 10.0
lerp( 0.0 , 10.0 , 2.0 ) ;  // 20.0 (extrapolation)
lerp( 10.0 , 0.0 , 0.25 ) ; // 7.5
author

Marc Alcaraz (ekameleon)

since
1.0.9
Return values
float

The interpolated value.

On this page

Search results