3D graphs to 3D Printable STL with OpenJSCAD

The Background:

After the AP exam my calculus class did random calculus projects. I did mine on the accuracy of a Taylor Series. The accuracy of a Taylor series at a given point depends on two factors, the number of terms calculated in that Taylor series and how far away that point is from the center of the Taylor series. I wanted to see how the error was affected by both the number of terms in the Taylor series and the distance away from the center point however, visualizing both is impossible with a 2D graph. So I settled on making a 3D graph. The problem is that 3D graphs are still hard to visualize on a 2D screen so I decided to 3D print these graphs.

The Problem:

After doing some research I could not find free software that could make STL files from a 3D graph. There are ways to make STL files from 3D graphs using Mathmatica and MATLAB however both of these are expensive. This software form townmath almost works however it is impossible to type in exact values for the x and y range which I needed to be able to do. 

The Solution:

Eventually, I came across OpenSCAD. OpenSCAD is essentially a mathematical 3D modeling tool where you can build any 3D shape using its programming language. I did not want to learn that language so I wrote some python code that outputted a .scad file. From that file I could export a printable STL from OpenSCAD. This code works by making a polygon of the graph made of triangular faces.  A top view showing how the triangles are arranged at certain points is shown below.

Eventually I realized that my software worked very well and could easily be generalized to work with most 3D functions. However, my current software was clunky because it required both python and OpenSCAD to be installed. I considered re-writing it in the OpenSCAD programming language but I did not want to learn that language. Eventually I found OpenJSCAD. OpenJSCAD is essentially OpenSCAD except it runs on JavaScript and works in a browser. I already knew some JavaScript so I translated my python code into OpenJSCAD. After a few modifications it worked.

The Result

With the change to OpenJSCAD the code does not require any special software to run. It can be entirely run from within a web browser. I have published the code on GitHub here. Included are instructions on how to create your own 3D graphs.