js-vector
v1.0.7
Published
Javascript vector library
Downloads
4
Maintainers
Readme
README
Simple package to ease the creation and manipulation of vectors in JavaScript.
Creation
let Vector = require("js-vector");
myVec = new Vector(20, 5);
Clone
let Vector = require("js-vector");
myVec = new Vector(20, 5);
myClone = myVec.clone();
Add
let Vector = require("js-vector");
myVec = new Vector(20, 5);
myVec2 = new Vector(12, 20);
myVec.add(myVec2);
//myVec = {x: 32, y: 25}
Subtract
let Vector = require("js-vector");
myVec = new Vector(10, 15);
myVec2 = new Vector(5, 10);
myVec.subtract(myVec2);
//myVec = {x: 5, y: 5}
Multiply
let Vector = require("js-vector");
myVec = new Vector(2, 3);
myVec2 = new Vector(3, 2);
myVec.multiply(myVec2);
//myVec = {x: 6, y: 6}
Divide
let Vector = require("js-vector");
myVec = new Vector(20, 15);
myVec2 = new Vector(10, 5);
myVec.divide(myVec2);
//myVec = {x: 2, y: 3}
Get Magnitude
let Vector = require("js-vector");
myVec = new Vector(20, 15);
myVec.mag();
Set Magnitude
let Vector = require("js-vector");
myVec = new Vector(20, 15);
myVec.mag(3);
Normalize
let Vector = require("js-vector");
myVec = new Vector(20, 15);
myVec.norm();