pub fn lerp<V>(u: V, v: V, t: f32) -> V
Expand description
Computes the linear interpolation between two vectors.
Linear interpolation (lerp) finds a point that is between two vectors, based on a given parameter t
.
It computes a weighted average of the vectors where t
determines the weight of the second vector.
§Arguments
u
- The starting vector.v
- The ending vector.t
- A scalar parameter between 0.0 and 1.0 that determines the interpolation point. Ift
is 0.0, the result isu
. Ift
is 1.0, the result isv
. For values between 0.0 and 1.0, the result is a point betweenu
andv
.
§Returns
A new vector that represents the interpolated result between u
and v
.
§Examples
use mini_matrix::{Vector, lerp};
let u = Vector::from([1.0, 2.0, 3.0]);
let v = Vector::from([4.0, 5.0, 6.0]);
let result = lerp(u, v, 0.5);
assert_eq!(result, Vector::from([2.5, 3.5, 4.5]));
§Panics
This function will panic if:
- The type
V
does not implement the required traits (Add
,Mul
).
§Notes
- This function assumes
t
is a floating-point number (f32
) and works with vectors where theAdd
andMul
traits are implemented.