3D Printing Generator
DeutschEnglish

Math Surface Generator: Print Any Formula in 3D

What is a math surface?

A math surface is the graph of a function made solid. You type a formula such as 4 + cos(r*36), and the generator turns it into a printable model: here the concentric ripples of a stone dropped into water, as a 90 mm disc. The model suits teachers who want waves, saddles and bell curves on the desk, students who want to hold what the equation describes, and makers who like math art or want a vase or bowl whose shape comes from a formula.

The gallery of examples has fourteen ready-made models, from a mathematical rose to two-slit interference and a twisted vase. Open one with a click and change its formula.

How the generator works

  1. Open the generator and pick a “Preset”, or keep “Custom” and write your own formula.
  2. Choose the “Coordinate system” and type the formula.
  3. Set the “Domain”: the area, radius or height the formula is evaluated over.
  4. Set the “Shape”: hollow, wall thickness, slit wall or hub, depending on the mode.
  5. Download STL or 3MF.

Everything runs in your browser. Nothing is uploaded, and your design, including the formula, lives in the page link, so you can send it to someone who changes the numbers. The model has one color, called “Model” in the color panel.

The engine is a port of two open OpenSCAD projects: the plot-function library by Ryan A. Colyer and the coordinate models of the Geometry collection by Joan Horvath and Rich Cameron. The credits at the end give the details.

Five coordinate systems

The “Coordinate system” decides what your formula computes. Each mode keeps its own formula, so switching back and forth never loses what you wrote.

Coordinate systemWhat the formula returnsVariables
“Cartesian z = f(x, y)”height over the point x, yx, y, r, a, s
“Polar z = f(r, a)”height over a disc, at radius r and angle ar, a, x, y
“Lathe r = f(z, a)”radius of a solid of revolution at height z and angle az, a
“Curve r = f(a) as a wall”radius of a curve at angle a, built as a walla
“Twisted bar a = f(z)”angle by which a straight bar is turned at height zz

In the Cartesian mode r is the distance from the center, a the angle in degrees and s the slit position (see below). In the polar mode x and y are available as well, which is handy when a formula is easier to write with them. Angles are always in degrees.

The three surface modes build a solid body: the surface is the top, and the body goes down to the bed. The Cartesian and polar modes are height fields, the lathe mode makes vases, cups and chalices, and the curve and bar modes build thin walls on a hub.

Writing a formula

The formula follows OpenSCAD rules, so you can copy formulas from .scad files. What you can use:

  • Numbers and constants: 3.5, 2e-3, pi, e.
  • Operators: + − * / % ^, where ^ is a power and % the remainder. Write 2*x, not 2x. The characters − (minus), · and × are accepted too.
  • Comparisons and choices: <, >, <=, >=, ==, !=, &&, ||, ! and c ? a : b, which return 1 or 0 or pick a value.
  • Functions: sin cos tan asin acos atan atan2 (degrees), sqrt pow exp ln log (ln is natural, log is base 10), abs min max floor ceil round sign.

A few patterns to start from:

  • 4 + cos(r*36) is a ripple: 36 degrees per mm gives a wave every 10 mm.
  • 2 + 30*exp(-r*r/200) is a bell curve.
  • 20 + (x*x - y*y)/100 is a saddle.
  • max(1, 50 - 50/sqrt(x*x + y*y)) is a gravity well, and max keeps the center from dropping below 1 mm.
  • 20 + 3*sin(a*5 + z*4) in the lathe mode gives five twisted ribs.

If the formula cannot be read, the editor says at which character and falls back to a plain shape, so the preview still shows the area. Unknown names are reported with the name and position: check the variables of the chosen coordinate system.

Domain: how big and how fine

“Domain” sets the extent of the model:

  • Cartesian: “x from”, “x to”, “y from” and “y to” from −89 to 89 mm, so a model can be up to 178 mm wide.
  • Polar: “Outer radius” from 2 to 88 mm.
  • Lathe: “z from” and “z to” (0–180 mm) and “Points around” (12–720) for the smoothness of each ring.
  • Curve: “Angle from”, “Angle to” (±1080°, so a curve can wind around up to six times) and “Angle step”.
  • Twisted bar: “Bar length” and “Slice height”.

“Grid step” (0.1–5 mm, default 0.4) is the distance between the calculated points. A smaller step shows finer detail, such as a rippled surface with a short wavelength, but gives larger files. When a step would need more than 150,000 formula evaluations, the generator raises it and shows a warning with the value it used. As a rule of thumb, use a step of at most a twentieth of the shortest wavelength in your formula: the ripples with a 10 mm wavelength use 0.5 mm.

The build volume is 180 mm: surfaces are cut off above 180 mm and radii above 88 mm, each with a warning.

