trimesh.path.segments¶
segments.py¶
Deal with (n, 2, 3) line segments.
Functions:

Find pairs of segments which are colinear. 

Extrude 2D line segments into 3D triangles. 

Extrude 2D line segments into 3D triangles. 

Find the overlap of two parallel line segments. 

Convert a parametric line segment representation to a two point line segment representation 

Resample line segments until no segment is longer than maxlen. 

For 3D line segments defined by two points, turn them in to an origin defined as the closest point along the line to the zero origin as well as a direction vector and start and end parameter. 

Find any points that lie on a segment (not an endpoint) and then split that segment into two segments. 

Convert (n, 2, 2) line segments to an SVG path string. 

Find unique nonzero line segments. 

trimesh.path.segments.
colinear_pairs
(segments, radius=0.01, angle=0.01, length=None)¶ Find pairs of segments which are colinear.
 Parameters
segments ((n, 2, (2, 3)) float) – Two or three dimensional line segments
radius (float) – Maximum radius line origins can differ and be considered colinear
angle (float) – Maximum angle in radians segments can differ and still be considered colinear
length (None or float) – If specified, will additionally require that pairs have a mean vertex distance less than this value from each other to qualify.
 Returns
pairs – Indexes of segments which are colinear
 Return type
(m, 2) int

trimesh.path.segments.
extrude
(segments, height, double_sided=False)¶ Extrude 2D line segments into 3D triangles.
 Parameters
segments ((n, 2, 2) float) – 2D line segments
height (float) – Distance to extrude along Z
double_sided (bool) – If true, return 4 triangles per segment
 Returns
vertices ((n, 3) float) – Vertices in space
faces ((n, 3) int) – Indices of vertices forming triangles

trimesh.path.segments.
length
(segments, summed=True)¶ Extrude 2D line segments into 3D triangles.
 Parameters
segments ((n, 2, 2) float) – 2D line segments
height (float) – Distance to extrude along Z
double_sided (bool) – If true, return 4 triangles per segment
 Returns
vertices ((n, 3) float) – Vertices in space
faces ((n, 3) int) – Indices of vertices forming triangles

trimesh.path.segments.
overlap
(origins, vectors, params)¶ Find the overlap of two parallel line segments.
 Parameters
origins ((2, 3) float) – Origin points of lines in space
vectors ((2, 3) float) – Unit direction vectors of lines
params ((2, 2) float) – Two (start, end) distance pairs
 Returns
length (float) – Overlapping length
overlap ((n, 2, 3) float) – Line segments for overlapping distance

trimesh.path.segments.
parameters_to_segments
(origins, vectors, parameters)¶ Convert a parametric line segment representation to a two point line segment representation
 Parameters
origins ((n, 3) float) – Line origin point
vectors ((n, 3) float) – Unit line directions
parameters ((n, 2) float) – Start and end distance pairs for each line
 Returns
segments – Line segments defined by start and end points
 Return type
(n, 2, 3) float

trimesh.path.segments.
resample
(segments, maxlen, return_index=False, return_count=False)¶ Resample line segments until no segment is longer than maxlen.
 Parameters
segments ((n, 2, 2) float) – 2D line segments
maxlen (float) – The maximum length of a line segment
return_index (bool) – Return the index of the source segment
return_count (bool) – Return how many segments each original was split into
 Returns
resampled ((m, 2, 3) float) – Line segments where no segment is longer than maxlen
index ((m,) int) – [OPTIONAL] The index of segments resampled came from
count ((n,) int) – [OPTIONAL] The count of the original segments

trimesh.path.segments.
segments_to_parameters
(segments)¶ For 3D line segments defined by two points, turn them in to an origin defined as the closest point along the line to the zero origin as well as a direction vector and start and end parameter.
 Parameters
segments ((n, 2, 3) float) – Line segments defined by start and end points
 Returns
origins ((n, 3) float) – Point on line closest to [0, 0, 0]
vectors ((n, 3) float) – Unit line directions
parameters ((n, 2) float) – Start and end distance pairs for each line

trimesh.path.segments.
split
(segments, points, atol=1e05)¶ Find any points that lie on a segment (not an endpoint) and then split that segment into two segments.
We are basically going to find the distance between point and both segment vertex, and see if it is with tolerance of the segment length.
 Parameters
segments ((n, 2, (2, 3) float) – Line segments in space
points ((n, (2, 3)) float) – Points in space
atol (float) – Absolute tolerance for distances
 Returns
split – Line segments in space, split at vertices
 Return type
(n, 2, (3  3) float

trimesh.path.segments.
to_svg
(segments, digits=4, matrix=None, merge=True)¶ Convert (n, 2, 2) line segments to an SVG path string.
 Parameters
segments ((n, 2, 2) float) – Line segments to convert
digits (int) – Number of digits to include in SVG string
matrix (None or (3, 3) float) – Homogeneous 2D transformation to apply before export
 Returns
path – SVG path string with one line per segment IE: ‘M 0.1 0.2 L 10 12’
 Return type
str

trimesh.path.segments.
unique
(segments, digits=5)¶ Find unique nonzero line segments.
 Parameters
segments ((n, 2, (23)) float) – Line segments in space
digits (int) – How many digits to consider when merging vertices
 Returns
unique – Segments with duplicates merged
 Return type
(m, 2, (23)) float