Release v0.13.1

By mozman, Sa 18 Juli 2020, in category Release

arc, drawing, ellipse, hatch, release, spline, transform

General Transformation Interface

New general transformation interface based on homogeneous transformation matrices. Supported transformations are scale & reflection, rotate and translate.

Transformation works best for entities with WCS vertices only like POINT, LINE or MESH. Uniform scale transformation works well for OCS entities like TEXT or INSERT. Problems exist for non uniform scaling and reflections for OCS entities including text or curves, especially the HATCH entity with arc- or ellipse edge paths, but ARC and ELLIPSE entities itself should work as expected.

Good support for:

Problems with non uniform scaling and/or reflections:

Untested:

Unsupported:

This new transformation interface also improves results for non uniform scaling for Insert.virtual_entities() and Insert.explode(), therefore the argument non_uniform_scaling to explicit enable non uniform scaling is marked as deprecated.

Example: rotate first line in "my.dxf" 90 degrees about the z-axis

import math
import ezdxf
from ezdxf.math import Matrix44

doc = ezdxf.readfile('my.dxf')
msp = doc.modelspace()
line = msp.query('LINE').first

if line:
    m = Matrix44.z_rotate(math.pi/2)
    line.transform(m)

Specialized entity transformation interfaces:

Simplified example:

...

if line:
    line.rotate_z(math.pi/2)

Drawing Add-on

The new drawing add-on by Matt Broadway is a translation layer to send DXF data to a render backend.

Basic supported for following backends are included:

Both packages are optional and not required to install ezdxf.

The implementation uses a Frontend object to break DXF entities down into graphic primitives and send this data to the Backend object. Not all DXF entities are supported yet and embedded ACIS data like in BODY, 3DSOLID or REGION will never be supported. Some of these missing DXF entities may get support in the future (LEADER, MLEADER, ACAD_TABLE). Support of start- and end width attributes for 2D polylines is also planned.

There are two example scripts to show how to use the drawing add-on to implement a DXF converter or DXF viewer.

Both are basic implementations without support for lineweights, linetypes, hatch pattern or multiple fonts and 3D objects are rendered flat into the xy-plane in wire-frame style. Additional features are planned, but don't expect a TrueView replacement, this is beyond our capabilities, time resources and the performance of a Python based project.

Example 1

Example 2

Example 3

Entity Converter

Convert CIRCLE and ARC to ELLIPSE entities by default the source ARC will be replaced by the new ELLIPSE entity:

for arc in msp.query('ARC'):
    arc.to_ellipse()

Set argument replace to False to add an additional ELLIPSE entity without deleting the source ARC:

for arc in msp.query('ARC'):
    arc.to_ellipse(replace=False)

Convert CIRCLE, ARC and ELLIPSE to SPLINE entities:

for arc in msp.query('ARC'):
    arc.to_spline()

The SPLINE entities have the best approximation with a minimum number of control points.

SPLINE from ARC

Math Tools

Constructors to create rational splines from arc (BSpline.from_arc()) and ellipses (BSpline.from_ellipse()).

Decomposition of non-rational B-splines into multiple Bezier curves by BSpline.bezier_decomposition() to feed B-splines into render engines with Bezier curve support. Works best with non-rational B-splines of 3rd degree, perhaps the the most common used B-spline, yielding cubic bezier curves, which are supported by many render engines.

Interface between the SPLINE DXF entity class and the construction tool BSpline(), Spline.construction_tool() returns the spline as BSpline() object and Spline.apply_construction_tool() transfer data from the BSpline() to the DXF entity. The same interface exist for the ELLIPSE entity and the ConstructionEllipse() class.

Interface to NURBS-Python to convert BSpline() objects to NURBS-Python curves by BSpline.to_nurbs_python_curve() and back by BSpline.from_nurbs_python_curve(). This requires the installation of the geomdl package which is the PyPI name of NURBS-Python:

    pip install --user geomdl

An interface to surfaces and volumes may follow, but only from NURBS-Python to ezdxf, because without ACIS support, ezdxf is restricted to mesh objects.

Rewritten spline interpolation without and with end derivative (tangents) support as function global_spline_interpolation() including helper tools to estimate tangents and end tangent magnitudes. A new local_bspline_interpolation() function and a fast cubic_bezier_interpolation() function also exist.

A faster linear equation solver for interpolation tasks was required: the new LUDecomposition() is faster than the previous gauss_*_solver() functions and a new banded diagonal matrix solver BandedMatrixLU() for even faster results for bigger matrices was added, compact_banded_matrix() is a helper function to create banded diagonal matrices and detect_banded_matrix() is its sidekick to auto-detect the required parameters.

Integrated derivative computation into BSpline() and Bezier() from special derivative classes. Instead of overriding the point() method, a new derivative() method exists which returns the curve point and derivatives.

Most of this new math tools are based on two books:

  1. B-Splines: "The NURBS Book" by Piegl and Tiller
  2. Linear Equation Solver: "Numerical Receipes" by Press, Teukolsky, Vetterling and Flannery

Change Log

Version 0.13.1 - 2020-07-18

Version 0.13 - 2020-07-04