API reference

Top-level package for ncollpyde.

class ncollpyde.Volume(vertices: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], triangles: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], validate=False, threads: Optional[bool] = None, n_rays=3, ray_seed=1991)[source]

Bases: object

contains(coords: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], threads: Optional[bool] = None) numpy.ndarray[Any, numpy.dtype[numpy.bool_]][source]

Check whether multiple points (as a Px3 array-like) are in the volume.

Parameters
  • coords

  • threads – None, Whether to parallelise the queries. If None (default), refer to the instance’s threads attribute.

Returns

np.ndarray of bools, whether each point is inside the volume

distance(coords: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], signed: bool = True, threads: Optional[bool] = None) numpy.ndarray[source]

Check the distance from the volume to multiple points (as a Px3 array-like).

Distances are reported to the boundary of the volume. By default, if the point is inside the volume, the distance will be reported as negative. signed=False is faster but cannot distinguish between internal and external points.

Parameters
  • coords

  • signed – bool, default True. Whether distances to points inside the volume should be reported as negative.

  • threads – None, Whether to parallelise the queries. If None (default), refer to the instance’s threads attribute.

Returns

np.ndarray of float, the distance from the volume to each given point

dtype: numpy.dtype = dtype('float64')

Float data type used internally

property extents: numpy.ndarray[Any, numpy.dtype[numpy.float64]]

Axis-aligned bounding box of the volume.

Returns

2x3 numpy array of floats, where the first row is mins and the second row is maxes.

property faces: numpy.ndarray[Any, numpy.dtype[numpy.uint32]]

Mx3 array of uint32 describing indexes into points array making up triangles

classmethod from_meshio(mesh: meshio.Mesh, validate=False, threads=None, n_rays=3, ray_seed=None) Volume[source]

Convenience function for instantiating a Volume from a meshio Mesh.

Parameters
  • mesh – meshio Mesh whose only cells are triangles.

  • validate – as passed to __init__, defaults to False

  • threads – as passed to __init__, defaults to None

  • n_rays – as passed to __init__, defaults to 3

  • ray_seed – as passed to __init__, defaults to None (random)

Raises

ValueError – if Mesh does not have triangle cells

Returns

Volume instance

intersections(src_points: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], tgt_points: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], threads: Optional[bool] = None) Tuple[numpy.ndarray[Any, numpy.dtype[numpy.uint64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.bool_]]][source]

Get intersections between line segments and volume.

Line segments are defined by their start (source) and end (target) points. Only the first intersection for a given line segment is reported.

Even if there is only one line segment to check, the argument arrays must have 2 dimensions, e.g. [[0, 0, 0]], [[1, 1, 1]].

The output arrays are:

  • Which line segment the intersection refers to, as an index into the argument arrays

  • The point of intersection

  • Whether the intersection is with the inside face of the mesh

N.B. the inside face check will report True for cases where a line touches (“skims”) an external edge; see https://github.com/dimforge/ncollide/issues/335 .

N.B. threads=True here uses a slightly different implementation, so you may not see the performance increase as with other methods.

Parameters
  • src_points – Nx3 array-like

  • tgt_points – Nx3 array-like

  • threads – None, Whether to parallelise the queries. If None (default), refer to the instance’s threads attribute.

Raises

ValueError – Inputs have different shapes or are not Nx3

Returns

tuple of uint array of indices (N), float array of locations (Nx3), bool array of is_backface (N)

property points: numpy.ndarray[Any, numpy.dtype[numpy.float64]]

Nx3 array of float describing vertices

property rays: numpy.ndarray[Any, numpy.dtype[numpy.float64]]

Rays used to detect containment as an ndarray of shape (n_rays, 3).

These rays are in random directions (set with the ray seed on construction), and are the length of the diameter of the volume’s bounding sphere.

threads: bool = True

Whether to use threading