Vector

Summary
Vector
Types
vectorRepresents a mathematical vector
Variables
xEqual to 0.
yEqual to 1.
zEqual to 2.
Functions
makeMakes a vector from the given array
getGets the ith component of the given vector.
addAdds two vectors and returns the results.
zeroReturns the zero vector of n dimensions.
subtractThe vector subtraction operation.
scaleScales the vector by the given scalar value.
dotGives the dot product of two vectors
magnitude2Gives the square magnitude of the vector
magnitudeGives the magnitude of the vector
multiplyPerforms elementwise multiplication of two vectors.
normalizeReturns a normalized version of the given vector
angleGives the angle in radians between the two vectors.
crossGives the vector cross product of two vectors.
projectProjects vector a onto another vector b
projectPlaneProjects a vector onto a plane defined by a normal vector

Types

vector

Represents a mathematical vector

vector<'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 : uint32The 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>

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

Returns the zero vector of n dimensions.

Type Signature

<’a;n>() -> vector<’a;n>

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>

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>

Parameters

scalar : ‘aScaling 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

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

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

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>

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>

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

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>

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>

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>

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

Close