trimesh.path.entities
entities.py
Basic geometric primitives which only store references to vertex indices rather than vertices themselves.
- class trimesh.path.entities.Arc(points, closed=None, layer=None, metadata=None, color=None, **kwargs)
Bases:
Entity
- bounds(vertices)
Return the AABB of the arc entity.
- Parameters
vertices ((n, dimension) float) – Vertices in space
- Returns
bounds – Coordinates of AABB in (min, max) form
- Return type
(2, dimension) float
- center(vertices, **kwargs)
Return the center information about the arc entity.
- Parameters
vertices ((n, dimension) float) – Vertices in space
- Returns
info – With keys: ‘radius’, ‘center’
- Return type
dict
- property closed
A boolean flag for whether the arc is closed (a circle) or not.
- Returns
closed – If set True, Arc will be a closed circle
- Return type
bool
- discrete(vertices, scale=1.0)
Discretize the arc entity into line sections.
- Parameters
vertices ((n, dimension) float) – Points in space
scale (float) – Size of overall scene for numerical comparisons
- Returns
discrete – Path in space made up of line segments
- Return type
(m, dimension) float
- property is_valid
Is the current Arc entity valid.
- Returns
valid – Does the current Arc have exactly 3 control points
- Return type
bool
- length(vertices)
Return the arc length of the 3-point arc.
- vertices(n, d) float
Vertices for overall drawing.
- Returns
length – Length of arc.
- Return type
float
- class trimesh.path.entities.BSpline(points, knots, layer=None, metadata=None, color=None, **kwargs)
Bases:
Curve
An open or closed B- Spline.
- __init__(points, knots, layer=None, metadata=None, color=None, **kwargs)
- discrete(vertices, count=None, scale=1.0)
Discretize the B-Spline curve.
- Parameters
vertices ((n, 2) or (n, 3) float) – Points in space
scale (float) – Scale of overall drawings (for precision)
count (int) – Number of segments to return
- Returns
discrete – Curve as line segments
- Return type
(m, 2) or (m, 3) float
- to_dict()
Returns a dictionary with all of the information about the entity.
- class trimesh.path.entities.Bezier(points, closed=None, layer=None, metadata=None, color=None, **kwargs)
Bases:
Curve
An open or closed Bezier curve
- discrete(vertices, scale=1.0, count=None)
Discretize the Bezier curve.
- Parameters
vertices ((n, 2) or (n, 3) float) – Points in space
scale (float) – Scale of overall drawings (for precision)
count (int) – Number of segments to return
- Returns
discrete – Curve as line segments
- Return type
(m, 2) or (m, 3) float
- class trimesh.path.entities.Curve(points, closed=None, layer=None, metadata=None, color=None, **kwargs)
Bases:
Entity
The parent class for all wild curves in space.
- property nodes
Returns an (n,2) list of nodes, or vertices on the path. Note that this generic class function assumes that all of the reference points are on the path which is true for lines and three point arcs.
If you were to define another class where that wasn’t the case (for example, the control points of a bezier curve), you would need to implement an entity- specific version of this function.
The purpose of having a list of nodes is so that they can then be added as edges to a graph so we can use functions to check connectivity, extract paths, etc.
The slicing on this function is essentially just tiling points so the first and last vertices aren’t repeated. Example:
self.points = [0,1,2] returns: [[0,1], [1,2]]
- class trimesh.path.entities.Entity(points, closed=None, layer=None, metadata=None, color=None, **kwargs)
Bases:
ABC
- __init__(points, closed=None, layer=None, metadata=None, color=None, **kwargs)
- bounds(vertices)
Return the AABB of the current entity.
- Parameters
vertices ((n, dimension) float) – Vertices in space
- Returns
bounds – Coordinates of AABB, in (min, max) form
- Return type
(2, dimension) float
- property closed
If the first point is the same as the end point the entity is closed
- Returns
closed – Is the entity closed or not?
- Return type
bool
- copy()
Return a copy of the current entity.
- Returns
copied – Copy of current entity
- Return type
- property end_points
Returns the first and last points. Also note that if you define a new entity class where the first and last vertices in self.points aren’t the endpoints of the curve you need to implement this function for your class.
- Returns
ends – Indices of the two end points of the entity
- Return type
(2,) int
- explode()
Split the entity into multiple entities.
- Returns
explode – Current entity split into multiple entities.
- Return type
list of Entity
- property is_valid
Is the current entity valid.
- Returns
valid – Is the current entity well formed
- Return type
bool
- property layer
Set the layer the entity resides on as a shortcut to putting it in the entity metadata.
- Returns
layer – Hashable layer identifier.
- Return type
any
- length(vertices)
Return the total length of the entity.
- Parameters
vertices ((n, dimension) float) – Vertices in space
- Returns
length – Total length of entity
- Return type
float
- property metadata
Get any metadata about the entity.
- Returns
metadata – Bag of properties.
- Return type
dict
- property nodes
Returns an (n,2) list of nodes, or vertices on the path. Note that this generic class function assumes that all of the reference points are on the path which is true for lines and three point arcs.
If you were to define another class where that wasn’t the case (for example, the control points of a bezier curve), you would need to implement an entity- specific version of this function.
The purpose of having a list of nodes is so that they can then be added as edges to a graph so we can use functions to check connectivity, extract paths, etc.
The slicing on this function is essentially just tiling points so the first and last vertices aren’t repeated. Example:
self.points = [0,1,2] returns: [[0,1], [1,2]]
- reverse(direction=-1)
Reverse the current entity in place.
- Parameters
direction (int) – If positive will not touch direction If negative will reverse self.points
- to_dict()
Returns a dictionary with all of the information about the entity.
- Returns
as_dict – Has keys ‘type’, ‘points’, ‘closed’
- Return type
dict
- class trimesh.path.entities.Line(points, closed=None, layer=None, metadata=None, color=None, **kwargs)
Bases:
Entity
A line or poly-line entity
- discrete(vertices, scale=1.0)
Discretize into a world- space path.
- Parameters
vertices ((n, dimension) float) – Points in space
scale (float) – Size of overall scene for numerical comparisons
- Returns
discrete – Path in space composed of line segments
- Return type
(m, dimension) float
- explode()
If the current Line entity consists of multiple line break it up into n Line entities.
- Returns
exploded
- Return type
(n,) Line entities
- property is_valid
Is the current entity valid.
- Returns
valid – Is the current entity well formed
- Return type
bool
- class trimesh.path.entities.Text(origin, text, height=None, vector=None, normal=None, align=None, layer=None, color=None, metadata=None)
Bases:
Entity
Text to annotate a 2D or 3D path.
- __init__(origin, text, height=None, vector=None, normal=None, align=None, layer=None, color=None, metadata=None)
An entity for text labels.
- Parameters
origin (int) – Index of a single vertex for text origin
text (str) – The text to label
height (float or None) – The height of text
vector (int or None) – An vertex index for which direction text is written along unitized: vector - origin
normal (int or None) – A vertex index for the plane normal: vector is along unitized: normal - origin
align ((2,) str or None) –
- Where to draw from for [horizontal, vertical]:
’center’, ‘left’, ‘right’
- angle(vertices)
If Text is 2D, get the rotation angle in radians.
- Parameters
vertices ((n, 2) float) – Vertices in space referenced by self.points
- Returns
angle – Rotation angle in radians
- Return type
float
- property closed
If the first point is the same as the end point the entity is closed
- Returns
closed – Is the entity closed or not?
- Return type
bool
- discrete(*args, **kwargs)
- property end_points
Returns the first and last points. Also note that if you define a new entity class where the first and last vertices in self.points aren’t the endpoints of the curve you need to implement this function for your class.
- Returns
ends – Indices of the two end points of the entity
- Return type
(2,) int
- property is_valid
Is the current entity valid.
- Returns
valid – Is the current entity well formed
- Return type
bool
- length(vertices)
Return the total length of the entity.
- Parameters
vertices ((n, dimension) float) – Vertices in space
- Returns
length – Total length of entity
- Return type
float
- property nodes
Returns an (n,2) list of nodes, or vertices on the path. Note that this generic class function assumes that all of the reference points are on the path which is true for lines and three point arcs.
If you were to define another class where that wasn’t the case (for example, the control points of a bezier curve), you would need to implement an entity- specific version of this function.
The purpose of having a list of nodes is so that they can then be added as edges to a graph so we can use functions to check connectivity, extract paths, etc.
The slicing on this function is essentially just tiling points so the first and last vertices aren’t repeated. Example:
self.points = [0,1,2] returns: [[0,1], [1,2]]
- property normal
A point representing the plane normal along the vector: vertices[normal] - vertices[origin]
- Returns
normal – Index of vertex
- Return type
int
- property origin
The origin point of the text.
- Returns
origin – Index of vertices
- Return type
int
- plot(vertices, show=False)
Plot the text using matplotlib.
- Parameters
vertices ((n, 2) float) – Vertices in space
show (bool) – If True, call plt.show()
- property vector
A point representing the text direction along the vector: vertices[vector] - vertices[origin]
- Returns
vector – Index of vertex
- Return type
int