# Vector

Summary
 Vector Types vector Represents a mathematical vector Variables x Equal to 0. y Equal to 1. z Equal to 2. Functions make Makes a vector from the given array get Gets the ith component of the given vector. add Adds two vectors and returns the results. zero Returns the zero vector of n dimensions. subtract The vector subtraction operation. scale Scales the vector by the given scalar value. dot Gives the dot product of two vectors magnitude2 Gives the square magnitude of the vector magnitude Gives the magnitude of the vector multiply Performs elementwise multiplication of two vectors. normalize Returns a normalized version of the given vector angle Gives the angle in radians between the two vectors. cross Gives the vector cross product of two vectors. project Projects vector a onto another vector b projectPlane Projects a vector onto a plane defined by a normal vector

### vector

Represents a mathematical vector

`vector<'a;n>`

#### Members

 data : ‘a[n] The internal data storage of the vector

### x

Equal to 0.  Represents the index of the x dimension

`uint8`

### y

Equal to 1.  Represents the index of the y dimension

`uint8`

### z

Equal to 2.  Represents the index of the z dimension

`uint8`

### 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

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>

#### 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 : ‘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`

#### 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