The library provides Vector class that supports core operations for mathematical 2d and 3d vectors (add, sub, mul, div, cross product, dot product).
- npm run build:
compile ts to js
- npm test:
run tests
- npm run lint:
run eslint
- npm run lint:fix:
run eslint in fix mode (--fix)
const a = new Vector (1, 2, 3); // 3D
const b = new Vector(1, 2); // 2D
Or by providing x, y, z as an array as parameter to the constructor.
const a = new Vector ([1, 2, 3]); // 3D
const b = new Vector([1, 2]); // 2D
Once you have constructed one or more vector objects, you can use the following mathematical operations to compute them:
const a = new Vector([1, 2, 3]);
const c = a.mul(10); // [10, 20, 30]
const a = new Vector([1, 2, 3]);
const c = a.div(10); // [0.1, 0.2, 0.3]
const a = new Vector([1, 2, 3]);
const b = new Vector([3, 2, 1]);
const c = a.add(b); // [4, 4, 4]
// OR const c = a.add([3, 2, 1]); // [4, 4, 4]
const a = new Vector([1, 2, 3]);
const b = new Vector([3, 2, 1]);
const c = a.sub(b); // [-2, 0, 2]
// OR const c = a.sub([3, 2, 1]); // [-2, 0, 2]
const a = new Vector([1, 2, 3]);
const b = new Vector([3, 2, 1]);
const c = a.cross(b); // [-4, 8, -4]
// OR const c = a.cross([3, 2, 1]); // [-4, 8, -4]
const a = new Vector([1, 2, 3]);
const b = new Vector([3, 2, 1]);
const c = a.dot(b); // 10
// OR const c = a.dot([3, 2, 1]); // 10