Isosurfaces
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
)
Installation
pip3 install isosurfaces
Usage
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]),
min_depth=3,
max_quads=1000,
)
for curve in curves:
print(', '.join(f"({p[0]:.3f},{p[1]:.3f})" for p in curve))
Dev examples
python3 isoline_demo.py && xdg-open out/demo.svg
manim -pql isosurface_demo.py --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 setup.py sdist bdist_wheel
twine check dist/*
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
twine upload dist/*
Code formatting
isosurfaces
uses black
and isort
. A Github Action will run to make sure it was applied.
Related
Related projects:
Other terms for an isoline:
- Contour
- Level curve
- Topographic map