Skip to main content

vector

An array of any number of floats.

new

new() -> vector 

Returns a new vector of dimension dim with all fields set to init (defaults to 0).

dim:

Vector dimension

init:

Default: 0

Initial value of all fields

dim

dim() -> int 

Returns the dimension of a vector.

The vector to find the dimension of.

as-mat

as-mat() -> matrix 

Converts a vector to a row or column matrix.

The vector to convert.

mode:

Default: "row"

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

as-vec

as-vec() -> vector 

Ensures a vector has an exact dimension. 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:

Default: (0

The vector to check the dimension against.

len

len() -> float 

Return length/magnitude of a vector.

The vector to find the magnitude of.

add

add() -> vector 

Adds two vectors of the same dimension

The vector on the left hand side.

The vector on the right hand side.

sub

sub() -> vector 

Subtracts two vectors of the same dimension

The vector on the left hand side.

The vector on the right hand side.

dist

dist() -> float 

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

Vector a

Vector b

scale

scale() -> vector 

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() -> vector 

Negates each value in a vector

The vector to negate.

norm

norm() -> vector 

Normalizes a vector (divide by its length)

The vector to normalize.

dot

dot() -> float 

Calculates the dot product between two vectors.

The vector on the left hand side.

The vector on the right hand side.

cross

cross() -> vector 

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() -> angle 

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.

rotate-z

rotate-z() -> vector 

Rotates a vector of dimension 2 or 3 around the z-axis by an angle.

The vector to rotate.

angle:

The angle to rotate by.