homework-vector-library
v1.0.1
Published
2D Vector Library, check jsdoc and readme.md
Downloads
3
Readme
Homework one - Vector Library.
Vector Library:
A JavaScript library for 2D vectors.
Installation
You can install the library using npm:
npm i homework-vector-library
code is in /src/
Usage
Adding vectors
const sum = a.add(b);
Calculating vector length
const abs = sum.abs();
console.log(a.toString()); // Output: Vector(1, 2)
console.log(b.toString()); // Output: Vector(2, 0.5)
console.log(sum.toString()); // Output: Vector(3, 2.5)
console.log(abs); // Output: 3.905124837953327
Finding unit vector
const unitA = a.unit();
console.log(unitA.toString()); // Output: Vector(0.4472135954999579, 0.8944271909999159)
Calculating direction angle
const angleA = a.angle();
console.log(angleA); // Output: 1.1071487177940904 (in radians)