Code Monkey home page Code Monkey logo

sylvester's Introduction

Sylvester

Vector and Matrix math for JavaScript. See the website for documentation.

Development

Sylvester is built using wake and tested with jstest. Tests should run on all target platforms, including browsers, Node and other JS runtimes.

Install the build tools:

$ npm install

To build the library from source:

$ npm run build

To test, run using various JS binaries and open the tests in the browser:

$ JS=(v8 node spidermonkey rhino narwhal ringo)
$ for js in "${JS[@]}"; do echo "$js" ; $js test/console.js ; echo $? ; done

$ cscript.exe test/console.js # on Windows

$ open test/browser.html

To view the website locally:

$ bundle exec staticmatic preview site

To build the static files for the website:

$ bundle exec staticmatic build site

License

(The MIT License)

Copyright (c) 2007-2015 James Coglan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sylvester's People

Contributors

jcoglan avatar zthomae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sylvester's Issues

Add AMD support

Please consider adding support for AMD, the Asynchronous Module Definition. The AMD plus web pattern seems suitable and it is easy to implement:

(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(factory);
    } else {
        // Browser globals
        root.amdWeb = factory(root.b);
    }
}(this, function () {

    // Current Sylvester code

    return {
        Sylvester: Sylvester,
        Vector: Vector,
        Matrix: Matrix,
        Line: Line,
        Plane: Plane,
        $V: $V,
        $M: $M,
        $L: $L,
        $P: $P
    }
}));

Plane.create Documentation Misleading

There are two cases for Plane.create(), when two arguments are passed and when three arguments are passed.

When two arguments are passed, the documentation and the code are in agreement: the second argument is used as the normal vector for the plane.

However, when three arguments are passed, the documentation and the code are in contradiction. The documentation claims that the second and third arguments should be direction vectors in the plane. However, the code does something different: it assumes that all three arguments are points in the plane, and it takes the cross product of (arg2-arg1) and (arg3-arg1) to compute the normal vector.

Please fix the documentation and code to be in agreement on this issue.

Browser compatibility in docs

Hello. Great library, thanks for all your work.

I see that the code uses array.map(), which isn't available for IE 8 and older. The docs does not state whether there's polyfill for IE. It would be helpful add a browser compatibility section in readme. Thanks.

Question. Sub matrix of matrix

Hi there,

just a simple question: do you have a way to get submatrix of other matrix with defined x, y and width and height, for example:

input
var Origin =
[
[ 0, 0, 1, 1, 1]
[0, 0, 1, 1, 1]
[0, 0, 1, 1, 1]
]

I need only part with 1,
var x0 = 2;
var y0 = 1;
var width = 3;
var height = 3;
var result = submatrix(Origin, x0, x0, width, height );

result matrix is:
[
[1,1,1]
[1,1,1]
[1,1,1]
]

Inverse of 1x1 Matrix

$M([[2]]).inv()
returns the error:
TypeError: Cannot read property '1' of undefined
in Chrome developer tools inspector.

It should return a matrix of:
[[0.5]] instead.

Replace <= and >=

Please replace all existing <= and >= with Sylvester.precision based operations such as

function leql(operand1, operand2) {
    return (operand1 < operand2) || eql(operand1, operand2);
}

for <=, which would probably solve #6 and other imaginable issues.

Can you add Vector.to2D?

I'm working in 2D only but Line.pointClosestTo returns 3D vector with z being 0, can you add Vector.to2D() function that would drop third element of a vector, right now there is Vector.to3D which adds zero, this would remove it. It is problem because when I want to use it later:

Vector.create([2, 0]).subtract(Vector.create([1, 0, 0])) - returns null

In order to make it work I need to use temp variable:
var t = Vector.create([1, 0, 0]);
t = Vector.create([t[0], t[1]]);
Vector.create([2, 0]).subtract(t);

Which is unwieldy but more importantly cannot be chained.

Problem in LineintersectionWith

Am I something wrong in below?

LineA : (1,3)(2,9), LineB : (1,6)(2,6) , Correct intersection Point should be (1.5, 6)

