A python wrapper around a subset of the ncollide rust library
Project description
A python wrapper around a subset of the ncollide rust library
Free software: MIT License
Documentation: https://ncollpyde.readthedocs.io.
Install
pip install ncollpyde
Pre-built wheels are available for Linux, MacOS, and Windows. If you have a stable rust compiler, you should also be able to install from source.
Features
Checking whether points are inside a volume defined by a triangular mesh
Checking the intersection of line segments with the mesh
Get the (signed) distance from points to the boundary of a mesh
Usage
This library implements most of its functionality through the Volume class, instantiated from an array of vertices, and an array of triangles as indices into the vertex array.
# get an array of vertices and triangles which refer to those points
import meshio
mesh = meshio.read("meshes/teapot.stl")
# use this library
from ncollpyde import Volume
volume = Volume(mesh.points, mesh.cells_dict["triangle"])
# or, for convenience
volume = Volume.from_meshio(mesh)
# containment checks: singular and multiple
assert [-2.30, -4.15, 1.90] in volume
assert np.array_equal(
volume.contains(
[
[-2.30, -4.15, 1.90],
[-0.35, -0.51, 7.61],
]
),
[True, False]
)
# line segment intersection
seg_idxs, intersections, is_backface = volume.intersections(
[[-10, -10, -10], [0, 0, 3], [10, 10, 10]],
[[0, 0, 3], [10, 10, 10], [20, 20, 20]],
)
assert np.array_equal(seg_idxs, [0, 1]) # idx 2 does not intersect
assert np.array_equal(seg_idxs, [0, 1])
assert np.allclose(
intersections,
[
[-2.23347309, -2.23347309, 0.09648498],
[ 3.36591285, 3.36591285, 5.356139],
],
)
assert np.array_equal(
is_backface,
[False, True],
)
# distance from boundary (negative means internal)
assert np.array_equal(
volume.distance([[10, 10, 10], [0, 0, 3]]),
[10.08592464, -2.99951118],
)
See the API docs for more advanced usage.
Known issues
Performance gains for multi-threaded queries are underwhelming, especially for ray intersections: see this issue
- Very rare false positives for containment
Due to a bug in the underlying library
Only happens when the point is outside the mesh and fires a ray which touches a single edge or vertex of the mesh.
Also affects is_backface result for ray intersection checks
manylinux-compatible wheels are built on CI but not necessarily in your local environment. Always allow CI to deploy the wheels.
If you are installing from a source distribution rather than a wheel, you need a compatible rust toolchain
ncollpyde v0.11 was the last to support meshio < 4.0.
Acknowledgements
Thanks to top users Philipp Schlegel (check out navis!) and Nik Drummond for their help in debugging and expanding ncollpyde ‘s functionality.
Thanks also to pyo3/ maturin developers @konstin and @messense for taking an interest in the project and helping along the way.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for ncollpyde-0.17.2-cp36-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c25842c3b2fca213f53ab1a06af0101fbb17a2f1a9378fa9e4349d62a366322 |
|
MD5 | 7c9ab57f91c115ba2cd731cbc7314152 |
|
BLAKE2b-256 | dd079625767a05587258b5f4b75967134406c44c92c81681ddb0020515282a58 |
Hashes for ncollpyde-0.17.2-cp36-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c0e98d060e9ed8bd7e06831ea913a15ecd6ebe13269e58435517cb4e6ca9ad8 |
|
MD5 | 7fe4e55873963c00ec5a136623a1db52 |
|
BLAKE2b-256 | 04a0da59542f5e8464430fe32303ad62727470a1ee445963a5815be523bf9c50 |
Hashes for ncollpyde-0.17.2-cp36-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8032180a36c92748fc0b9f68a8d5c3f94679a21017d702ef4a5c5433f36749b4 |
|
MD5 | d1644c13c2d3aa2fd3ec5117c8b93c5c |
|
BLAKE2b-256 | 89f838e5f661f58587efd932da787d067c28ebcb58eb95a0d163b973f862a16f |