Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/maath/src/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { Quaternion, Vector3 } from "three";
import type { TypedArray, MyVector2, MyVector3 } from "./ctypes";
import { lerp as _lerp } from "./misc";
import { lerp as _lerp, lpi3 as _lpi3 } from "./misc";
import * as v2 from "./vector2";
import * as v3 from "./vector3";

Expand Down Expand Up @@ -84,6 +84,24 @@ export function lerp(
}
}

/**
*
* Interpolates using Lagrane Interpolation between three buffers, passed in as array into final
*
* @param buffers array of three buffers: bufferA, bufferB, bufferC
* @param final interpolation buffer (output)
* @param t time, reccomended
*/
export function lpi3(
buffers: [TypedArray, TypedArray, TypedArray],
final: TypedArray,
t: number
) {
for (let i = 0; i < buffers[0].length; i++) {
final[i] = _lpi3([buffers[0][i], buffers[1][i], buffers[2][i]], t);
}
}

// TODO add stride
// TODO Fix types & vectors
/**
Expand Down
16 changes: 16 additions & 0 deletions packages/maath/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ export function fade(t: number) {
return t * t * t * (t * (t * 6 - 15) + 10);
}

/**
*
* Returns the result of lagrange polynomial interpolation between A, B, and C by the time of t
*
* @param v array of three numbers to interpolate between
* @param t time
* @returns 3-point interpolation given pos of t
*/
export function lpi3(v: [number, number, number], t: number) {
return (
2 * (t - 1) * (t - 0.5) * v[0] -
4 * (t - 1) * t * v[1] +
2 * (t - 0.5) * t * v[2]
);
}

/**
*
* Returns the result of linearly interpolating between input A and input B by input T.
Expand Down