b-spline evaluation near t=1

Please don't post Bullet support questions here, use the above forums instead.
mewert
Posts: 52
Joined: Sat Oct 08, 2005 1:16 am
Location: Itinerant

b-spline evaluation near t=1

Post by mewert »

When I evaluate a non-periodic b-spline near the end t ~= 1 the basis functions return 0.

for a b-spline of degree 2. Knot vector k = [0,0,0,0.33, 0.66, 1, 1, 1] with 4 non-zero control points P0,...P3.

Using the recursive formulation:
f(t) = P0*N0,2(t) + P1*N1,2(t) +... P3*N3,2(t)

Ni,0(t) = 1 if k <= t < k[i+1] and k < k[i+1]
= 0 otherwise

Ni,p(t) = (t - k)/(k[i+p] - k)*Ni,p-1(t) + (k[i+p+1] - t)/(k[i+p+1] - k[i+1])*Ni+1,p-1

Now I know that at t = 1 I'm at the end of my spline and I should see that N3,2(1) = 1

But when I plug in the values I get N3,2(1) = 0

Let's look at N3,2(1):

First we can see that Ni,0(1) is non-zero only for i = 4 since 0.66 <= 1.0 < 1.0 and even then I'm fudging that < into a <= since it's the end of the spline, so I'm treating it specially. So N4,0(1) = 1 the rest are 0

N3,2(1) = C1*N3,1(1) + C2*N4,1(1)

C1 = (1-0.33)/(1.0-0.33) = 1.0
C2 = (1-1)/(1-0.66) = 0
so,
N3,2(1) = N3,1(1)

N3,1(1) = D1*N3,0(1) + D2*N4,0(1) = D1*0 + D2*1 = D2
D2 = (k[5] - 1)/(k[5]-k[4]) = (1-1)/(1-0.66) = 0

ack. The numerator goes to zero so the whole thing does.

What am I doing wrong? I'm following the formula mostely:

http://mathworld.wolfram.com/B-Spline.html

I know this is not a very efficient way to evaluate a b-spline, so no "why aren't you doing it this way..." answers please.

Alternately, if anyone has the b-spline code I already wrote about 4 years ago you can just send that to me :)

- Michael Alexander Ewert
Nathanael
Posts: 78
Joined: Mon Nov 13, 2006 1:44 am

Re: b-spline evaluation near t=1

Post by Nathanael »

I think your basis functions should be of degree 3 ('num knots'-'num cp'-1), if the curve you expect is a "classic" Bezier like, your knots vector should be {0,0,0,0,1,1,1,1}, be careful to handle divide by zero == 0.
If you look for a library, the best that i know of is http://libnurbs.sourceforge.net/, it target NURBS, but most algorithms are the same for non rational bsplines (just set w==1), including how to generate standard knots vectors.
mewert wrote:I know this is not a very efficient way to evaluate a b-spline, so no "why aren't you doing it this way..." answers please.
:wink: (non uniform) b-splines are a pain, you have to carry that knots vector all along, for results that can be obtained with pieces of Bezier, or go for full blown NURBS if you need exact conic sections representation.

Hope it help,
Nathanael.