Beispiel #1
0
def spline_insert_knot():
    doc = ezdxf.new("R2000", setup=True)
    msp = doc.modelspace()

    def add_spline(control_points, color=3, knots=None):
        msp.add_polyline2d(control_points,
                           dxfattribs={
                               "color": color,
                               "linetype": "DASHED"
                           })
        msp.add_open_spline(control_points,
                            degree=3,
                            knots=knots,
                            dxfattribs={"color": color})

    control_points = Vec3.list([
        (0, 0),
        (10, 20),
        (30, 10),
        (40, 10),
        (50, 0),
        (60, 20),
        (70, 50),
        (80, 70),
    ])
    add_spline(control_points, color=3, knots=None)

    bspline = BSpline(control_points, order=4)
    bspline.insert_knot(bspline.max_t / 2)
    add_spline(bspline.control_points, color=4, knots=bspline.knots())

    doc.saveas("Spline_R2000_spline_insert_knot.dxf")
Beispiel #2
0
def test_normalize_knots_if_needed():
    s = BSpline(
        control_points=DEFPOINTS,
        knots=[2, 2, 2, 2, 3, 6, 6, 6, 6],
        order=4,
    )
    k = s.knots()
    assert k[0] == 0.0
Beispiel #3
0
from typing import cast
from pathlib import Path
import ezdxf
from ezdxf.math import Vector, BSpline

DIR = Path('~/Desktop/Outbox').expanduser()

doc = ezdxf.readfile('../../examples/addons/drawing/test_files/hatches_2.dxf')
msp = doc.modelspace()

hatch = cast('Hatch', msp.query('HATCH').first)
if hatch:
    for edge in hatch.paths[0].edges:
        if edge.EDGE_TYPE == 'SplineEdge':
            s = BSpline(control_points=edge.control_points,
                        knots=edge.knot_values,
                        order=edge.degree + 1)
            print(s.knots())
            c = s.to_nurbs_python_curve()
            print(c.knotvector)
            print(s)
            print(list(s.approximate(10)))