1.1.0 • Published 6 years ago
reergymerej-vectors v1.1.0
vectors
2d vectors for the whole family
Installation
yarn add reergymerej-vectorsUsage
import Vector from 'reergymerej-vectors';
const vector = new Vector(3, 4);
console.log(vector.magnitude); // 5API
Properties
The following examples use
const vector = new Vector(3, 4);x
vector.x; // 3y
vector.y; // 4magnitude
vector.magnitude; // 5length
vector.length; // 5unit
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); // 39kickstarted by npm-boom