Reference

Vector

New

Input A list of numbers.
Output A vector containing the list of numbers.

Signature

vector_new(a: List): Vector

Example

vector_new([1, 2, 3]) // returns <1, 2, 3>

Add

Input Two vectors.
Output A vector that is the sum of the two input vectors.

Signature

vector_add(a: Vector, b: Vector): Vector

Example

vector_add(vector_new([1, 2]), vector_new([3, 4])) // returns <4, 6>

Subtract

Input Two vectors.
Output A vector that is the difference of the two input vectors.

Signature

vector_sub(a: Vector, b: Vector): Vector

Example

vector_sub(vector_new([5, 7]), vector_new([2, 3])) // returns <3, 4>

Normalize

Input A vector.
Output A vector with the same direction but with a magnitude of 1.

Signature

vector_normalize(a: Vector): Vector

Example

vector_normalize(vector_new([3, 4])) // returns <0.6, 0.8>

Scale

Input A vector and a scalar.
Output A vector scaled by the given scalar.

Signature

vector_scale(a: Vector, b: Number): Vector

Example

vector_scale(vector_new([1, 2]), 3) // returns <3, 6>

Magnitude

Input A vector.
Output The magnitude of the input vector.

Signature

vector_magnitude(a: Vector): Number

Example

vector_magnitude(vector_new([3, 4])) // returns 5

Angle

Input Two vectors.
Output The angle between the two input vectors in radians.

Signature

vector_angle(a: Vector, b: Vector): Number

Example

vector_angle(vector_new([1, 0]), vector_new([0, 1])) // returns 1.5708...

Dot

Input Two vectors.
Output The dot product of the two vectors.

Signature

vector_dot(a: Vector, b: Vector): Number

Example

vector_dot(vector_new([1, 2]), vector_new([3, 4])) // returns 11

Distance

Input Two vectors.
Output The Euclidean distance between the two vectors.

Signature

vector_distance(a: Vector, b: Vector): Number

Example

vector_distance(vector_new([0, 0]), vector_new([3, 4])) // returns 5