Vector
Types
alias vector

Represents a mathematical vector

alias vector<'a;n> = { data : 'a[n] }
Members
data : 'a[n]

The internal data storage of the vector

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
make

Makes a vector from the given array

Type Signature
<'a;n>(||)('a[n]) -> vector<'a;n>
Parameters
d : 'a[n]

The initial array of data

Returns

The vector

get

Gets the ith component of the given vector.

Type Signautre
<'a;n>(||)(uint32, vector<'a;n>) -> 'a
Parameters
i : uint32

The index of the component of the vector

v : vector<'a;n>

The vector to get the component of

Returns

The value at the ith position in the vector.

add

Adds two vectors and returns the results.

Type Signature
<'a;n>(||)(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
<'a;n>(||)() -> 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
<'a;n>(||)(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;n>(||)('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
<'a;n>(||)(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
<'a;n>(||)(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
<'a;n>(||)(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
<'a;n>(||)(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
<'a;n>(||)(vector<'a;n>) -> vector<'a;n> where 'a : num
Parameters
v : vector<'a;n>

The vector to normalize

Returns

The normalized vector

angle

Gives the angle in radians between the two vectors.

Type Signature
<'a;n>(||)(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
<'a>(||)(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
<'z;n>(||)(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
<'z;n>(||)(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