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
start

Path start point, resetting the start point of an empty path is possible.

end

Path end point.

is_closed

Returns True if the start point is close to the end point.

classmethod from_lwpolyline(lwpolyline: LWPolyline)Path

Returns a Path from a LWPolyline entity, all vertices transformed to WCS.

classmethod from_polyline(polyline: Polyline)Path

Returns a Path from a Polyline entity, all vertices transformed to WCS.

classmethod from_spline(spline: Spline, level: int = 4)Path

Returns a Path from a Spline.

classmethod from_ellipse(ellipse: Ellipse, segments: int = 1)Path

Returns a Path from a Ellipse.

classmethod from_arc(arc: Arc, segments: int = 1)Path

Returns a Path from an Arc.

classmethod from_circle(circle: Circle, segments: int = 1)Path

Returns a Path from a Circle.

classmethod from_hatch_boundary_path(boundary: Union[PolylinePath, EdgePath], ocs: OCS = None, elevation: float = 0)Path

Returns a Path from a Hatch polyline- or edge path.

classmethod from_hatch_polyline_path(polyline: PolylinePath, ocs: OCS = None, elevation: float = 0)Path

Returns a Path from a Hatch polyline path.

classmethod from_hatch_edge_path(edge: EdgePath, ocs: OCS = None, elevation: float = 0)Path

Returns a Path from a Hatch edge 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: Vec3)

Add a line from actual path end point to location.

curve_to(location: Vec3, ctrl1: Vec3, ctrl2: Vec3)

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.

clone()Path

Returns a new copy of Path with shared immutable data.

reversed()Path

Returns a new Path with reversed segments and control vertices.

clockwise()Path

Returns new Path in clockwise orientation.

counter_clockwise()Path

Returns new Path in counter-clockwise orientation.

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 class ConstructionEllipse 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 object

  • segments – 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 object

  • level – 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 = 20) → Iterable[Vec3]

Approximate path by vertices, segments is the count of approximation segments for each cubic bezier curve.

flattening(distance: float, segments: int = 16) → Iterable[Vec3]

Approximate path by vertices and use adaptive recursive flattening to approximate cubic Bèzier curves. The argument segments is the minimum count of approximation segments for each curve, if the distance from the center of the approximation segment to the curve is bigger than distance the segment will be subdivided.

Parameters
  • distance – maximum distance from the center of the cubic (C3) curve to the center of the linear (C1) curve between two approximation points to determine if a segment should be subdivided.

  • segments – minimum segment count