# 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](https://people.engr.tamu.edu/schaefer/research/iso_simplicial.pdf).
An example graph, including quad lines, of `y(x-y)^2 = 4x+8` (Python expression: `y*(x-y)**2 - 4*x - 8`)
<!-- Note: `src="https://cdn.jsdelivr.net/gh/jared-hughes/isosurfaces/assets/demo.svg"` is automatically replaced with a jsdelivr link for PyPI -->
<img src="https://cdn.jsdelivr.net/gh/jared-hughes/isosurfaces/assets/demo.svg" alt="Demo with grid lines" height=300>
## Installation
```sh
pip3 install isosurfaces
```
## Usage
```py
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
min_depth=3,
# Ensure max_quads is more than 4**min_depth to capture details better
# than a 2**min_depth by 2**min_depth uniform grid
max_quads=1000,
)
for curve in curves:
print(', '.join(f"({p[0]:.3f},{p[1]:.3f})" for p in curve))
```
## Dev examples
```sh
python3 isoline_demo.py && xdg-open out/demo.svg
manim -pql isosurface_demo.py --renderer=opengl --enable_gui
```
Pyflakes, allowing manim star imports
```sh
python3 -m pyflakes . | grep -v "star imports: manim"
```
Build source archive and wheel:
```sh
rm -rf dist build isosurfaces.egg-info
python3 setup.py sdist bdist_wheel
twine check dist/*
# for test:
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
# for actual
twine upload dist/*
```
## Code formatting
`isosurfaces` uses [`black`](https://github.com/psf/black) and [`isort`](https://github.com/PyCQA/isort). A Github Action will run to make sure it was applied.
## Related
Related projects:
- (2D, grid-based) https://pypi.org/project/meander/
- (2D, grid-based) https://pypi.org/project/contours/
- (Archived) https://github.com/AaronWatters/contourist
Other terms for an isoline:
- Contour
- Level curve
- Topographic map
Raw data
{
"_id": null,
"home_page": "https://github.com/jared-hughes/isosurfaces",
"name": "isosurfaces",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "Jared Hughes",
"author_email": "jahughes.dev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/da/cf/bd7e70bb7b8dfd77afdc79aba8d83afd4a9263f045861cd4ddd34b7f6a12/isosurfaces-0.1.2.tar.gz",
"platform": null,
"description": "# Isosurfaces\n\nConstruct 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.\n\nThis 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](https://people.engr.tamu.edu/schaefer/research/iso_simplicial.pdf).\n\nAn example graph, including quad lines, of `y(x-y)^2 = 4x+8` (Python expression: `y*(x-y)**2 - 4*x - 8`)\n\n<!-- Note: `src=\"https://cdn.jsdelivr.net/gh/jared-hughes/isosurfaces/assets/demo.svg\"` is automatically replaced with a jsdelivr link for PyPI -->\n<img src=\"https://cdn.jsdelivr.net/gh/jared-hughes/isosurfaces/assets/demo.svg\" alt=\"Demo with grid lines\" height=300>\n\n## Installation\n\n```sh\npip3 install isosurfaces\n```\n\n## Usage\n\n```py\nfrom isosurfaces import plot_isoline\nimport numpy as np\n\ndef f(x, y):\n return y * (x - y) ** 2 - 4 * x - 8\n\ncurves = plot_isoline(\n lambda u: f(u[0], u[1]),\n np.array([-8, -6]),\n np.array([8, 6]),\n # Increasing min_depth can help if you have small features\n min_depth=3,\n # Ensure max_quads is more than 4**min_depth to capture details better\n # than a 2**min_depth by 2**min_depth uniform grid\n max_quads=1000,\n)\n\nfor curve in curves:\n print(', '.join(f\"({p[0]:.3f},{p[1]:.3f})\" for p in curve))\n```\n\n## Dev examples\n\n```sh\npython3 isoline_demo.py && xdg-open out/demo.svg\nmanim -pql isosurface_demo.py --renderer=opengl --enable_gui\n```\n\nPyflakes, allowing manim star imports\n\n```sh\npython3 -m pyflakes . | grep -v \"star imports: manim\"\n```\n\nBuild source archive and wheel:\n\n```sh\nrm -rf dist build isosurfaces.egg-info\npython3 setup.py sdist bdist_wheel\ntwine check dist/*\n# for test:\ntwine upload --repository-url https://test.pypi.org/legacy/ dist/*\n# for actual\ntwine upload dist/*\n```\n\n## Code formatting\n\n`isosurfaces` uses [`black`](https://github.com/psf/black) and [`isort`](https://github.com/PyCQA/isort). A Github Action will run to make sure it was applied.\n\n## Related\n\nRelated projects:\n\n- (2D, grid-based) https://pypi.org/project/meander/\n- (2D, grid-based) https://pypi.org/project/contours/\n- (Archived) https://github.com/AaronWatters/contourist\n\nOther terms for an isoline:\n\n- Contour\n- Level curve\n- Topographic map\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Construct isolines/isosurfaces over a 2D/3D scalar field defined by a function (not a uniform grid)",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/jared-hughes/isosurfaces"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b168d5e9e6e0d6e43107d8393d2ee3d231dbb597bf93052c6f3117b313724980",
"md5": "32d685f12e3c2dab72a1b74c792772df",
"sha256": "525a49ba93f4dbc35303cd2faf30976af0f99d9274cfa2787aec016b8ef96c64"
},
"downloads": -1,
"filename": "isosurfaces-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "32d685f12e3c2dab72a1b74c792772df",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 11649,
"upload_time": "2024-02-26T00:20:41",
"upload_time_iso_8601": "2024-02-26T00:20:41.308006Z",
"url": "https://files.pythonhosted.org/packages/b1/68/d5e9e6e0d6e43107d8393d2ee3d231dbb597bf93052c6f3117b313724980/isosurfaces-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dacfbd7e70bb7b8dfd77afdc79aba8d83afd4a9263f045861cd4ddd34b7f6a12",
"md5": "16061f81d60a563b35857c96630415be",
"sha256": "fa51ebe864ea9355b26830e27fdd6a41d5a58b419fa8d4b47e3b8b80718d6e21"
},
"downloads": -1,
"filename": "isosurfaces-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "16061f81d60a563b35857c96630415be",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 11348,
"upload_time": "2024-02-26T00:20:52",
"upload_time_iso_8601": "2024-02-26T00:20:52.066194Z",
"url": "https://files.pythonhosted.org/packages/da/cf/bd7e70bb7b8dfd77afdc79aba8d83afd4a9263f045861cd4ddd34b7f6a12/isosurfaces-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-26 00:20:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jared-hughes",
"github_project": "isosurfaces",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "isosurfaces"
}