def approximate(self, 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 an :class:`~ezdxf.math.UCS`, to transformed the curve into :ref:`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. Args: segments: count of line segments for approximation, vertex count is `segments` + 1 ucs: :class:`~ezdxf.math.UCS` definition, control points in ucs coordinates. Returns: list of vertices in :class:`~ezdxf.math.OCS` as :class:`~ezdxf.math.Vec3` objects """ if self.closed: spline = BSplineClosed(self.control_points, order=self.degree + 1) else: spline = BSpline(self.control_points, order=self.degree + 1) vertices = spline.approximate(segments) if ucs is not None: vertices = (ucs.to_ocs(vertex) for vertex in vertices) return list(vertices)
def approximate(self, segments: int = 40, ucs: 'UCS' = None) -> List['Vertex']: if self.closed: spline = BSplineClosed(self.control_points, order=self.degree + 1) else: spline = BSpline(self.control_points, order=self.degree + 1) vertices = spline.approximate(segments) if ucs is not None: vertices = (ucs.to_ocs(vertex) for vertex in vertices) return list(vertices)
def render_closed_bspline(self, layout: 'BaseLayout', degree: int = 3, dxfattribs: dict = None) -> None: """ Render a closed uniform BSpline as 3D :class:`~ezdxf.entities.Polyline`. Definition points are control points. Args: layout: :class:`~ezdxf.layouts.BaseLayout` object degree: degree of B-spline (order = `degree` + 1) dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline` """ spline = BSplineClosed(self.points, order=degree + 1) layout.add_polyline3d(list(spline.approximate(self.segments)), dxfattribs=dxfattribs)
def render_closed_bspline(self, layout: 'GenericLayoutType', degree: int = 3, dxfattribs: dict = None) -> None: """ Render a closed uniform BSpline as 3d polyline. Definition points are control points. Args: layout: ezdxf layout degree: B-spline degree (order = degree + 1) dxfattribs: DXF attributes for POLYLINE """ spline = BSplineClosed(self.points, order=degree + 1) layout.add_polyline3d(list(spline.approximate(self.segments)), dxfattribs=dxfattribs)
def render_closed_rbspline(self, layout: 'GenericLayoutType', weights: Iterable[float], degree: int = 3, dxfattribs: dict = None) -> None: """ Render a rational BSpline as 3d polyline. Args: layout: ezdxf layout weights: list of weights, requires a weight value for each defpoint. degree: B-spline degree (order = degree + 1) dxfattribs: DXF attributes for POLYLINE """ spline = BSplineClosed(self.points, order=degree + 1, weights=weights) layout.add_polyline3d(list(spline.approximate(self.segments)), dxfattribs=dxfattribs)
def render_closed_rbspline(self, layout: 'BaseLayout', weights: Iterable[float], degree: int = 3, dxfattribs: dict = None) -> None: """ Render a rational BSpline as 3D :class:`~ezdxf.entities.Polyline`. Definition points are control points. Args: layout: :class:`~ezdxf.layouts.BaseLayout` object weights: list of weights, requires a weight value (float) for each definition point. degree: degree of B-spline (order = `degree` + 1) dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline` """ spline = BSplineClosed(self.points, order=degree + 1, weights=weights) layout.add_polyline3d(list(spline.approximate(self.segments)), dxfattribs=dxfattribs)