コード例 #1
0
def spline_insert_knot():
    dwg = ezdxf.new('R2000')
    ezdxf.setup_linetypes(dwg)
    msp = dwg.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 = Vector.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.knot_values())

    if dwg.validate():
        dwg.saveas("Spline_R2000_spline_insert_knot.dxf")
コード例 #2
0
def test_basis_vector_N_ip():
    degree = 3
    fit_points = Vector.list(POINTS2)  # data points D
    n = len(fit_points) - 1
    t_vector = list(uniform_t_vector(fit_points))
    knots = list(control_frame_knots(n, degree, t_vector))
    should_count = len(fit_points) - 2  # target control point count
    h = should_count - 1
    spline = Basis(knots, order=degree + 1, count=len(fit_points))
    matrix_N = [spline.basis(t) for t in t_vector]

    for k in range(1, n):
        basis_vector = bspline_basis_vector(u=t_vector[k],
                                            count=len(fit_points),
                                            degree=degree,
                                            knots=knots)
        for i in range(1, h):
            assert is_close(matrix_N[k][i], basis_vector[i])
コード例 #3
0
def spline_control_frame_approximation():
    dwg = ezdxf.new('R2000')
    ezdxf.setup_linetypes(dwg)

    fit_points = Vector.list([(0, 0), (10, 20), (30, 10), (40, 10), (50, 0),
                              (60, 20), (70, 50), (80, 70), (65, 75)])
    msp = dwg.modelspace()
    msp.add_polyline2d(fit_points, dxfattribs={'color': 2, 'linetype': 'DOT2'})

    spline = bspline_control_frame_approx(fit_points,
                                          count=7,
                                          degree=3,
                                          method='uniform')
    msp.add_polyline2d(spline.control_points,
                       dxfattribs={
                           'color': 3,
                           'linetype': 'DASHED'
                       })
    msp.add_open_spline(spline.control_points,
                        degree=spline.degree,
                        dxfattribs={'color': 3})
    msp.add_spline(fit_points, degree=3, dxfattribs={'color': 1})
    if dwg.validate():
        dwg.saveas("Spline_R2000_spline_control_frame_approximation.dxf")
コード例 #4
0
ファイル: using_spline_addon.py プロジェクト: soldocode/ezdxf
from ezdxf.algebra import Vector, Matrix44

next_frame = Matrix44.translate(0, 5, 0)
right_frame = Matrix44.translate(10, 0, 0)

NAME = 'spline.dxf'
dwg = ezdxf.new('R2000')
msp = dwg.modelspace()


def draw(points):
    for point in points:
        msp.add_circle(radius=0.1, center=point, dxfattribs={'color': 1})


spline_points = Vector.list([(1., 1.), (2.5, 3.), (4.5, 2.), (6.5, 4.)])

# fit points
draw(spline_points)
Spline(spline_points).render_as_fit_points(
    msp, method='distance',
    dxfattribs={'color': 2})  # curve with definition points as fit points
Spline(spline_points).render_as_fit_points(msp,
                                           method='uniform',
                                           dxfattribs={'color': 3})
Spline(spline_points).render_as_fit_points(msp,
                                           method='centripetal',
                                           dxfattribs={'color':
                                                       4})  # distance ^ 1/2
Spline(spline_points).render_as_fit_points(msp,
                                           method='centripetal',