@footmap/matrix
v0.0.3
Published
A toolkit for using vectors and matrices
Downloads
5
Readme
@footmap/matrix
A toolkit for using vectors and matrices
Install
Install the package from npm:
npm install --save @footmap/matrixOr, using yarn:
yarn add @footmap/matrixUsage
// foomap-matrix-demo.js
import { Vector, Matrix } from '@footmap/matrix'
const vector2 = new Vector(7, 3);
const vector3 = new Vector(7, 3, 9);
const matrix2x2 = new Matrix([1, 2], [3, 4]);
const matrix2x3 = new Matrix([1, 2, 3], [4, 5, 6]);
const matrix3x2 = new Matrix([1, 2], [3, 4], [5, 6]);
// 2D => 2D
console.log(vector2.transform(matrix2x2));
// Vector { components: [ 13, 33 ] }
// 3D => 2D
console.log(vector3.transform(matrix2x3));
// Vector { components: [ 40, 97 ] }
// 2D => 3D
console.log(vector2.transform(matrix3x2));
// Vector { components: [ 11, 33, 57 ] }
console.log(vector2.transform(matrix2x3));
// Error: Matrix columns length should be equal to vector components length.