reergymerej-vectors
v1.1.0
Published
2d vectors for the whole family
Downloads
10
Readme
vectors
2d vectors for the whole family
Installation
yarn add reergymerej-vectors
Usage
import Vector from 'reergymerej-vectors';
const vector = new Vector(3, 4);
console.log(vector.magnitude); // 5
API
Properties
The following examples use
const vector = new Vector(3, 4);
x
vector.x; // 3
y
vector.y; // 4
magnitude
vector.magnitude; // 5
length
vector.length; // 5
unit
vector.unit; // Vector { x: 0.6, y: 0.8 }
Methods/Functions
The following examples use
const vectorA = new Vector(3, 4);
const vectorB = new Vector(5, 6);
add
add(vectorA, vectorB); // Vector { x: 8, y: 10 }
vectorA.add(vectorB); // Vector { x: 8, y: 10 }
subtract
subtract(vectorA, vectorB); // Vector { x: -2, y: -2 }
vectorA.subtract(vectorB); // Vector { x: -2, y: -2 }
multiply
multiply(vectorA, vectorB); // Vector { x: 15, y: 24 }
vectorA.multiply(vectorB); // Vector { x: 15, y: 24 }
dotProduct
dotProduct(vectorA, vectorB); // 39
vectorA.dotProduct(vectorB); // 39
kickstarted by npm-boom