Skip to main content

vector

An array of any number of floats.

as-mat

as-mat() 

Converts a vector to a row or column matrix.

The vector to convert.

mode:

The type of matrix to convert into. Must be one of "row" or "column".

as-vec

as-vec() 

Ensures a vector has an exact number of components. This is done by passing another vector init that has the required dimension. If the original vector does not have enough dimensions, the values from init will be inserted. It is recommended to use a zero vector for init.

The vector to ensure.

init:

The vector to check the dimension against.

len

len() 

Return length/magnitude of a vector.

The vector to find the magnitude of.

add

add() 

Adds two vectors of the same dimension

The vector on the left hand side.

The vector on the right hand side.

sub

sub() 

Subtracts two vectors of the same dimension

The vector on the left hand side.

The vector on the right hand side.

dist

dist() 

Calculates the distance between two vectors by subtracting the length of vector a from vector b.

Vector a

Vector b

scale

scale() 

Multiplys a vector with scalar x

The vector to scale.

The scale factor.

div

div() 

Divides a vector by scalar x

The vector to be divded.

The inverse scale factor.

neg

neg() 

Negates each value in a vector

The vector to negate.

norm

norm() 

Normalizes a vector (divide by its length)

The vector to normalize.

element-product

element-product() 

Multiply two vectors component-wise

First vector.

Second vector.

dot

dot() 

Calculates the dot product between two vectors.

The vector on the left hand side.

The vector on the right hand side.

cross

cross() 

Calculates the cross product of two vectors with a dimension of three.

The vector on the left hand side.

The vector on the right hand side.

angle2

angle2() 

Calculates the angle between two vectors and the x-axis in 2d space

The vector to measure the angle from.

The vector to measure the angle to.

angle

angle() 

Calculates the angle between three vectors

The vector to measure the angle from.

The vector to measure the angle at.

The vector to measure the angle to.

lerp

lerp() 

Linear interpolation between two vectors.

The vector to interpolate from.

The vector to interpolate to.

The factor to interpolate by. A value of 0 is v1 and a value of 1 is v2.