Vector methods

Before jumping into the methods, it's highly recommened that you read through theVectorArgRest documentation, as it's used by all methods in the Vector class

Instance methods

import { Vector } from 'volts';

const a = new Vector(1,2,3);
const b = a.add(1); // calls .add(1) on 'a', and assigns 'a' to 'const b'

a.values; // [2,3,4]
b.values; // [2,3,4]

b.add(1); // also calls .add(1) on 'a'

The "correct" way to prevent the case above, is to copy the vector, then do the operation

import { Vector } from 'volts';

const a = new Vector(1,2,3);
const b = a.copy().add(1); // creates a new Vector and adds 1 to it

a.values; // [1,2,3] - not modified
b.values; // [2,3,4] - modified

b.add(1); // only modifies the 'b' Vecto

add

Adds two VectorArgRest together

sub

Subtracts one VectorArgRest from another VectorArgRest

mul

Multiples two VectorArgRest together

Vector.random2D

This static method returns a random unit-length 2D Vector

Vector.random3D

This static method returns a random unit-length 3D Vector

Last updated

Was this helpful?