Class: QgsNurbsCurve¶
Represents a NURBS (Non-Uniform Rational B-Spline) curve geometry in 2D/3D.
NURBS curves are a mathematical model commonly used in computer graphics for representing curves. They are parametric curves defined by control points, weights, knot vectors, and a degree.
Added in version 4.0.
List of all members, including inherited members
Class Hierarchy¶
Base classes¶
Abstract base class for curved geometry type. |
|
Abstract base class for all geometries. |
Methods
Returns the control points of the NURBS curve. |
|
Returns the degree of the NURBS curve. |
|
Evaluates the NURBS curve at parameter t ∈ [0,1]. |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns the knot vector of the NURBS curve. |
|
Sets the control points of the NURBS curve. |
|
Sets the degree of the NURBS curve. |
|
Sets the knot vector of the NURBS curve. |
|
Sets the weight at the specified control point index. |
|
Sets the weight vector of the NURBS curve. |
|
Returns the weight at the specified control point index. |
|
Returns the weight vector of the NURBS curve. |
Static Methods
Generates a knot vector for converting piecewise Bézier curves to NURBS. |
|
Generates a uniform clamped knot vector for a NURBS curve. |
- class qgis.core.QgsNurbsCurve[source]¶
Bases:
QgsCurve- __init__()
Constructor for an empty NURBS curve geometry.
- __init__(controlPoints: Iterable[QgsPoint], degree: int, knots: Iterable[float], weights: Iterable[float])
Constructs a NURBS curve from control points, degree, knot vector and weights.
- Parameters:
controlPoints (Iterable[QgsPoint]) – control points defining the curve. The number of control points must be strictly greater than
degreedegree (int) – degree of the NURBS curve (must be >= 1, typically 1-3)
knots (Iterable[float]) – knot vector (must have size = control points count + degree + 1, values must be non-decreasing)
weights (Iterable[float]) – weight vector for rational curves (same size as control points)
- __init__(a0: QgsNurbsCurve)
- Parameters:
a0 (QgsNurbsCurve)
- controlPoints(self) list[QgsPoint]¶
Returns the control points of the NURBS curve.
- Return type:
list[QgsPoint]
- evaluate(self, t: float) QgsPoint[source]¶
Evaluates the NURBS curve at parameter t ∈ [0,1]. Uses the Cox-de Boor algorithm for B-spline basis function evaluation.
- Parameters:
t (float) – parameter value between 0 and 1
- Return type:
- Returns:
point on the curve at parameter t
- Raises:
ValueError – if t is not in range [0, 1]
- static generateKnotsForBezierConversion(nAnchors: int, degree: int = 3) list[float]¶
Generates a knot vector for converting piecewise Bézier curves to NURBS.
Creates a knot vector with multiplicity ‘degree’ at junctions for C0 continuity. Format: [0 repeated (degree+1), 1 repeated degree, …, s repeated (degree+1)] where s = nAnchors - 1 (number of segments)
- Parameters:
nAnchors (int) – number of anchor points (must be >= 2)
degree (int = 3) – degree of the curve (must be >= 1), defaults to 3 (cubic)
- Return type:
list[float]
- Returns:
the generated knot vector, or empty if invalid parameters
Added in version 4.0.
- static generateUniformKnots(numControlPoints: int, degree: int) list[float]¶
Generates a uniform clamped knot vector for a NURBS curve.
The generated knot vector has size = numControlPoints + degree + 1, with:
The first (degree + 1) knots are set to 0.0 (indices 0 to degree).
The last (degree + 1) knots are set to 1.0 (indices numControlPoints to numControlPoints + degree).
Interior knots uniformly spaced
- Parameters:
numControlPoints (int) – number of control points
degree (int) – degree of the NURBS curve (must be >= 1)
- Return type:
list[float]
- Returns:
the generated knot vector
Added in version 4.0.
- isAnchorVertex(self, localIndex: int) bool[source]¶
Returns
Trueif the control point at localIndex is an anchor vertex in a poly-Bézier curve. Anchor vertices are at positions 0, degree, 2*degree, etc.- Parameters:
localIndex (int) – the control point index to check
- Return type:
bool
- Returns:
Trueif this is an anchor vertex,Falseotherwise
Added in version 4.0.
- isBSpline(self) bool[source]¶
Returns
Trueif this curve represents a B-spline (non-rational NURBS).- Return type:
bool
- isBezier(self) bool[source]¶
Returns
Trueif this curve represents a Bézier curve. A Bézier curve is a special case of NURBS with uniform weights and specific knot vector.- Return type:
bool
- isPolyBezier(self) bool[source]¶
Returns
Trueif this curve represents a poly-Bézier curve structure.A poly-Bézier is a piecewise Bézier curve with C0 continuity (positional continuity only) used for editing. It requires:
Control points: (controlPointCount - 1) % degree == 0
Knot vector with multiplicity ‘degree’ at internal junctions
Can have 1 or more segments (like MultiPolygon can have 1+ polygons)
Works for any degree ≥ 1. Note that a single-segment poly-Bézier will also return
TrueforisBezier()(degree = n-1 condition).- Return type:
bool
- isRational(self) bool[source]¶
Returns
Trueif this curve is rational (has non-uniform weights).- Return type:
bool
- knots(self) list[float]¶
Returns the knot vector of the NURBS curve.
- Return type:
list[float]
- setControlPoints(self, points: Iterable[QgsPoint])[source]¶
Sets the control points of the NURBS curve.
- Parameters:
points (Iterable[QgsPoint]) – control points
- setDegree(self, degree: int)[source]¶
Sets the degree of the NURBS curve.
- Parameters:
degree (int) – curve degree (typically 1-3)
- setKnots(self, knots: Iterable[float])[source]¶
Sets the knot vector of the NURBS curve.
- Parameters:
knots (Iterable[float]) – knot vector (must have size = control points count + degree + 1, values must be non-decreasing)
- setWeight(self, index: int, weight: float)[source]¶
Sets the
weightat the specified control pointindex. Weight must be positive (> 0).- Raises:
IndexError – if no control point with the specified index exists.
ValueError – if weight is not positive.
Added in version 4.0.
- Parameters:
index (int)
weight (float)
- setWeights(self, weights: Iterable[float])[source]¶
Sets the weight vector of the NURBS curve.
- Parameters:
weights (Iterable[float]) – weight vector (same size as control points)
- weight(self, index: int) float[source]¶
Returns the weight at the specified control point
index.- Raises:
IndexError – if no control point with the specified index exists.
Added in version 4.0.
- Parameters:
index (int)
- Return type:
float
- weights(self) list[float]¶
Returns the weight vector of the NURBS curve.
- Return type:
list[float]