Spline

Render B-spline as 2D/3D Polyline, can be used with DXF R12. The advantage over R12Spline is the real 3D support which means the B-spline curve vertices has not to be in a plane and no hassle with UCS for 3D placing.

class ezdxf.addons.Spline
Spline.__init__(points=None, segments=100)
Parameters:
  • points – spline definition points
  • segments – count of line segments for approximation, vertex count is segments+1
Spline.render_as_fit_points(layout, degree=3, method='distance', power=.5, dxfattribs=None)

Render a B-spline as 2d/3d polyline, where the definition points are fit points.

  • 2d points in -> add_polyline2d()
  • 3d points in -> add_polyline3d()

To get vertices at fit points, use method=’uniform’ and use Spline.subdivide(count), where count is the sub-segment count, count=4, means 4 line segments between two definition points.

Parameters:
  • layout – ezdxf Layout object
  • degree – degree of B-spline
  • method – ‘uniform’, ‘distance’ or ‘centripetal’, calculation method for parameter t
  • power – power for ‘centripetal’, default is distance ^ .5
  • dxfattribs – DXF attributes for Polyline
Spline.render_open_bspline(layout, degree=3, dxfattribs=None)

Render an open uniform BSpline as 3D Polyline. Definition points are control points.

Parameters:
  • layout – ezdxf Layout object
  • degree – degree of B-spline, (order = degree + 1)
  • dxfattribs – DXF attributes for Polyline
Spline.render_uniform_bspline(layout, degree=3, dxfattribs=None):

Render a uniform BSpline as 3D Polyline. Definition points are control points.

Parameters:
  • layout – ezdxf Layout object
  • degree – degree of B-spline, (order = degree + 1)
  • dxfattribs – DXF attributes for Polyline
Spline.render_closed_bspline(layout, degree=3, dxfattribs=None)

Render a closed uniform BSpline as 3D Polyline. Definition points are control points.

Parameters:
  • layout – ezdxf Layout object
  • degree – degree of B-spline, (order = degree + 1)
  • dxfattribs – DXF attributes for Polyline
Spline.render_open_rbspline(layout, weights, degree=3, dxfattribs=None)

Render a rational open uniform BSpline as 3D Polyline. Definition points are control points.

Parameters:
  • layout – ezdxf Layout object
  • weights – list of weights, requires a weight value for each defpoint.
  • degree – degree of B-spline, (order = degree + 1)
  • dxfattribs – DXF attributes for Polyline
Spline.render_uniform_rbspline(layout, weights, degree=3, dxfattribs=None)

Render a rational uniform BSpline as 3D Polyline. Definition points are control points.

Parameters:
  • layout – ezdxf Layout object
  • weights – list of weights, requires a weight value for each defpoint.
  • degree – degree of B-spline, (order = degree + 1)
  • dxfattribs – DXF attributes for Polyline
Spline.render_closed_rbspline(layout, weights, degree=3, dxfattribs=None)

Render a rational BSpline as 3D Polyline. Definition points are control points.

Parameters:
  • layout – ezdxf Layout object
  • weights – list of weights, requires a weight value for each defpoint.
  • degree – degree of B-spline, (order = degree + 1)
  • dxfattribs – DXF attributes for Polyline

R12Spline

DXF R12 supports 2D B-splines, but Autodesk do not document the usage in the DXF Reference. The base entity for splines in DXF R12 is the POLYLINE entity. The spline itself is always in a plane, but as any 2D entity, the spline can be transformed into the 3D object by elevation and extrusion (OCS, UCS).

The result is not better than Spline, it is also just a POLYLINE, but as with all tools, I never know if someone needs it some day.

class:R12Spline
R12Spline.__init__(control_points, degree=2, closed=True)
Parameters:
  • control_points – B-spline control frame vertices as (x, y) tuples
  • degree – degree of B-spline, 2 or 3 is valid
  • closed – True for closed curve
R12Spline.render(layout, segments=40, ucs=None, dxfattribs=None)

Renders the B-spline into layout as 2D Polyline entity. Use an UCS to place the 2D spline in 3D space, see R12Spline.approximate() for more information.

Parameters:
  • layout – ezdxf Layout
  • segments – count of line segments to use, vertex count is segments+1
  • ucsUCS definition, control points in ucs coordinates.
  • dxfattribs – DXF attributes for Polyline
Returns:

the Polyline object

R12Spline.approximate(segments=40, ucs=None)
Parameters:
  • segments – count of line segments to use, vertex count is segments+1
  • ucsUCS definition, control points in ucs coordinates.
Returns:

list of vertices in OCS as Vector objects

Approximate B-spline by a polyline with segments line segments. If ucs is not None, ucs defines an UCS, to transformed the curve into OCS. The control points are placed in this UCS xy-plane, you shouldn’t use z-axis coordinates, if so make sure all control points are a plane parallel to the OCS base plane (UCS xy-plane), else the result is unpredictable and depends on the used CAD application (may be crash).

Bezier

Render bezier curve as 3D Polyline.

The Bezier class is implemented with multiple segments, each segment is an optimized 4 point bezier curve, the 4 control points of the curve are: the start point (1) and the end point (4), point (2) is start point + start vector and point (3) is end point + end vector. Each segment has its own approximation count.

class ezdxf.addons.Bezier
Bezier.start(point, tangent)

Set start point and start tangent.

Parameters:
  • point – start point as (x, y, z) tuple
  • tangent – start tangent as vector, also (x, y, z) tuple
Bezier.append(point, tangent1, tangent2=None, segments=20):

Append a control point with two control tangents.

Parameters:
  • point – the control point as (x, y, z) tuple
  • tangent1 – first control tangent as vector left of point
  • tangent2 – second control tangent as vector right of point, if omitted tangent2 = -tangent1
  • segments – count of line segments for polyline approximation, count of line segments from previous control point to this point.
Bezier.render(layout, force3d=False, dxfattribs=None)

Render bezier curve as 2D or 3D Polyline entity into layout.

Parameters:
  • layout – ezdxf Layout object
  • force3d – force rendering as 3D Polyline
  • dxfattribs – dict of DXF attributes e.g. {‘layer’: ‘mesh’, ‘color’: 7}

EulerSpiral

Render euler spiral as 3D Polyline or Spline.

class ezdxf.addons.EulerSpiral
EulerSpiral.__init__(curvature=1)
Parameters:curvature – Radius of curvature
EulerSpiral.render_polyline(layout, length=1, segments=100, matrix=None, dxfattribs=None)

Render euler spiral as 3D Polyline entity into layout.

Parameters:
  • layout – ezdxf Layout object
  • length – length measured along the spiral curve from its initial position
  • segments – count of line segments to use, vertex count is segments+1
  • matrix – transformation matrix as Matrix44
  • dxfattribs – dict of DXF attributes e.g. {‘layer’: ‘mesh’, ‘color’: 7}
EulerSpiral.render_spline(layout, length=1, fit_points=10, degree=3, matrix=None, dxfattribs=None)

Render euler spiral as Spline entity into layout, DXF version R2000 or later required.

Parameters:
  • layout – ezdxf Layout object
  • length – length measured along the spiral curve from its initial position
  • fit_points – count of spline fit points to use
  • degree – degree of spline
  • matrix – transformation matrix as Matrix44
  • dxfattribs – dict of DXF attributes e.g. {‘layer’: ‘mesh’, ‘color’: 7}