NURBSCurve#

class ansys.geometry.core.shapes.curves.nurbs.NURBSCurve(geomdl_object: geomdl.NURBS.Curve = None)#

Bases: ansys.geometry.core.shapes.curves.curve.Curve

Represents a NURBS curve.

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#

contains_param

Check a parameter is within the parametric range of the curve.

contains_point

Check a point is contained by the curve.

from_control_points

Create a NURBS curve from control points.

fit_curve_from_points

Fit a NURBS curve to a set of points.

from_json_file

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

to_json_file

Serialize one or more NURBS curves to a JSON file.

length

Calculate the length of the NURBS curve.

parameterization

Get the parametrization of the NURBS curve.

transformed_copy

Create a transformed copy of the curve.

evaluate

Evaluate the curve at the given parameter.

project_point

Project a point to the NURBS curve.

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.

visualization_polydata

VTK polydata representation for PyVista visualization.

__eq__

Determine if two curves are equal.

Import detail#

from ansys.geometry.core.shapes.curves.nurbs import NURBSCurve

Property detail#

property NURBSCurve.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 NURBSCurve.control_points: list[ansys.geometry.core.math.Point3D]#

Get the control points of the curve.

property NURBSCurve.degree: int#

Get the degree of the curve.

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

Get the knot vector of the curve.

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

Get the weights of the control points.

property NURBSCurve.visualization_polydata: pyvista.PolyData#

VTK polydata representation for PyVista visualization.

Returns:
pyvista.PolyData

VTK pyvista.PolyData configuration.

Method detail#

NURBSCurve.length(num_points: int = None) ansys.geometry.core.typing.Real#

Calculate the length of the NURBS curve.

Parameters:
num_pointsint, default: None

Number of points to sample along the curve for length calculation.

Returns:
Real

Length of the NURBS curve.

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

Create a NURBS curve from control points.

Parameters:
control_pointslist[Point3D]

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:
NURBSCurve

NURBS curve.

classmethod NURBSCurve.fit_curve_from_points(points: list[ansys.geometry.core.math.Point3D], degree: int) NURBSCurve#

Fit a NURBS curve to a set of points.

Parameters:
pointslist[Point3D]

Points to fit the curve to.

degreeint

Degree of the curve.

Returns:
NURBSCurve

Fitted NURBS curve.

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

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

Parameters:
sourceUnion[str, Path]

JSON file path, or a raw JSON string. Each curve must be wrapped under a named element, e.g. {“rail_1”: {…}}.

elementslist[str], optional

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

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

A single NURBSCurve if only one element was built (either because the file has one, or elements requested one). Otherwise, a dict mapping each name to its NURBSCurve.

Raises:
ValueError

If any name in elements is not found in the JSON payload, or if an element’s data looks like it belongs to a different NURBS entity type (e.g. a surface or a sketch curve).

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

Serialize one or more NURBS curves to a JSON file.

Parameters:
curvesdict[str, NURBSCurve]

Mapping of element name to the NURBSCurve to serialize under that name, e.g. {“rail_1”: curve_1, “rail_2”: curve_2}.

pathUnion[str, Path]

File path to write the JSON to. Required.

Raises:
ValueError

If path is not provided, or curves is empty.

NURBSCurve.__eq__(other: NURBSCurve) bool#

Determine if two curves are equal.

NURBSCurve.parameterization() ansys.geometry.core.shapes.parameterization.Parameterization#

Get the parametrization of the NURBS curve.

The parameter is defined in the interval [0, 1] by default. Information is provided about the parameter type and form.

Returns:
Parameterization

Information about how the NURBS curve is parameterized.

NURBSCurve.transformed_copy(matrix: ansys.geometry.core.math.Matrix44) NURBSCurve#

Create a transformed copy of the curve.

Parameters:
matrixMatrix44

Transformation matrix.

Returns:
NURBSCurve

Transformed copy of the curve.

NURBSCurve.evaluate(parameter: ansys.geometry.core.typing.Real) ansys.geometry.core.shapes.curves.curve_evaluation.CurveEvaluation#

Evaluate the curve at the given parameter.

Parameters:
parameterReal

Parameter to evaluate the curve at.

Returns:
CurveEvaluation

Evaluation of the curve at the given parameter.

abstractmethod NURBSCurve.contains_param(param: ansys.geometry.core.typing.Real) bool#

Check a parameter is within the parametric range of the curve.

abstractmethod NURBSCurve.contains_point(point: ansys.geometry.core.math.Point3D) bool#

Check a point is contained by the curve.

The point can either lie within the curve or on its boundary.

NURBSCurve.project_point(point: ansys.geometry.core.math.Point3D, initial_guess: ansys.geometry.core.typing.Real | None = None) ansys.geometry.core.shapes.curves.curve_evaluation.CurveEvaluation#

Project a point to the NURBS curve.

This method returns the evaluation at the closest point.

Parameters:
pointPoint3D

Point to project to the curve.

initial_guessReal, optional

Initial guess for the optimization algorithm. If not provided, the midpoint of the domain is used.

Returns:
CurveEvaluation

Evaluation at the closest point on the curve.

Notes

Based on the NURBS book, the projection of a point to a NURBS curve is the solution to the following optimization problem: minimize the distance between the point and the curve. The distance is defined as the Euclidean distance squared. For more information, please refer to the implementation of the distance_squared function.