I have the value of a function in three dimensions, $f(x, y, z)$, which varies smoothly.

I would like to compute a 3D mesh where $f(x, y, z)$ has a particular value.

Are there algorithms to do this? (And if so, any implementations?)

Note: This is the 3D equivalent of finding a contour of a 2D function, $f(x, y)$:

2D contour examlpe


2 Answers 2


I think you could use the "marching cubes" algorithm. If memory serves, it requires a grid of samples as input, so at the very least you should be able to sample your function and run the algorithm as-is. You also might be able to modify the algorithm to callback to f directly. There's a popular implementation at http://paulbourke.net/geometry/polygonise/ that might help you get started.

  • 1
    $\begingroup$ Thanks! For others, I used an implementation in scikit-image. $\endgroup$
    – davipatti
    Commented Jul 10, 2018 at 18:17

In addition to the voxel-based approach that rchilton suggests, you could also look at Delaunay-type algorithms. For example, the Computational Geometry Algorithms Library (CGAL) has some built-in functionality for surface mesh generation with examples here. You could also try distmesh, the essential idea of which has been ported to a number of other libraries and programming languages. There's also an interesting blog post about getting distmesh3d to work just right.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.