Hollow bowls and cups

Switch “Hollow” on in the polar or lathe mode and the inside is cut out. “Wall” (0.8–10 mm, default 2) is the thickness.

  • In the lathe mode the inside is the same profile moved inward, so you get an open cup with a floor of the same thickness. The chalice and the twisted vase work this way.
  • In the polar mode the inside is the surface moved down by “Wall”. The result is a thin shell that follows the surface, like the bowl from a sphere formula: a 20 mm radius cap with a 2 mm shell and no solid block under it. Its underside is open towards the bed, and where the underside is flatter than 45° it needs supports.

If the wall is as thick as the body is tall, the body stays solid and a warning says so.

The slit wall for wave experiments

In the Cartesian mode “Slit wall” puts a wall at y = 0 with “One slit” or “Two slits”. In front of the wall (y below 0) the formula “In front of the wall z = f(x, y)” applies, for example a plane wave 2.5*(1+cos(y*36))+2. Behind the wall the main formula applies, and s stands for the “Slit position”, the distance of each slit from the center line (2–60 mm). “Wall height” (1–60 mm) sets how tall the wall is. The area must reach from y = −1.5 mm to y = 1.5 mm, or the wall is left out with a warning.

The two-slit interference and single-slit examples use this: a classic of wave optics you can hold. Both are 50 × 55 mm.

Curve walls, twisted bars and the hub

The curve mode draws the curve r = f(a) as a wall. “Height” (2–180 mm, default 100) is the wall height, “Wall thickness” (0.8–5 mm, default 1.2) its thickness; a 1 mm foot, twice as wide, joins the wall to the hub. The Archimedean spiral is 80*a/90, and the rose curve 40*cos(3*a). Negative radii point the other way.

The bar mode turns a straight bar by a = f(z) degrees, counter-clockwise, so a line sweeps out a helicoid: the helicoid example turns a bar 90° over 100 mm.

Both modes can stand on a tube: “Hub tube” (on by default) adds a tube in the center. “Rod diameter” (2–12 mm, default 5) and “Hub clearance” (0.1–1 mm, default 0.3) set the hole, and the tube wall is the “Wall thickness”. With the defaults the hole is 5.6 mm and the tube 8 mm across, so several models stack on one 5 mm rod.

Printing tips and numbers

All models stand flat on the bed in a single color. We sliced the examples with PrusaSlicer for a Prusa MINI, 0.20 mm SPEED profile and Prusament PLA, with automatic supports switched on to see what needs them. We have not test-printed the models, so treat the numbers as estimates.

ExampleSizeFilamentPrint time
Mathematical rose44 mm wide, 21 mm tall10.0 g33 min
Bowl from a sphere formula40 mm wide3.2 g (+0.5 g supports)13 min
Chalice30 mm wide, 50 mm tall8.8 g (+0.2 g supports)50 min
Two-slit interference50 × 55 mm11.3 g41 min
Ripples on a disc90 mm wide19.8 g42 min
Saddle surface80 × 80 mm44.5 g1 h 24 min
Twisted vase120 mm tall37.6 g2 h 8 min
Archimedean spiral wall100 mm tall18.0 g1 h 44 min
Helicoid from a twisted bar60 mm bar, 100 mm tall15.2 g1 h 43 min

Tips:

  • Supports. The bowl and the chalice copy the source demos and need small supports. Print the bowl solid (“Hollow” off) to skip them. Every other example slices without supports.
  • Overhangs. A solid height surface never overhangs, however steep the slope. Overhangs only come from a hollow polar surface, a lathe profile that widens quickly with height (more than 45° from vertical) and a strongly twisted bar.
  • The helicoid. The original bar is 100 mm long; at that length its tip leans 57° and the tip needs supports. The example uses 60 mm, where the tip leans 43° and the model prints without them.
  • Layer lines. Smooth surfaces such as the bell curve show layer steps. Use 0.12–0.16 mm layers for them, and a smaller “Grid step” if the preview looks faceted.
  • Thin walls. Keep the “Wall thickness” of curve walls and bars at 0.8 mm or more; the default is 1.2 mm.

Sources and licenses

The Math surface generator builds on two projects. Both permit reuse, and we ported the relevant parts:

  • plot-function by Ryan A. Colyer (CC0 1.0, public domain): the three plotting modules for Cartesian, polar and lathe surfaces, the closed-mesh routine and the demo formulas for the gravity well, bowl, rose, chalice and two slits.
  • Geometry by Joan Horvath and Rich Cameron (CC BY 4.0): the coordinate models r(theta) (curve wall) and helicoid (twisted bar) with the hub for a rod.

