pythoncurve-fittingbsplinenurbsbasis

How to find knot vector if control points are known for a NURBS curve?


I have a set of control points

pts = [[849, 1181],
       [916, 1257],
       [993, 1305],
       [1082,1270], 
       [1137,1181],
       [1118,1055], 
       [993,1034], 
       [873,1061], 
       [849, 1181]]

I have the logic for generating an open knot vector:

/*
Subroutine to generate a B-spline open knot vector with multiplicity
equal to the order at the ends.

c            = order of the basis function
n            = the number of defining polygon vertices
nplus2       = index of x() for the first occurence of the maximum knot       vector value
nplusc       = maximum value of the knot vector -- $n + c$
x()          = array containing the knot vector
*/

knot(n,c,x)

int n,c;
int x[];

{
    int nplusc,nplus2,i;
nplusc = n + c;
nplus2 = n + 2;

x[1] = 0;
    for (i = 2; i <= nplusc; i++){
        if ( (i > c) && (i < nplus2) )
            x[i] = x[i-1] + 1;
    else
            x[i] = x[i-1];


    }
}

And another one for generating periodic knot vector:

/*  Subroutine to generate a B-spline uniform (periodic) knot vector.

c            = order of the basis function
n            = the number of defining polygon vertices
nplus2       = index of x() for the first occurence of the maximum knot vector value
nplusc       = maximum value of the knot vector -- $n + c$
x[]          = array containing the knot vector
*/

#include    <stdio.h>

knotu(n,c,x)

int n,c;
int x[];

{
    int nplusc,nplus2,i;

nplusc = n + c;
nplus2 = n + 2;

x[1] = 0;
for (i = 2; i <= nplusc; i++){
    x[i] = i-1;
}
}

I however need to generate a non-uniform knot vector in the range of [0,1]

The above algorithms result in uniform knot vectors.

Kindly suggest if there is any way to do this. It would be preferable if the code is in python


Solution

  • Knot vector (uniform or not) is part of the definition of a NURBS curve. So, you can actually define your own non-uniform knot vector as long as the knot vector follows the basic rules:

    1) # of knot values = # of control points + order

    2) All knot values must be non-decreasing. Namely, k[i] <= k[i+1].

    For your example with 9 control points, you can have non-uniform knot vector like [0, 0, 0, 0, a, b, c, d, e, 1, 1, 1, 1], where 0.0 < a <= b <= c <=d <=e < 1.0 for a degree 3 B-spline curve. Of course, choosing different values for a, b, c, d and e will result in curves with different shape.