var a = sv.Line.create([1,3],[2,9]);
var b = sv.Line.create([1,6],[2,6],);
console.log('intersectionWith : ', a.intersectionWith(b));
But it result
intersectionWith : [3.000000000000011, 12.000000000000052, 0]
intersects : true
pointClosestTo : [3.000000000000011, 12.000000000000052, 0]
reflectionIn :
{ anchor: [-0.800000000000003, 3.600000000000001, -1.1617635945578294e-16],
direction: [0.41216786985544684, 0.9111079228383558, 1.2601095422223854e-17] }

Bug in toRightTriangular

Hi
I think there is a bug in Sylvester, in the toRightTriangular function of sylvester.src.js it is missing declaring j as a local variable.
Currently:
var n = this.elements.length, k = n, i, np, kp = this.elements[0].length, p;
Should be:
var n = this.elements.length, k = n, i, j, np, kp = this.elements[0].length, p;

It is currently modifying any global j variable.

Best regards

PS: did not find your contact address

global j in toRightTriangular in v 0.1.3

HI,

I have been using Sylvester as it is posted on the website v 0.1.3. The Unit testing framework I am using reported a global variable "j".

I tracked it down to the function "toRightTriangular" where "j" is used without being declared.

This seems already to have been fixed on the repository, but I am new to GIT, and don't know how to get the latest version.

Thanks Jacob

Release a new version

Hi there,

Would you mind tagging a new release? It looks like the last one was in 2008 so it's missing a bunch of commits.

At the moment, I'm hung up on the fact that the last tagged release has no package.json.

Thanks!

Issue with isAntiparallelTo(vector) documentation

Reading the api documentation for vector, under isAntiparallelTo() method it says: "Returns true iff vector’s direction is exactly opposed to that of the receiver, that is, if the angle between them is π." Wouldn't exactly opposite be π/2?

Rotation on both axis at the same time

Is something like this correct ? Matrix.RotationX(value).add(Matrix.RotationY(value)); How would i go about if i wanted to get the rotation on both axis by a given value ?

handling 'null' entries

Hi, I m having some trouble with 'null' values within a matrix. Is there a way to handle such entries? it would be great to keep them, and not replace these entries by another (numerical) value.

example:
a = [[1,2],[3,4],[null,5]]
$M(a) should deliver sth like:
[1 2
3 4
null 5]

but actually builds a matrix like this:
[1 2
3 4]

best, johsh

How to scale the X axis for Polygon?

Hello expert,

I have discovered the function "Polygon.prototype.scale(k, point)" always scale up/down the polygon in all directions (including X, Y, Z). However, I'd like to scale the polygon in X direction.

Could you please give me a few of algorithm suggestions?

Line.Segment.intersectionWith can fail

There is a possibility of Line.Segment.intersectionWith to fail, by trying to access a null object.

Current code:

intersectionWith: function(obj) {
    if (!this.line.intersects(obj)) { return null; }
    var P = this.line.intersectionWith(obj);
    return (this.contains(P) ? P : null);
  }

The problem exists with the value of 'P'. This can be returned as null. Thus when the last line is executed "this.contains(P)" the code will fail, as P is null.

Test Code:

a = Sylvester.Line.Segment.create([600,216], [200, 216])
b = Sylvester.Line.Segment.create([300,616], [200, 216])
a.intersectionWith(b) // returns a valid point
b.intersectionWith(a) // fails! TypeError: Cannot read property 'start' of null

Line Intersections (am I using this wrong?)

Posted also on Stack: http://stackoverflow.com/questions/11658338/line-intersections-with-sylvesterjs-did-i-break-my-maths

Am I misusing vectors, possibly? Or did I just forget how to use tangents to indicate a direction? I can't seem to get this intersections to work:

var angle = 45;
var line1 = $L([1,1],[Math.tan(angle * Math.PI/180),Math.tan(angle * Math.PI/180)]); //Should be a 45-degree angle
angle = -45;
var line2 = $L([0,0],[Math.tan(angle * Math.PI/180),Math.tan(angle * Math.PI/180)]); //Should be a -45-degree angle
line1.intersects(line2);
//returns false, should be true, I would think?

Update to ES6/npm

Someone has put Sylvester into a handy npm module: sylvester-es6. It's only a matter a time when the two versions diverge and the documentation no longer matches. Maybe it's time for a major update with incorporation of ES6, NPM and other relevant JS tools.
I'm currently using sylvester-es6 for this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.