What is it?
Sylvester is a JavaScript library designed to let you do mathematics with vectors and matrices without having to write lots of loops and throw piles of arrays around. It includes classes for modelling vectors and matrices in any number of dimensions, and for modelling infinite lines and planes in 3-dimensional space. It lets you write object-oriented easy-to-read code that mirrors the maths it represents. For example, it lets you multiply vectors together:
var V1 = $V([3,4,5]);
var V2 = $V([9,-3,0]);
var d = V1.dot(V2);
// d is 15
var c = V1.cross(V2);
// c is the vector (15,45,-45)
and multiply matrices:
var M1 = $M([
[1,7,3],
[9,4,0],
[2,7,1]
]);
var M2 = $M([
[6,2,8],
[9,1,3],
[0,7,6]
]);
var M = M1.x(M2);
// M is the matrix
// 69 30 47
// 90 22 84
// 75 18 43
and any number of other useful arithmetic and geometric operations. For more information, take a look at the API documentation.
Download version 0.1.3
The download is a ZIP archive containing the following files:
sylvester.src.js– the full source code, with comments (43.8 kb)sylvester.js– the packed version (13.2 kb)sylvester.js.gz– a gzipped copy of the packed version (5.0 kb), so you can serve compressed codeCHANGELOG.txt
Sylvester is © 2007 James Coglan, and is released under the MIT license.
0.1 is the first released version. It consists of the Vector, Matrix, Line and Plane classes – a useful mathematical base on which to build. Later releases will add components for more specific geometric modelling functionality, building towards a feature-complete 1.0 release. For news and announcements, head over to my blog.
Bug reports and feature requests are both welcome at james@jcoglan.com. I am working on extending Sylvester to support line segments, flat polygons and 3-dimensional objects, with a view to building a 3D geometry framework with a rendering layer for the <canvas> element.
Compatibility
Sylvester has been successfully tested in Firefox 1.0, 1.5 and 2.0, Internet Explorer 5.5, 6.0 and 7.0, Opera 7, 8 and 9, and Safari 3 for Windows.