Very useful small class to perform vector calculations. Very practical as basis for all kinds of simulations and games where objects move through a two-dimensional space.
npm i 2dv
Use in your JavaScript/Typescript project
import { Vector } from '2dv';
// OR
const { Vector } = require('2dv');
const myVector = new Vector(10, 20);
myVector.add(100);
…
const newVector = Vector.add(myVector, 10);
…
Detailed documentation: https://wetterben.github.io/2dv/
- x
- y
- angle
- length
- magnitude
- max
- min
- add
- angleTo
- clone
- crossProduct
- divide
- dotProduct
- equals
- inverse
- multiply
- normalize
- set
- sub
- toArray
- add
- angleBetween
- closestPointBetween
- crossProduct
- distance
- divide
- dotProduct
- equals
- fromArray
- inverse
- isOnLine
- multiply
- normalize
- pointBetween
- sub
You can find a detailed documentation of all methods here: https://wetterben.github.io/2dv/
- Automated tests
- Visual Demo
- More methods
Feel free to add missing functions or fix things. Just do a PR.