pub fn lerp<V>(u: V, v: V, t: f32) -> VExpand 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. Iftis 0.0, the result isu. Iftis 1.0, the result isv. For values between 0.0 and 1.0, the result is a point betweenuandv.
§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
Vdoes not implement the required traits (Add,Mul).
§Notes
- This function assumes
tis a floating-point number (f32) and works with vectors where theAddandMultraits are implemented.