Spline¶
Render a 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.render.
Spline
¶ -
__init__
(points: Iterable[Vertex] = None, segments: int = 100)¶ - Parameters
points – spline definition points as
Vector
or(x, y, z)
tuplesegments – count of line segments for approximation, vertex count is segments + 1
-
subdivide
(segments: int = 4) → None¶ Calculate overall segment count, where segments is the sub-segment count, segments = 4, means 4 line segments between two definition points e.g. 4 definition points and 4 segments = 12 overall segments, useful for fit point rendering.
- Parameters
segments – sub-segments count between two definition points
-
render_as_fit_points
(layout: BaseLayout, degree: int = 3, method: str = 'chord', dxfattribs: dict = None) → None¶ Render a B-spline as 2D/3D
Polyline
, where the definition points are fit points.2D spline vertices uses:
add_polyline2d()
3D spline vertices uses:
add_polyline3d()
- Parameters
layout –
BaseLayout
objectdegree – degree of B-spline (order = degree + 1)
method – “uniform”, “distance”/”chord”, “centripetal”/”sqrt_chord” or “arc” calculation method for parameter t
dxfattribs – DXF attributes for
Polyline
-
render_open_bspline
(layout: BaseLayout, degree: int = 3, dxfattribs: dict = None) → None¶ Render an open uniform BSpline as 3D
Polyline
. Definition points are control points.- Parameters
layout –
BaseLayout
objectdegree – degree of B-spline (order = degree + 1)
dxfattribs – DXF attributes for
Polyline
-
render_uniform_bspline
(layout: BaseLayout, degree: int = 3, dxfattribs: dict = None) → None¶ Render a uniform BSpline as 3D
Polyline
. Definition points are control points.- Parameters
layout –
BaseLayout
objectdegree – degree of B-spline (order = degree + 1)
dxfattribs – DXF attributes for
Polyline
-
render_closed_bspline
(layout: BaseLayout, degree: int = 3, dxfattribs: dict = None) → None¶ Render a closed uniform BSpline as 3D
Polyline
. Definition points are control points.- Parameters
layout –
BaseLayout
objectdegree – degree of B-spline (order = degree + 1)
dxfattribs – DXF attributes for
Polyline
-
render_open_rbspline
(layout: BaseLayout, weights: Iterable[float], degree: int = 3, dxfattribs: dict = None) → None¶ Render a rational open uniform BSpline as 3D
Polyline
. Definition points are control points.- Parameters
layout –
BaseLayout
objectweights – list of weights, requires a weight value (float) for each definition point.
degree – degree of B-spline (order = degree + 1)
dxfattribs – DXF attributes for
Polyline
-
render_uniform_rbspline
(layout: BaseLayout, weights: Iterable[float], degree: int = 3, dxfattribs: dict = None) → None¶ Render a rational uniform BSpline as 3D
Polyline
. Definition points are control points.- Parameters
layout –
BaseLayout
objectweights – list of weights, requires a weight value (float) for each definition point.
degree – degree of B-spline (order = degree + 1)
dxfattribs – DXF attributes for
Polyline
-
render_closed_rbspline
(layout: BaseLayout, weights: Iterable[float], degree: int = 3, dxfattribs: dict = None) → None¶ Render a rational BSpline as 3D
Polyline
. Definition points are control points.- Parameters
layout –
BaseLayout
objectweights – list of weights, requires a weight value (float) for each definition point.
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 entity, but as with all tools, you never
know if someone needs it some day.
-
class
ezdxf.render.
R12Spline
¶ -
__init__
(control_points: Iterable[Vertex], degree: int = 2, closed: bool = True)¶ - Parameters
control_points – B-spline control frame vertices as
(x, y)
tuples orVector
objectsdegree – degree of B-spline,
2
or3
are valid valuesclosed –
True
for closed curve
-
render
(layout: BaseLayout, segments: int = 40, ucs: UCS = None, dxfattribs: dict = None) → Polyline¶ Renders the B-spline into layout as 2D
Polyline
entity. Use anUCS
to place the 2D spline in 3D space, seeapproximate()
for more information.- Parameters
layout –
BaseLayout
objectsegments – count of line segments for approximation, vertex count is segments + 1
ucs –
UCS
definition, control points in ucs coordinates.dxfattribs – DXF attributes for
Polyline
-
approximate
(segments: int = 40, ucs: UCS = None) → List[Vertex]¶ Approximate B-spline by a polyline with segments line segments. If ucs is not
None
, ucs defines anUCS
, to transformed the curve into OCS. The control points are placed xy-plane of the UCS, don’t use z-axis coordinates, if so make sure all control points are in a plane parallel to the OCS base plane (UCS xy-plane), else the result is unpredictable and depends on the CAD application used to open the DXF file, it maybe crash.
-
Bezier¶
Render a bezier curve as 2D/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.render.
Bezier
¶ -
start
(point: Vertex, tangent: Vertex) → None¶ Set start point and start tangent.
- Parameters
point – start point as
Vector
or(x, y, z)
tupletangent – start tangent as vector, example:
(5, 0, 0)
means a horizontal tangent with a length of 5 drawing units
-
append
(point: Vertex, tangent1: Vertex, tangent2: Vertex = None, segments: int = 20)¶ Append a control point with two control tangents.
- Parameters
point – control point as
Vector
or(x, y, z)
tupletangent1 – first control tangent as vector “left” of control point
tangent2 – second control tangent as vector “right” of control point, if omitted tangent2 = -tangent1
segments – count of line segments for polyline approximation, count of line segments from previous control point to appended control point.
-
render
(layout: BaseLayout, force3d: bool = False, dxfattribs: dict = None) → None¶ Render bezier curve as 2D/3D
Polyline
.- Parameters
layout –
BaseLayout
objectforce3d – force 3D polyline rendering
dxfattribs – DXF attributes for
Polyline
-
EulerSpiral¶
Render an euler spiral as 3D Polyline
or Spline
.
This is a parametric curve, which always starts at the origin (0, 0)
.
-
class
ezdxf.render.
EulerSpiral
¶ -
__init__
(curvature: float = 1)¶ - Parameters
curvature – Radius of curvature
-
render_polyline
(layout: BaseLayout, length: float = 1, segments: int = 100, matrix: Matrix44 = None, dxfattribs: dict = None)¶ Render curve as
Polyline
.- Parameters
layout –
BaseLayout
objectlength – 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 – DXF attributes for
Polyline
- Returns
-
render_spline
(layout: BaseLayout, length: float = 1, fit_points: int = 10, degree: int = 3, matrix: Matrix44 = None, dxfattribs: dict = None)¶ Render curve as
Spline
.- Parameters
layout –
BaseLayout
objectlength – length measured along the spiral curve from its initial position
fit_points – count of spline fit points to use
degree – degree of B-spline
matrix – transformation matrix as
Matrix44
dxfattribs – DXF attributes for
Spline
- Returns
-
Random Paths¶
Random path generators for testing purpose.
-
ezdxf.render.
random_2d_path
(steps=100, max_step_size=1, max_heading=pi / 2, retarget=20) → Iterable[Vec2]¶ Returns a random 2D path as iterable of
Vec2
objects.- Parameters
steps – count of vertices to generate
max_step_size – max step size
max_heading – limit heading angle change per step to ± max_heading/2 in radians
retarget – specifies steps before changing global walking target
-
ezdxf.render.
random_3d_path
(steps=100, max_step_size=1, max_heading=pi / 2, max_pitch=pi / 8, retarget=20) → Iterable[Vector]¶ Returns a random 3D path as iterable of
Vector
objects.- Parameters
steps – count of vertices to generate
max_step_size – max step size
max_heading – limit heading angle change per step to ± max_heading/2, rotation about the z-axis in radians
max_pitch – limit pitch angle change per step to ± max_pitch/2, rotation about the x-axis in radians
retarget – specifies steps before changing global walking target