Changes: formulas are typed as text and read by our own safe parser, values are limited to the build volume, and the hollow bowl and the slit wall are built as single bodies. The full list of licenses is on the licenses page.

Ready to try it? Open the Math surface generator, browse the examples, or give a vase a pattern with the Textured vase generator or shape a bowl with the Decorative bowl generator.

All parameters

The numeric settings of the generator with their default values and allowed ranges. Text, fonts, patterns and colors are set directly in the generator.

ParameterDefaultRangeMeaning
Formula
Domain
x from-40 mm-89 – 88 mmLeft edge of the plotted area.
x to40 mm-88 – 89 mmRight edge of the plotted area.
y from-40 mm-89 – 88 mmFront edge of the plotted area.
y to40 mm-88 – 89 mmBack edge of the plotted area.
Outer radius22 mm2 – 88 mmRadius of the plotted disc.
z from0 mm0 – 179 mmLowest height the formula is evaluated at; the body is placed on the bed.
z to50 mm1 – 180 mmHighest height the formula is evaluated at.
Angle from0 °-1080 – 1080 °Start angle of the curve in degrees.
Angle to90 °-1080 – 1080 °End angle of the curve in degrees; more than 360° winds around again.
Grid step0.4 mm0.1 – 5 mmDistance between the sampled points (x/y, along the radius or in height). Smaller gives finer detail and larger files.
Points around18012 – 720Number of points on each ring of the solid of revolution.
Angle step1 °0.25 – 10 °Distance between the sampled points of the curve in degrees.
Shape
Wall2 mm0.8 – 10 mmThickness of the hollow shell: the same surface moved down (polar) or inward (lathe) by this much is cut out.
Slit position10 mm2 – 60 mmDistance of each slit from the center line (x = ±s); the formulas can use it as s.
Wall height16 mm1 – 60 mmHeight of the wall with the slits at y = 0.
Wall thickness1.2 mm0.8 – 5 mmThickness of the curve wall or the twisted bar, and of the hub tube.
Height100 mm2 – 180 mmHeight of the wall or the twisted bar.
Rod diameter5 mm2 – 12 mmDiameter of the rod the hub fits on, so several models stack on one rod.
Hub clearance0.3 mm0.1 – 1 mmPlay between the rod and the hub on each side.

Frequently asked questions

Which formulas can I type in?

Numbers, the variables of the chosen coordinate system, the operators + − * / % ^, comparisons, c ? a : b, the constants pi and e and the functions sin, cos, tan, asin, acos, atan, atan2, sqrt, pow, exp, ln, log, abs, min, max, floor, ceil, round and sign. Angles are in degrees and log is base 10, as in OpenSCAD. A formula can be up to 200 characters long.

Is it safe to type a formula? Does it run as code?

It never runs as code. A small parser reads the text and only accepts the whitelisted functions and variables, so anything else is reported as an unknown name. Nothing is uploaded either: the formula lives in your browser and in the share link.

Do I need supports?

Most examples print without supports. The bowl (“Bowl from a sphere formula”) and the chalice need small ones, because they copy the shapes of the original demos: in our test slices that was 0.51 g for the bowl and 0.17 g inside the foot of the chalice. Switch off “Hollow” and the bowl becomes a solid block with no overhang. We have not test-printed any of the models.

Why is my model flat, cut off or smaller than I expected?

Heights below 0 are cut off, because every body stands on the bed. Heights above 180 mm and radii above 88 mm are limited and the editor shows a warning. If a formula divides by zero or takes the root of a negative number, those points are set to the minimum and the warning names the first one.

Can I stack several models on one rod?

Yes, for the curve wall and the twisted bar. “Hub tube” adds a tube in the middle whose inner diameter is “Rod diameter” plus twice the “Hub clearance”, so a 5 mm rod with 0.3 mm clearance needs a 5.6 mm hole. Stack as many models on the rod as you like.

Which file formats can I download?

STL and 3MF. The model has a single color, so a single extruder is enough.

Origin & license

  • plot-function by Ryan A. Colyer · CC0 1.0 · code ported – PlotFunction, PlotPolarFunction and PlotAxialFunction with PlotClosePoints ported (closed meshes from point loops), plus the demo formulas gravity well, bowl, rose, chalice, two-slit and one-slit. Adapted: formulas as text with a safe parser, values capped to the build volume, bowl and chalice as one body instead of difference(), slit wall and waves as one height field instead of union().
  • Geometry by Joan Horvath and Rich Cameron · CC BY 4.0 · code ported – Coordinate models r(theta).scad (curve as a wall with a foot) and helicoid.scad (twisted bar) with a hub for a rod ported. Adapted: curve and twist angle as formulas, angle range and sizes as parameters, hub optional.