How to get new temporary control points in deboors algorithm

146 Views Asked by At

I am trying to implement deboor's algorithm in c++ to make a b spline. I'm trying to follow the Wikipedia page of it (https://en.wikipedia.org/wiki/De_Boor%27s_algorithm). Here is the implementation they provide:

dj = c(j + k -p) for j = 0 …. p.

Iterate for r = 1, …, p:

dj = (1 - alphaj)d(j-1) + alphaj*dj

j = p, …., r

alpha = (x - t(j + k - p))/(t(j+1+k-r) - t(j+k-p))

When I tried to code this, I get a indexing error. If my b spline is quadratic I believe my p should be 2. Suppose I had 4 control points and 7 knots. If I am trying to evaluate a knot position of 4, then for the first line: p = 2, k = 4, and j = 0 to 2. At one point dj will try to access the control point at place 2 + 4 - 2 = 4 but there are only four control points. Maybe it is a zero indexing issue, but even then if I try to access a knot position of 5 it will still go out of bounds. Is there something I'm misunderstanding?

1

There are 1 best solutions below

0
On

There is code for de Boor's algorithm in "The NURBS Book" by Tiller and Piegl. You can probably find it in other places, too. I don't know what's wrong with your code.