The Javascript Math Toolkit Project


I began my programming career in the late 1970’s on TI programmable calculators.  Since that time, I’ve worked in Fortran, Basic, Assembler, C, C++, Javascript/HTML, and Flash/Flex/Actionscript.  Although my focus on applied mathematics (particularly numerical analysis and computational geometry) has remained constant across language transitions, I handled every transition in the same manner.  Just in time.

In other words, a company or client makes a request for something in Actionscript.  My general reply would be along the lines of ‘oh yeah, I can do that’ followed by digging up some old Fortran, C, or C++ code and then converting it into the fab language of the day.  Even when I wrote something new in a new language, it was only a matter of time before it became something in a library of ‘past code’ to be ported to some new language when the demand arose.

Not only has the front-end dev. pendulum swung back to native from plugins, I’m seeing a number of devs. running into problems that are not programming problems as much as they are mathematical software issues.  Well, that’s where I come in and this time I decided to approach my value proposition in a different manner.

Instead of being reactive to client requests, I’ve taken on a pretty massive background project in an attempt to be proactive.  So, today I am pleased to announce the Javascript Math Toolkit Project.

jsMathToolkit is an attempt to produce an organized, high-quality math library for front-end developers that encompasses practically everything I’ve worked on since I began my business in 1997.  I expect the effort to be ongoing and driven by client demands, but my primary objective is to change my pat response from ‘oh yeah, I can do that’ to ‘oh yeah, I’ve ALREADY DONE THAT.’  And, btw, that solution is already packaged into a modular, documented, well-tested library.

jsMathToolkit is currently organized around RequireJS.  I am looking into supporting CommonJS in the future, although there are a number of challenges dealing with both environments from the same code base.  So, my intent is to move the library to a solid release-candidate state before circling back and working on CommonJS support.

Once development reaches a solid beta state, I will reach out to existing clients and solicit a beta test team.  I have not decided on how the library will be distributed, but at this stage it will most likely be a client-only library because of the required support level.  I’ve received a few inquiries about releasing the library for sale to the general public, but I’m very wary about such a path because I believe that support requirements could get out of hand.

After reaching the beta development goal, I will create a PDF file that documents all the classes and methods in the library for clients wishing to contract me out for development services.

Currently, the library contains 107 ‘classes’, encompassing well over 500 methods ranging from basic data structures to splines to simple physics to matrix analysis, and more.  There are 72 demos in the library, many of which could be split out into separate usable components such as a zoomable/pannable number line and some spline-based data visualization.

Here is a very brief list of the library layout and contents.  Look to future blog posts for announcements on new development.

Abstract Models

– Deal with basic operations (add, subtract, multiply, divide, etc.) on complex types; current models are Fractions and Clock Time.


– AI methods for game programmers, business intelligence, and advanced user interaction.  Current methods are pathfinding (A* for waypoints and tiles).  The future is wide open and will be heavily driven by client demand.

Complex Shapes

– Complex shapes are planar shapes defined by a draw stack.  This stack is similar to SVG in that it defines a sequence of move, line, and curve commands that define the shape.  A core method is provided for rendering/transforming the stack using EaselJS, although rendering is completely decoupled from shape description.


– The core package contains classes used across the entire library.  Line decorators (i.e. dashed and dotted) and data structures are here along with visual graph helper classes and the draw stack renderer (which contains a complete set of transformation tools).

Freehand Drawing

– This will be a subset of the freehand drawing library I created in Flex.  Currently under development.

Function Graphing

– A freeform Javascript function parser (i.e. enter and evaluate arbitrary functions in a calculator-like syntax) as well as a very general-purpose function graphing engine.  Currently under development.


– Various geometric tools such as convex hull and line simplification.


– Helper classes for drawing 2D graphs such as managing axes with tic marks, zoom/pan, etc.  Computations are decoupled from rendering so that you could use these classes with any visual environment.


– Forward and inverse.  Currently under development.


– Anything math-related that does not seem to fit elsewhere.  Currently contains cubic root finder, derivative methods, easing classes, a robust matrix class (with LU decomposition and backsolve), random number generation, and Quaternions (with SLERP and NLERP).

Planar Curves

– Lines, very deep quadratic and cubic Beziers, and a two-point Bezier curve with adjustable parameters.


– Everything is built on top of the Polygon class.  All the things you expect are here and you can solve point-in-polygon and polygon-polygon intersection problems.

Simple Physics

– For basic game development and complex UI components with a need for physics behaviors.  Various physics-based motions now and behaviors in the near future.


– Natural Cubic, Catmull-Rom, Quad Bezier, Cubic Bezier and a very rich set of spline-to-Bezier utilities.  Catmull-Rom and Cubic Bezier support closed-loop as well.


– A general-purpose data statistics class along with all the familiar distributions, carefully coded to avoid numerical issues and work with large sample sizes.  This stuff was not coded out of a book or from Wikipedia :)  NormInv works the way it should (f**k Excel) and you even get a fast quad. Bezier approximation for graphing the normal, which is useful for educational applications.  Linear least squares with polynomials (lines handled as a separate, optimized case).

Data analysis will be a huge focus of this library.  There is already a robust data-stats class and I’m adding table-based analysis as well with generous cross-tab facilities.  Bayesian analysis and machine learning classes are on the way.


– This is probably the deepest area of development at this stage of the library.  Includes a very robust set of Bezier curve utilities, practically every geometric utility you can think of (if not, let me know and I’ll code it), polygon utilities, number formatting, root finders, numerical integration, math utilities, circle utilities.  It goes on and on …

My goal for jsMathToolkit is to address important problems ranging from games to engineering to business intelligence to data analysis and visualization to complex UI’s to educational applications.  All with a focus on the needs of front-end developers.

Thanks to everyone who encouraged me to start this project and I hope you will follow the blog regularly for updates.

5 Comments on “The Javascript Math Toolkit Project

  1.  by  Richard Davey

    Sounds fascinating (and useful!). What license will it be released under? (and does it have a Github repo or similar, so others can contribute?)

    •  by  theAlgorithmist

      Thanks, Richard. Right now, this is how I make my living. I don’t have a comfy full-time job where I can afford to develop stuff like this and give it away. A library such as this requires a great deal of support and I can only afford to provide that support to paying clients if I want to eat and pay the bills. So, unless someone can make me a full-time offer where I can afford to release this to the public, it will remain a client-only library.


      – jim

      •  by  Andreas Renberg

        How much would you require in order to make it worthwhile to release as open source, and support development until it has enough support to stand on its own two feet?

        •  by  theAlgorithmist

          Andreas – I’ve been developing math libraries since the 1980’s, including an incredibly rigorously tested and debugged code base in excess of 250,000 lines of assembler. No matter how well tested, they NEVER stand on their own two feet. It is a nonstop, constant, time sink of answering questions, debugging someone’s application to prove the bug is not in your library, improving documentations/demos, and providing detailed hand-holding to customers. It would, honestly, have to be a full-time job and I may have to pay for some additional support resources once the number of frequent users exceeds a few dozen. I’ve thought about pursuing an NSF grant, but that’s the only thing I can think of at this time.

  2.  by  Joseph

    This looks really like a great Toolkit for developers. I see a lot of great features right out of the box.