Function
Static Public Summary | ||
public |
Component-wise addition of two arrays/vectors. |
|
public |
Component-wise addition of a set of arrays/vectors. |
|
public |
Component-wise addition of one vector with a scaled version of another vector. |
|
public |
Find the axis aligned angle of a 3d vector |
|
public |
Find the axis aligned angle of a 2d vector |
|
public |
Clamps the argument according to min and max. |
|
public |
Clamps each value in array according to min and max. |
|
public |
clampValue(value: number, min: number, max: number): number Clamps the value to min or max if value is less than min or greater than max |
|
public |
Find the cross product between two 3d vectors |
|
public |
Find the psudo cross product between two 2d vectors |
|
public |
Convert radians to degrees |
|
public |
descr(from: number[], to: number[], target: number[]): {vector: number[], sqr: number, distance: number, unit: number[]} Describes relationships between two points. |
|
public |
Get a unit vector between two points/coordinates. |
|
public |
Calculate the distance between two points/coordinates. |
|
public |
Calculate the dot product between two vectors |
|
public |
flattenList(arg: number[], flattend: number[], max: number): * Recursivly flattens a list of arguments to a 1 dimensional array |
|
public |
Test if a vector is a null vector |
|
public |
Linear interpolation between two numbers |
|
public |
Factory function for creating and assigning a matrix from an array. |
|
public |
Factory function for creating and assigning a 2x2 matrix. |
|
public |
Factory function for creating and assigning a 3x3 matrix. |
|
public |
Factory function for creating and assigning a 4x4 matrix. |
|
public |
Mix (interpolate) numbers or arrays (similar to glsl implementation). |
|
public |
Normalizes an array/vector |
|
public |
Normalise an angle to be between -PI to +PI |
|
public |
Create a vector of specific dimension and optionally set its values. |
|
public |
Get a unit vector that is perpendicular to the input vector. |
|
public |
Convert degrees to radians |
|
public |
Rounds a number to the specific number of digits. |
|
public |
rowsToColumns(arr: number[], cols: number, target: number[]): * Transpose a single dimensional array, representing 2d data, from rows first to columns first. |
|
public |
Computes the scalar value (length) of a vector |
|
public |
Component-wise scaling of an array or vector |
|
public |
Generates a list of interpolated values between from and to, where the number of elements returned are controlled by the steps argument. |
|
public |
Generates a list of interpolated values between 0 and 1, where the number of elements returned are controlled by the steps argument. |
|
public |
smoothstep(edge0: number, edge1: number, x: number): * Implementation of glsl smoothstep function |
|
public |
Implementation of glsl step function. |
|
public |
As glsl step function for multiple numeric values |
|
public |
As glsl step function for single numeric values |
|
public |
Component-wise subtraction of two arrays/vectors. |
|
public |
Component-wise subtraction of array/vector and all elements in vectors. |
|
public |
Component-wise addition of one vector with a scaled version of another vector. |
|
public |
Computes the sum of squares |
|
public |
Get the triple product between three 3d vectors |
|
public |
Create a vector from two points. |
|
public |
Factory function for creating and assigning a 2d vector. |
|
public |
Factory function for creating and assigning a 3d vector. |
|
public |
Factory function for creating and assigning a 4d vector. |
Static Public
public add(to: number[], from: number[], target: number[]): number[] source
import {add} from '@kjerandp/linear-algebra/src/functions.js'
Component-wise addition of two arrays/vectors. If target is NOT specified, the first argument will be mutated. Target will be overwritten and NOT included in the sum.
public addAll(vectors: number[][], target: number[]): number[] source
import {addAll} from '@kjerandp/linear-algebra/src/functions.js'
Component-wise addition of a set of arrays/vectors. If target is NOT specified, the first element in the set will be mutated. Target (if it has valid values) WILL be included in the sum.
Params:
Name | Type | Attribute | Description |
vectors | number[][] | Array of equally length arrays/vectors (to be added) |
|
target | number[] | optional array/vector to add into |
public addScaled(to: number[], from: number[], factor: number, target: number[]): number[] source
import {addScaled} from '@kjerandp/linear-algebra/src/functions.js'
Component-wise addition of one vector with a scaled version of another vector. If target is NOT specified, the first argument will be mutated. Target will be overwritten and NOT included in the sum.
public angle(vector: number[], axis: number): number source
import {angle} from '@kjerandp/linear-algebra/src/functions.js'
Find the axis aligned angle of a 3d vector
public angle2(vector: number[]): number source
import {angle2} from '@kjerandp/linear-algebra/src/functions.js'
Find the axis aligned angle of a 2d vector
Params:
Name | Type | Attribute | Description |
vector | number[] |
public clamp(arg: number | number[], min: number, max: number, target: number[]): number | number[] source
import {clamp} from '@kjerandp/linear-algebra/src/functions.js'
Clamps the argument according to min and max. Arg can be either a numeric value or an array of numeric values.
public clampArray(arr: number[], min: number, max: number, target: number[]): number[] source
import {clampArray} from '@kjerandp/linear-algebra/src/functions.js'
Clamps each value in array according to min and max.
public clampValue(value: number, min: number, max: number): number source
import {clampValue} from '@kjerandp/linear-algebra/src/functions.js'
Clamps the value to min or max if value is less than min or greater than max
public cross(v1: number[], v2: number[], target: number[]): number[] source
import {cross} from '@kjerandp/linear-algebra/src/functions.js'
Find the cross product between two 3d vectors
public cross2(v1: number[], v2: number[]): number source
import {cross2} from '@kjerandp/linear-algebra/src/functions.js'
Find the psudo cross product between two 2d vectors
public deg(r: number): number source
import {deg} from '@kjerandp/linear-algebra/src/functions.js'
Convert radians to degrees
Params:
Name | Type | Attribute | Description |
r | number | radians |
public descr(from: number[], to: number[], target: number[]): {vector: number[], sqr: number, distance: number, unit: number[]} source
import {descr} from '@kjerandp/linear-algebra/src/functions.js'
Describes relationships between two points.
public dir(from: number[], to: number[], target: number[]): number[] source
import {dir} from '@kjerandp/linear-algebra/src/functions.js'
Get a unit vector between two points/coordinates. This function does not mutate any arguments, but a target may still be used to control the return type or to avoid creating additional arrays.
public dist(p1: number[], p2: number[]): number source
import {dist} from '@kjerandp/linear-algebra/src/functions.js'
Calculate the distance between two points/coordinates.
public dot(v1: number[], v2: number[]): number source
import {dot} from '@kjerandp/linear-algebra/src/functions.js'
Calculate the dot product between two vectors
public flattenList(arg: number[], flattend: number[], max: number): * source
import {flattenList} from '@kjerandp/linear-algebra/src/utils.js'
Recursivly flattens a list of arguments to a 1 dimensional array
Return:
* |
public isNullVec(v: number[], epsilon: number): * source
import {isNullVec} from '@kjerandp/linear-algebra/src/functions.js'
Test if a vector is a null vector
Return:
* |
public lerp(a: number, b: number, t: number): number source
import {lerp} from '@kjerandp/linear-algebra/src/functions.js'
Linear interpolation between two numbers
public mat(arr: ...number, cols: number, rowsFirst: boolean): Matrix source
import {mat} from '@kjerandp/linear-algebra/src/matrix.js'
Factory function for creating and assigning a matrix from an array. The array must be 1 dimensional, and will be split into rows and columns based on the specified cols parameter. If array length divided by cols doesn't add up to a whole number, then only floor(args.length / cols) values will be read from the input array.
Initial values are passed in row-first order by default, but can optionally be passed in columns-first by setting the rowFirst argument to false.
public mat2(args: ...number): Matrix source
import {mat2} from '@kjerandp/linear-algebra/src/matrix.js'
Factory function for creating and assigning a 2x2 matrix. Initial values are passed in row-first order.
Params:
Name | Type | Attribute | Description |
args | ...number | initial values |
public mat3(args: ...number): Matrix source
import {mat3} from '@kjerandp/linear-algebra/src/matrix.js'
Factory function for creating and assigning a 3x3 matrix. Initial values are passed in row-first order.
Params:
Name | Type | Attribute | Description |
args | ...number | initial values |
public mat4(args: ...number): Matrix source
import {mat4} from '@kjerandp/linear-algebra/src/matrix.js'
Factory function for creating and assigning a 4x4 matrix. Initial values are passed in row-first order.
Params:
Name | Type | Attribute | Description |
args | ...number | initial values |
public mix(a: number[], b: number[], t: number | number[], target: number[]): number[] source
import {mix} from '@kjerandp/linear-algebra/src/functions.js'
Mix (interpolate) numbers or arrays (similar to glsl implementation). Works on both vectors and matrices, since they are both arrays.
public norm(vector: number[], target: number[]): number[] source
import {norm} from '@kjerandp/linear-algebra/src/functions.js'
Normalizes an array/vector
public nrad(r: number): number source
import {nrad} from '@kjerandp/linear-algebra/src/functions.js'
Normalise an angle to be between -PI to +PI
Params:
Name | Type | Attribute | Description |
r | number | radians |
public nvec(dim: number, values: Array<number>): Vector source
import {nvec} from '@kjerandp/linear-algebra/src/vector.js'
Create a vector of specific dimension and optionally set its values. If values contains only one element, the all components will be set to this value. Elements in values exceeding the specified dimension will be neglected.
public orth2(vector: number[], target: number[]): number[] source
import {orth2} from '@kjerandp/linear-algebra/src/functions.js'
Get a unit vector that is perpendicular to the input vector. Only for 2d vectors!
public rad(d: number): number source
import {rad} from '@kjerandp/linear-algebra/src/functions.js'
Convert degrees to radians
Params:
Name | Type | Attribute | Description |
d | number | degrees |
public round(v: number | number[], digits: number): number source
import {round} from '@kjerandp/linear-algebra/src/functions.js'
Rounds a number to the specific number of digits. Works with either a single number or an array of numbers, which means it can be used with vectors and matrices as well.
public rowsToColumns(arr: number[], cols: number, target: number[]): * source
import {rowsToColumns} from '@kjerandp/linear-algebra/src/utils.js'
Transpose a single dimensional array, representing 2d data, from rows first to columns first.
Return:
* |
public scalar(vector: number[]): number source
import {scalar} from '@kjerandp/linear-algebra/src/functions.js'
Computes the scalar value (length) of a vector
Params:
Name | Type | Attribute | Description |
vector | number[] | array/vector to compute |
public scale(arr: number[], factor: number, target: number[]): number[] source
import {scale} from '@kjerandp/linear-algebra/src/functions.js'
Component-wise scaling of an array or vector
public seq(from: number | number[], to: number | number[], steps: number, start: number, end: number): * source
import {seq} from '@kjerandp/linear-algebra/src/functions.js'
Generates a list of interpolated values between from and to, where the number of elements returned are controlled by the steps argument.
Return:
* |
public seqI(steps: number): * source
import {seqI} from '@kjerandp/linear-algebra/src/functions.js'
Generates a list of interpolated values between 0 and 1, where the number of elements returned are controlled by the steps argument.
Params:
Name | Type | Attribute | Description |
steps | number | interpolation steps |
Return:
* |
public smoothstep(edge0: number, edge1: number, x: number): * source
import {smoothstep} from '@kjerandp/linear-algebra/src/functions.js'
Implementation of glsl smoothstep function
Return:
* |
public step(edge: number | number[], x: number | number[], target: number[]): number | number[] source
import {step} from '@kjerandp/linear-algebra/src/functions.js'
Implementation of glsl step function. Returns 0 if an edge is less than the threshold x, otherwise 1
public stepArray(edges: number[], x: number | number[], target: number[]): number[] source
import {stepArray} from '@kjerandp/linear-algebra/src/functions.js'
As glsl step function for multiple numeric values
public stepValue(edge: number, x: number): number source
import {stepValue} from '@kjerandp/linear-algebra/src/functions.js'
As glsl step function for single numeric values
public sub(from: number[], vector: number[], target: number[]): number[] source
import {sub} from '@kjerandp/linear-algebra/src/functions.js'
Component-wise subtraction of two arrays/vectors. If target is NOT specified, the first argument will be mutated. Target will be overwritten and NOT included in the sum.
public subAll(from: number[], vectors: number[][], target: number[]): number[] source
import {subAll} from '@kjerandp/linear-algebra/src/functions.js'
Component-wise subtraction of array/vector and all elements in vectors. If target is NOT specified, the first argument will be mutated. Target will be overwritten and NOT included in the sum.
public subScaled(from: number[], vector: number[], factor: number, target: number[]): number[] source
import {subScaled} from '@kjerandp/linear-algebra/src/functions.js'
Component-wise addition of one vector with a scaled version of another vector. If target is NOT specified, the first argument will be mutated. Target will be overwritten and NOT included in the sum.
public sumsqr(arr: number[]): number source
import {sumsqr} from '@kjerandp/linear-algebra/src/functions.js'
Computes the sum of squares
Params:
Name | Type | Attribute | Description |
arr | number[] | array/vector to compute |
public triple(v1: number[], v2: number[], v3: number[]): number source
import {triple} from '@kjerandp/linear-algebra/src/functions.js'
Get the triple product between three 3d vectors
public vec(from: number[], to: number[], target: number[]): number[] source
import {vec} from '@kjerandp/linear-algebra/src/functions.js'
Create a vector from two points. This function will NOT mutate any arguments unless 'target' is the same as 'from'.
public vec2(args: ...number): Vector source
import {vec2} from '@kjerandp/linear-algebra/src/vector.js'
Factory function for creating and assigning a 2d vector. If a single argument is passed, then all components will be assigned with its value. Missing initial values will be filled with zeros.
Params:
Name | Type | Attribute | Description |
args | ...number | initial values |
public vec3(args: ...number): Vector source
import {vec3} from '@kjerandp/linear-algebra/src/vector.js'
Factory function for creating and assigning a 3d vector. If a single argument is passed, then all components will be assigned with its value. Missing initial values will be filled with zeros.
Params:
Name | Type | Attribute | Description |
args | ...number | initial values |
public vec4(args: ...number): Vector source
import {vec4} from '@kjerandp/linear-algebra/src/vector.js'
Factory function for creating and assigning a 4d vector. If a single argument is passed, then all components will be assigned with its value. Missing initial values will be filled with zeros.
Params:
Name | Type | Attribute | Description |
args | ...number | initial values |