def random_point_comparision_to_nurbs_python(spline: BSpline, count: int = 10): curve = spline.to_nurbs_python_curve() for _ in range(count): t = random.random() p1 = spline.point(t) p2 = curve.evaluate_single(t) assert p1.isclose(p2)
def random_derivatives_comparision_to_nurbs_python(spline: BSpline, count: int = 10): curve = spline.to_nurbs_python_curve() for _ in range(count): t = random.random() p1, d1_1, d2_1 = spline.derivative(t, n=2) p2, d1_2, d2_2 = curve.derivatives(t, order=2) assert p1.isclose(p2) assert d1_1.isclose(d1_2) assert d2_1.isclose(d2_2)
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)))