Math utility functions
npm install lemonade-math
import { lerp } from 'lemonade-math';
console.log(lerp(0, 2, 0.5)); // 1
- Type:
(value: number, min:number, max:number) => number
Constrain a value to lie between two further values
- Type:
(a: number[3], b: number[3]) => number[3]
Compute the cross product of two 3D vectors
- Type:
(angle: number) => number
Convert an angle in degrees to radians
- Type:
(a: number[2|3], b: number[2|3]) => number
Compute the Euclidian distance between two vectors
- Type:
(a: number[2], b: number[2]) => number
Compute the Euclidian distance between two 2D vectors
- Type:
(a: number[3], b: number[3]) => number
Compute the Euclidian distance between two 3D vectors
- Type:
(a: number[2|3], b: number[2|3]) => number
Compute the square of the Euclidian distance between two vectors
- Type:
(a: number[2], b: number[2]) => number
Compute the square of the Euclidian distance between two 2D vectors
- Type:
(a: number[3], b: number[3]) => number
Compute the square of the Euclidian distance between two 3D vectors
- Type:
(value: number) => number
Compute the fractional part of a value
- Type:
({ x: number, y: number, z: number }) => { latitude: number, longitude: number }
Convert geocentric coordinates (x, y, z) to polar coordinates (latitude, longitude)
- Type:
(a: number[2|3|4], b: number[2|3|4]) => number
Compute the Euclidian length between two vectors
- Type:
(a: number[2], b: number[2]) => number
Compute the Euclidian length between two 2D vectors
- Type:
(a: number[3], b: number[3]) => number
Compute the Euclidian length between two 3D vectors
- Type:
(a: number[4], b: number[4]) => number
Compute the Euclidian length between two 4D vectors
- Type:
(a: number[2|3|4], b: number[2|3|4]) => number
Compute the square of the Euclidian length between two vectors
- Type:
(a: number[2], b: number[2]) => number
Compute the square of the Euclidian length between two 2D vectors
- Type:
(a: number[3], b: number[3]) => number
Compute the square of the Euclidian length between two 3D vectors
- Type:
(a: number[4], b: number[4]) => number
Compute the square of the Euclidian length between two 4D vectors
- Type:
(a: number, b: number) => number
Linearly interpolate between two values
- Type:
(a: number[2], b: number[2]) => number[2]
Linearly interpolate between two 2D vectors
- Type:
(a: number[3], b: number[3]) => number[3]
Linearly interpolate between two 3D vectors
- Type:
(a: number[4], b: number[4]) => number[4]
Linearly interpolate between two 4D vectors
- Type:
(value: number, min: number, max: number, nmin: number, nmax: number) => number
Convert a number from one range to an other
- Type:
(a: number[2], b: number[2], direction?: number) => number[2]
Compute the normal between two 2D vectors
- Type:
(a: number[2|3|4], b: number[2|3|4]) => number[2|3|4]
Compute the unit vector of a vector
- Type:
(a: number[2], b: number[2]) => number[2]
Compute the unit vector of a 2D vector
- Type:
(a: number[3], b: number[3]) => number[3]
Compute the unit vector of a 3D vector
- Type:
(a: number[4], b: number[4]) => number[4]
Compute the unit vector of a 4D vector
- Type:
({ latitude: number, longitude: number }) => { x: number, y: number, z: number }
Convert polar coordinates (latitude, longitude) to geocentric coordinates (x,y,z)
- Type:
(angle: number) => number
Convert an angle in radians to degrees
MIT License, see LICENSE for details