Skip to main content

Construct isolines/isosurfaces over a 2D/3D scalar field defined by a function (not a uniform grid)

Project description


Construct isolines/isosurfaces of a 2D/3D scalar field defined by a function, i.e. curves over which f(x,y)=0 or surfaces over which f(x,y,z)=0. Most similar libraries use marching squares or similar over a uniform grid, but this uses a quadtree to avoid wasting time sampling many far from the implicit surface.

This library is based on the approach described in Manson, Josiah, and Scott Schaefer. "Isosurfaces over simplicial partitions of multiresolution grids." Computer Graphics Forum. Vol. 29. No. 2. Oxford, UK: Blackwell Publishing Ltd, 2010.

An example graph, including quad lines, of y(x-y)^2 = 4x+8 (Python expression: y*(x-y)**2 - 4*x - 8)

Demo with grid lines


pip3 install isosurfaces


from isosurfaces import plot_isoline
import numpy as np

def f(x, y):
    return y * (x - y) ** 2 - 4 * x - 8

curves = plot_isoline(
    lambda u: f(u[0], u[1]),
    np.array([-8, -6]),
    np.array([8, 6]),
    # Increasing min_depth can help if you have small features
    # Ensure max_quads is more than 4**min_depth to capture details better
    # than a 2**min_depth by 2**min_depth uniform grid

for curve in curves:
    print(', '.join(f"({p[0]:.3f},{p[1]:.3f})" for p in curve))

Dev examples

python3 examples/ && xdg-open
manim -pql examples/ --renderer=opengl --enable_gui

Pyflakes, allowing manim star imports

python3 -m pyflakes . | grep -v "star imports: manim"

Build source archive and wheel:

rm -rf dist build isosurfaces.egg-info
python3 sdist bdist_wheel
twine check dist/*
# for test:
twine upload --repository-url dist/*
# for actual
twine upload dist/*


Related projects:

Other terms for an isoline:

  • Contour
  • Level curve
  • Topographic map

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

isosurfaces-0.1.0.tar.gz (10.1 kB view hashes)

Uploaded source

Built Distribution

isosurfaces-0.1.0-py3-none-any.whl (10.4 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page