A robotics-focused linear algebra module
This code was officially presented at JSConf US 2013. There are slides from the talk here: AI.js: Robots with Brains
npm install vektor
npm test
var v = require('vektor').vector;
var a = new v(1, 0, 0);
// or
var b = new v({x: 1, y: 2, z: 3});
Note: Vectors can be initialized with 2 or 3 arguments only.
var c = a.add(b); // [2, 2, 3]
var c = a.dot(b); // 1
var c = a.cross(b); // [0, -3, 2]
var c = a.distanceFrom(b); // 3.6
var c = b.length(); // 3.74
Note: matrices can be of any size
var m = require('vektor').matrix;
var A = new m(2); // a 2x2 empty matrix
var B = new m(2, 3); // a 2x3 empty matrix
var I_3 = new m(3, 3, true); // a 3x3 identity matrix
/* our matrices:
A = [ [1, 2],
[3, 4] ];
B = [ [5, 6],
[7, 8] ];
*/
A.set(0,0,1);
A.set(0,1,2);
A.set(1,0,3);
A.set(1,1,4);
B.set(0,0,5);
B.set(0,1,6);
B.set(1,0,7);
B.set(1,1,8);
var c = A.get(1,1); // 4
var C = A.scale(-1); // A = [ [-1, -2], [-3, -4] ]
var C = A.add(B); // C = [ [6, 8], [10, 12] ]
var C = A.dot(B); // C = [ [19, 22], [43, 50] ]
var C = A.transpose(); // C = [ [1, 3], [2, 4] ]
var c = A.det(); // c = -2
Note: only works with square matrices... for now.
var c = A.trace(); // c = 5
- Rotations
- Translations
- Manipulator
- Tutorials :-)
Please, please, please help make this module more robust!
- Send in pull requests (make sure the tests pass)
- Discuss additional features in the Issues section
- Add your name and Github handle here:
- Rick Waldron - rwaldron
- Forbes Lindsay - ForbesLindesay
- Alexander Beletsky - alexanderbeletsky
- Bill Mills - BillMills