Path¶
This module implements a geometrical Path
supported by several render backends,
with the goal to create such paths from LWPOLYLINE, POLYLINE and HATCH boundary paths
and send them to the render backend, see ezdxf.addons.drawing
.
Minimum common interface:
- matplotlib: PathPatch
matplotlib.path.Path() codes:
MOVETO
LINETO
CURVE4 - cubic Bèzier-curve
- PyQt: QPainterPath
moveTo()
lineTo()
cubicTo() - cubic Bèzier-curve
- PyCairo: Context
move_to()
line_to()
curve_to() - cubic Bèzier-curve
- SVG: SVG-Path
“M” - absolute move to
“L” - absolute line to
“C” - absolute cubic Bèzier-curve
ARC and ELLIPSE entities are approximated by multiple cubic Bézier-curves, which are close enough for display rendering. Non-rational SPLINES of 3rd degree can be represented exact as multiple cubic Bézier-curves, other B-splines will be approximated.
-
class
ezdxf.render.path.
Path
¶ -
-
is_closed
¶ Returns
True
if the start point is close to the end point.
-
classmethod
from_lwpolyline
(lwpolyline: LWPolyline) → Path¶ Returns a
Path
from aLWPolyline
entity, all vertices transformed to WCS.
-
classmethod
from_polyline
(polyline: Polyline) → Path¶ Returns a
Path
from aPolyline
entity, all vertices transformed to WCS.
-
classmethod
from_hatch_polyline_path
(polyline: PolylinePath, ocs: ezdxf.math.ucs.OCS = None, elevation: float = 0) → Path¶
-
classmethod
from_hatch_edge_path
(edges: EdgePath, ocs: ezdxf.math.ucs.OCS = None, elevation: float = 0) → Path¶
-
control_vertices
()¶ Yields all path control vertices in consecutive order.
-
has_clockwise_orientation
() → bool¶ Returns
True
if 2D path has clockwise orientation, ignores z-axis of all control vertices.
-
line_to
(location: Vector)¶ Add a line from actual path end point to location.
-
curve_to
(location: Vector, ctrl1: Vector, ctrl2: Vector)¶ Add a cubic Bèzier-curve from actual path end point to location, ctrl1 and ctrl2 are the control points for the cubic Bèzier-curve.
-
close
() → None¶ Close path by adding a line segment from the end point to the start point.
-
add_curves
(curves: Iterable[Bezier4P])¶ Add multiple cubic Bèzier-curves to the path.
Auto-detect if the path end point is connected to the start- or end point of the curves, if none of them is close to the path end point a line from the path end point to the curves start point will be added.
-
add_ellipse
(ellipse: ConstructionEllipse, segments=1)¶ Add an elliptical arc as multiple cubic Bèzier-curves, use
from_arc()
constructor of classConstructionEllipse
to add circular arcs.Auto-detect connection point, if none is close a line from the path end point to the ellipse start point will be added (see
add_curves()
).By default the start of an empty path is set to the start point of the ellipse, setting argument reset to
False
prevents this behavior.- Parameters
ellipse – ellipse parameters as
ConstructionEllipse
objectsegments – count of Bèzier-curve segments, at least one segment for each quarter (pi/2),
1
for as few as possible.reset – set start point to start of ellipse if path is empty
-
add_spline
(spline: BSpline, level=4)¶ Add a B-spline as multiple cubic Bèzier-curves.
Non-rational B-splines of 3rd degree gets a perfect conversion to cubic bezier curves with a minimal count of curve segments, all other B-spline require much more curve segments for approximation.
Auto-detect connection point, if none is close a line from the path end point to the spline start point will be added (see
add_curves()
).By default the start of an empty path is set to the start point of the spline, setting argument reset to
False
prevents this behavior.- Parameters
spline – B-spline parameters as
BSpline
objectlevel – subdivision level of approximation segments
reset – set start point to start of spline if path is empty
-
transform
(m: Matrix44) → Path¶ Returns a new transformed path.
- Parameters
m – transformation matrix of type
Matrix44
-
approximate
(segments: int) → Iterable[Vector]¶ Approximate path by vertices, segments is the count of approximation segments for each cubic bezier curve.
-