Vector
Types
alias vector

Represents a mathematical vector

alias vector<a, n> = a[n]
Variables
x

Equal to 0. Represents the index of the x dimension

Type
uint8
y

Equal to 1. Represents the index of the y dimension

Type
uint8
z

Equal to 2. Represents the index of the z dimension

Type
uint8
Functions
add

Adds two vectors and returns the results.

Type Signature
(vector<a, n>, vector<a, n>) -> vector<a, n> where a : num
Parameters
v1 : vector<a, n>

The first vector to add

v2 : vector<a, n>

The second vector to add

Returns

The sum of the two vectors

zero
Type Signature
() -> vector<a, n> where a : num

Returns the zero vector of n dimensions.

Returns

The zero vector of n dimensions.

subtract

The vector subtraction operation.

Parameters
v1 : vector<a, n>

The first vector (minuend)

v2 : vector<a, n>

The second vector (subtrahend)

Type Signature
(vector<a, n>, vector<a, n>) -> vector<a, n> where a : num
Returns

The vector difference v1-v2

scale

Scales the vector by the given scalar value.

Type Signature
(a, vector<a, n>) -> vector<a, n> where a : num
Parameters
scalar : a

Scaling value

v : vector<a, n>

The vector to scale

Returns

The result of scalar*v

dot

Gives the dot product of two vectors

Type Signature
(vector<a, n>, vector<a, n>) -> a where a : num
Parameters
v1 : vector<a, n>

The first vector

v2 : vector<a, n>

The second vector

Returns

The result of v1 dot v2

magnitude2

Gives the square magnitude of the vector

Type Signature
(vector<a, n>) -> a where a : num
Parameters
v : vector<a, n>

The vector to find the magnitude^2 of

Returns

The square magnitude of the vector

magnitude

Gives the magnitude of the vector

Type Signature
(vector<a, n>) -> double where a : num
Parameters
v : vector<a, n>

The vector to find the magnitude of

Returns

The magnitude of the vector

multiply

Performs elementwise multiplication of two vectors.

Type Signature
(vector<a, n>, vector<a, n>) -> vector<a, n> where a : num
Parameters
u : vector<a, n>

The first vector

v : vector<a, n>

The second vector

Returns

The vector formed by elementwise multiplication of the two vectors

normalize

Returns a normalized version of the given vector

Type Signature
(vector<a, n>) -> vector<a, n> where a : num
Parameters
v : vector<a, n>

The vector to normalize

Returns

The normalized vector. If the input vector is the zero vector, the zero vector is returned.

angle

Gives the angle in radians between the two vectors.

Type Signature
(vector<a, n>, vector<a, n>) -> double where a : num
Parameters
v1 : vector<a, n>

The first vector

v2 : vector<a, n>

The second vector

Returns

The angle betweeen the two vectors.

cross

Gives the vector cross product of two vectors.

Type Signature
(vector<a, 3>, vector<a, 3>) -> vector<a, 3> where a : num
Parameters
u : vector<a, 3>

The first vector

v : vector<a, 3>

The second vector

Returns

The result of u cross v

project

Projects vector a onto another vector b

Type Signature
(vector<z, n>, vector<z, n>) -> vector<z, n> where z : num
Parameters
a : vector<z, n>

The vector to project

b : vector<z, n>

The other vector

Returns

The result of projecting vector a onto vector b

projectPlane

Projects a vector onto a plane defined by a normal vector

Type Signature
(vector<z, n>, vector<z, n>) -> vector<z, n> where z : num
Parameters
a : vector<z, n>

The vector to project

m : vector<z, n>

The vector normal to the plane

Returns

Vector a projected onto the plane defined by m