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.
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.
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.