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

Inheritance diagram of qgis.core.QgsNurbsCurve

Base classes

QgsCurve

Abstract base class for curved geometry type.

QgsAbstractGeometry

Abstract base class for all geometries.

Methods

controlPoints

Returns the control points of the NURBS curve.

degree

Returns the degree of the NURBS curve.

evaluate

Evaluates the NURBS curve at parameter t ∈ [0,1].

isAnchorVertex

Returns True if the control point at localIndex is an anchor vertex in a poly-Bézier curve.

isBSpline

Returns True if this curve represents a B-spline (non-rational NURBS).

isBezier

Returns True if this curve represents a Bézier curve.

isPolyBezier

Returns True if this curve represents a poly-Bézier curve structure.

isRational

Returns True if this curve is rational (has non-uniform weights).

knots

Returns the knot vector of the NURBS curve.

setControlPoints

Sets the control points of the NURBS curve.

setDegree

Sets the degree of the NURBS curve.

setKnots

Sets the knot vector of the NURBS curve.

setWeight

Sets the weight at the specified control point index.

setWeights

Sets the weight vector of the NURBS curve.

weight

Returns the weight at the specified control point index.

weights

Returns the weight vector of the NURBS curve.

Static Methods

generateKnotsForBezierConversion

Generates a knot vector for converting piecewise Bézier curves to NURBS.

generateUniformKnots

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 degree

  • degree (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]

degree(self) int[source]

Returns the degree of the NURBS curve.

Return type:

int

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:

QgsPoint

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 True if 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:

True if this is an anchor vertex, False otherwise

Added in version 4.0.

isBSpline(self) bool[source]

Returns True if this curve represents a B-spline (non-rational NURBS).

Return type:

bool

isBezier(self) bool[source]

Returns True if 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 True if 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 True for isBezier() (degree = n-1 condition).

Return type:

bool

isRational(self) bool[source]

Returns True if 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 weight at the specified control point index. 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]