trimesh.path.traversal module¶
- class trimesh.path.traversal.PathSample(points: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])¶
Bases:
object
- __init__(points: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])¶
- sample(distances: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], include_original: bool = False) ndarray[Any, dtype[float64]] ¶
Return points at the distances along the path requested.
- Parameters:
distances – Distances along the path to sample at.
include_original – Include the original vertices even if they are not specified in distance. Useful as this will return a result with identical area and length, however indexes of distance will not correspond with result.
- Returns:
samples – Samples requested. n==len(distances) if not include_original
- Return type:
(n, dimension)
- truncate(distance: float | floating | int | integer | unsignedinteger) ndarray[Any, dtype[float64]] ¶
Return a truncated version of the path. Only one vertex (at the endpoint) will be added.
- Parameters:
distance – Distance along the path to truncate at.
- Returns:
Path clipped to distance requested.
- Return type:
path
- trimesh.path.traversal.closed_paths(entities, vertices)¶
Paths are lists of entity indices. We first generate vertex paths using graph cycle algorithms, and then convert them to entity paths.
This will also change the ordering of entity.points in place so a path may be traversed without having to reverse the entity.
- Parameters:
entities ((n,) entity objects) – Entity objects
vertices ((m, dimension) float) – Vertex points in space
- Returns:
entity_paths – Ordered traversals of entities
- Return type:
sequence of (n,) int
- trimesh.path.traversal.discretize_path(entities, vertices, path, scale=1.0)¶
Turn a list of entity indices into a path of connected points.
- Parameters:
entities ((j,) entity objects) – Objects like ‘Line’, ‘Arc’, etc.
vertices ((n, dimension) float) – Vertex points in space.
path ((m,) int) – Indexes of entities
scale (float) – Overall scale of drawing used for Number tolerances in certain cases
- Returns:
discrete – Connected points in space that lie on the path and can be connected with line segments.
- Return type:
(p, dimension) float
- trimesh.path.traversal.resample_path(points: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], count: int | integer | unsignedinteger | None = None, step: float | floating | int | integer | unsignedinteger | None = None, step_round: bool = True, include_original: bool = False) ndarray[Any, dtype[float64]] ¶
Given a path along (n,d) points, resample them such that the distance traversed along the path is constant in between each of the resampled points. Note that this can produce clipping at corners, as the original vertices are NOT guaranteed to be in the new, resampled path.
ONLY ONE of count or step can be specified Result can be uniformly distributed (np.linspace) by specifying count Result can have a specific distance (np.arange) by specifying step
- Parameters:
points ((n, d) float) – Points in space
count (int,) – Number of points to sample evenly (aka np.linspace)
step (float) – Distance each step should take along the path (aka np.arange)
step_round – Alter step to the nearest integer division of overall length.
include_original – Include the exact original points in the output.
- Returns:
resampled – Points on the path
- Return type:
(j,d) float
- trimesh.path.traversal.split(path)¶
Split a Path2D into multiple Path2D objects where each one has exactly one root curve.
- Parameters:
path (trimesh.path.Path2D) – Input geometry
- Returns:
split – Original geometry as separate paths
- Return type:
list of trimesh.path.Path2D
- trimesh.path.traversal.vertex_graph(entities)¶
Given a set of entity objects generate a networkx.Graph that represents their vertex nodes.
- Parameters:
entities (list) – Objects with ‘closed’ and ‘nodes’ attributes
- Returns:
graph (networkx.Graph) – Graph where node indexes represent vertices
closed ((n,) int) – Indexes of entities which are ‘closed’
- trimesh.path.traversal.vertex_to_entity_path(vertex_path, graph, entities, vertices=None)¶
Convert a path of vertex indices to a path of entity indices.
- Parameters:
vertex_path ((n,) int) – Ordered list of vertex indices representing a path
graph (nx.Graph) – Vertex connectivity
entities ((m,) list) – Entity objects
vertices ((p, dimension) float) – Vertex points in space
- Returns:
entity_path – Entity indices which make up vertex_path
- Return type:
(q,) int