trimesh.path.traversal#
- class trimesh.path.traversal.PathSample(points)#
Bases:
object
- __init__(points)#
- sample(distances)#
- truncate(distance)#
Return a truncated version of the path. Only one vertex (at the endpoint) will be added.
- 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 numeric 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, count=None, step=None, step_round=True)#
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)
- 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