SketchNurbs#

class ansys.geometry.core.sketch.nurbs.SketchNurbs#

Bases: ansys.geometry.core.sketch.edge.SketchEdge

Represents a NURBS sketch curve.

Warning

NURBS sketching is only supported in 26R1 and later versions of Ansys.

Notes

This class is a wrapper around the NURBS curve class from the geomdl library. By leveraging the geomdl library, this class provides a high-level interface to create and manipulate NURBS curves. The geomdl library is a powerful library for working with NURBS curves and surfaces. For more information, see https://pypi.org/project/geomdl/.

Overview#

fit_curve_from_points

Fit a NURBS curve to a set of points.

from_control_points

Create a NURBS curve from control points.

from_json_file

Create NURBS sketch curve(s) from a JSON file or JSON string.

to_json_file

Serialize one or more NURBS sketch curves to a JSON file.

partial_ellipse

Create an exact rational NURBS for a partial ellipse arc.

contains_point

Check if the curve contains a given point within a specified tolerance.

geomdl_nurbs_curve

Get the underlying NURBS curve.

control_points

Get the control points of the curve.

degree

Get the degree of the curve.

knots

Get the knot vector of the curve.

weights

Get the weights of the control points.

start

Get the start point of the curve.

end

Get the end point of the curve.

visualization_polydata

Get the VTK polydata representation for PyVista visualization.

Import detail#

from ansys.geometry.core.sketch.nurbs import SketchNurbs

Property detail#

property SketchNurbs.geomdl_nurbs_curve: geomdl.NURBS.Curve#

Get the underlying NURBS curve.

Notes

This property gives access to the full functionality of the NURBS curve coming from the geomdl library. Use with caution.

property SketchNurbs.control_points: list[ansys.geometry.core.math.point.Point2D]#

Get the control points of the curve.

property SketchNurbs.degree: int#

Get the degree of the curve.

property SketchNurbs.knots: list[ansys.geometry.core.typing.Real]#

Get the knot vector of the curve.

property SketchNurbs.weights: list[ansys.geometry.core.typing.Real]#

Get the weights of the control points.

property SketchNurbs.start: ansys.geometry.core.math.point.Point2D#

Get the start point of the curve.

property SketchNurbs.end: ansys.geometry.core.math.point.Point2D#

Get the end point of the curve.

property SketchNurbs.visualization_polydata: pyvista.PolyData#

Get the VTK polydata representation for PyVista visualization.

Returns:
pyvista.PolyData

VTK pyvista.Polydata configuration.

Notes

The representation lies in the X/Y plane within the standard global Cartesian coordinate system.

Method detail#

SketchNurbs.contains_point(point: ansys.geometry.core.math.point.Point2D, tol: float = 1e-06) bool#

Check if the curve contains a given point within a specified tolerance.

Parameters:
pointPoint2D

The point to check.

tolfloat, optional

The tolerance for the containment check, by default 1e-6.

Returns:
bool

True if the curve contains the point within the tolerance, False otherwise.

classmethod SketchNurbs.fit_curve_from_points(points: list[ansys.geometry.core.math.point.Point2D], degree: int = 3) SketchNurbs#

Fit a NURBS curve to a set of points.

Parameters:
pointslist[Point2D]

The points to fit the curve to.

degreeint, optional

The degree of the NURBS curve, by default 3.

Returns:
SketchNurbs

A new instance of SketchNurbs fitted to the given points.

classmethod SketchNurbs.from_control_points(control_points: list[ansys.geometry.core.math.point.Point2D], degree: int, knots: list[ansys.geometry.core.typing.Real], weights: list[ansys.geometry.core.typing.Real] | None = None) SketchNurbs#

Create a NURBS curve from control points.

Parameters:
control_pointslist[Point2D]

Control points of the curve.

degreeint

Degree of the curve.

knotslist[Real]

Knot vector of the curve.

weightslist[Real], optional

Weights of the control points.

Returns:
SketchNurbs

NURBS curve.

classmethod SketchNurbs.from_json_file(source: str | pathlib.Path, elements: list[str] | None = None) SketchNurbs | dict[str, SketchNurbs]#

Create NURBS sketch curve(s) from a JSON file or JSON string.

Parameters:
sourceUnion[str, Path]

JSON file path, or a raw JSON string.

elementslist[str], optional

Names of the elements to build. If omitted, every element found in the JSON is built.

Returns:
Union[SketchNurbs, dict[str, SketchNurbs]]

A single SketchNurbs if one element is requested, or a dictionary of SketchNurbs keyed by element name if multiple elements are requested.

Raises:
ValueError

If any requested element is missing from the JSON data.

classmethod SketchNurbs.to_json_file(curves: dict[str, SketchNurbs], path: str | pathlib.Path) pathlib.Path#

Serialize one or more NURBS sketch curves to a JSON file.

Parameters:
curvesdict[str, SketchNurbs]

Mapping of element name to the SketchNurbs to serialize under that name, e.g. {“hub_0”: curve_1, “hub_1”: curve_2}.

pathUnion[str, Path]

File path to write the JSON to. Required.

Raises:
ValueError

If path is not provided, or curves is empty.

classmethod SketchNurbs.partial_ellipse(center: ansys.geometry.core.math.point.Point2D, major_radius: pint.Quantity | ansys.geometry.core.misc.measurements.Distance | ansys.geometry.core.typing.Real, minor_radius: pint.Quantity | ansys.geometry.core.misc.measurements.Distance | ansys.geometry.core.typing.Real, start_angle: pint.Quantity | ansys.geometry.core.misc.measurements.Angle | ansys.geometry.core.typing.Real, end_angle: pint.Quantity | ansys.geometry.core.misc.measurements.Angle | ansys.geometry.core.typing.Real, angle: pint.Quantity | ansys.geometry.core.misc.measurements.Angle | ansys.geometry.core.typing.Real = 0) SketchNurbs#

Create an exact rational NURBS for a partial ellipse arc.

Parameters:
centerPoint2D

Center of the ellipse.

major_radiusQuantity | Distance | Real

Semi-major axis length (x-direction before rotation).

minor_radiusQuantity | Distance | Real

Semi-minor axis length (y-direction before rotation).

start_angleQuantity | Angle | Real

Parametric start angle. Defaults to radians when given as a Real.

end_angleQuantity | Angle | Real

Parametric end angle. Defaults to radians when given as a Real. The arc sweeps counter-clockwise when end_angle > start_angle.

angleQuantity | Angle | Real, default: 0

Rotation of the ellipse about its center (radians when Real).

Returns:
SketchNurbs

Exact rational quadratic NURBS (degree 2) for the requested arc. The arc is split into segments of at most 90° for numerical stability.

Raises:
ValueError

If either radius is non-positive.

ValueError

If start_angle equals end_angle (zero-length arc).