Skip to main content

A python wrapper around a subset of the ncollide rust library

Project description

https://img.shields.io/pypi/v/ncollpyde.svg Actions Status Documentation Status https://img.shields.io/badge/code%20style-black-000000.svg

A python wrapper around a subset of the ncollide rust library

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

Usage

# get an array of vertices and triangles which refer to those points
import meshio
mesh = meshio.read("tests/teapot.stl")
vertices = mesh.points
triangles = mesh.cells_dict["triangle"]

# use this library
from ncollpyde import Volume

volume = Volume(vertices, triangles)

Containment checks:

# individual points (as 3-length array-likes) can be checked with `in`
assert [-2.3051376, -4.1556454,  1.9047838] in volume
assert [-0.35222054, -0.513299, 7.6191354] not in volume

# many points (as an Nx3 array-like) can be checked with the `contains` method
bools = volume.contains(np.array([
    [-2.3051376, -4.1556454,  1.9047838],
    [-0.35222054, -0.513299, 7.6191354],
]))
assert np.array_equal(bools, [True, False])

# checks can be parallelised
volume.contains(np.random.random((1000, 3)), threads=4)

Note that v0.11 was the last to support meshio < 4.0.

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.

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

ncollpyde-0.16.0.tar.gz (258.9 kB view hashes)

Uploaded Source

Built Distributions

ncollpyde-0.16.0-cp36-abi3-win_amd64.whl (225.0 kB view hashes)

Uploaded CPython 3.6+ Windows x86-64

ncollpyde-0.16.0-cp36-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl (291.9 kB view hashes)

Uploaded CPython 3.6+ manylinux: glibc 2.5+ x86-64

ncollpyde-0.16.0-cp36-abi3-macosx_10_7_x86_64.whl (265.4 kB view hashes)

Uploaded CPython 3.6+ macOS 10.7+ x86-64

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