- Notifications
You must be signed in to change notification settings - Fork1
A rich toolset for two dimensional vector math.
License
dcodeIO/JustMath.js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
An implementation of two dimensional vector math including a rich toolset for vector operations. It's also the mathlibrary behindeSoccer, a cross-platform multiplayer HTML5 game developed atUniversity ofApplied Sciences Bonn.
- Augments core Math
- Allows replacement of all methods (e.g. custom implementations of
JustMath.sqrt(value)) - Adds some convenience methods (
JustMath.sq(value),JustMath.cot(angle))
Vector instantiation (
new Vec2(vOrX[, y])) and cloning (Vec2#clone())Direct modification through
Vec2#xandVec2#y, also provides getters (Vec2#getX(),Vec2#getY()) and a setter(Vec2#set(vOrX[, y]))Vector addition (
Vec2#add(vOrX[, y])), subtraction (Vec2#sub(vOrX[, y])) and multiplication(Vec2#dot(vOrX[, y])))Vector orthogonality (
Vec2#ort())Vector normalization (
Vec2#norm()), scaling (Vec2#scale(factor)), inversion (Vec2#inv()) and magnitude(Vec2#mag(),Vec2#magSq()) calculationVector-Vector distances (
Vec2#dist(b),Vec2#distSq(b))Vector rotation (
Vec2#rot(angle)) and direction calculation (Vec2#dir())Vector projection (
Vec2#project(b)) and rejection (Vec2#reject(b))Vector reflection (
Vec2#reflect(n)), also with component-wise (projected and rejected component) scaling(Vec2#reflectAndScale(n, projectFactor, rejectFactor))Vector interpolation (
Vec2#lerp(p, percent))Vector containment in rectangle (
Vec2#inRect(p1, p2))[Vector,Vector] determinant calculation (
Vec2.det(v1, v2))Provides Vector#toString and
Vector#equals()Provides vector operation chaining, e.g.
vara=newVec2(1,2);varb=newVec2(2,1);varn=newVec2(0,1);a.clone().sub(b).norm().project(n)...
Provides
Vec2#toString()for pain-free debuggingIs of course able to evaluate
Vec2#equals(b)Exports and imports JSON payloads (
Vec2#getXY(),new Vec2(jsonPayload))Small allocation footprint when using
Vec2#clone()wiselyAccepts another Vec2 or plain X and Y coordinates as parameters where possible (e.g.
Vec2#add(vOrX[, y]))
- CommonJS compatible
- RequireJS/AMD compatible
- Shim compatible
- node.js compatible, also available vianpm (npm install justmath)
- Closure Compiler ADVANCED_OPTIMIZATIONS compatible (fully annotated)
- Fully documented usingjsdoc3
- Zero dependencies and prerequisites
- Small footprint
- Install:
npm install justmath
varJustMath=require("justmath"),Vec2=JustMath.Vec2;vara=newVec2(1,2);console.log("Not more than "+a.x+", "+a.y+", 3.");
<scriptsrc="//raw.github.com/dcodeIO/JustMath.js/master/JustMath.min.js"></script>
varJustMath=dcodeIO.JustMath,Vec2=JustMath.Vec2;vara=newVec2(1,2);alert("Not more than "+a.x+", "+a.y+", 3.");
varJustMath=require("/path/to/JustMath.js"),Vec2=JustMath.Vec2;vara=newVec2(1,2);alert("Not more than "+a.x+", "+a.y+", 3.");
- Run visual tests (requires working HTML5 Canvas)
- View source
- View deploy tests source
Apache License, Version 2.0 -http://www.apache.org/licenses/LICENSE-2.0.html
About
A rich toolset for two dimensional vector math.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.

