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
dim() -> int
Returns the dimension of a vector.
as-mat
as-mat() -> matrix
Converts a vector to a row or column matrix.
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
.
len
len() -> float
Return length/magnitude of a vector.
add
add() -> vector
Adds two vectors of the same dimension
sub
sub() -> vector
Subtracts two vectors of the same dimension
dist
dist() -> float
Calculates the distance between two vectors by subtracting the length of vector a
from vector b
.
scale
scale() -> vector
Multiplys a vector with scalar x
div
div()
Divides a vector by scalar x
neg
neg() -> vector
Negates each value in a vector
norm
norm() -> vector
Normalizes a vector (divide by its length)
dot
dot() -> float
Calculates the dot product between two vectors.
cross
cross() -> vector
Calculates the cross product of two vectors with a dimension of three.
angle2
angle2() -> angle
Calculates the angle between two vectors and the x-axis in 2d space
angle
angle()
Calculates the angle between three vectors
lerp
lerp()
Linear interpolation between two vectors.
rotate-z
rotate-z() -> vector
Rotates a vector of dimension 2 or 3 around the z-axis by an angle.