# B-spline problem

This topic is 3824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hallo, I have been trying to implement Uniform quadratic B-splines into a project I am working on, but I have some problems. I dont fully understand the formula for it. Here is the formula: http://upload.wikimedia.org/math/a/6/5/a656ebac5f7c1d5dd683d191a8e5eb88.png If I have a list of control points, how do I know where to use which one? I thought that at t = 0 you are at controlPoint_0 and at t = 1 you are at controlPoint_n, but as t is the only changing factor( Si(t) =...) I cant see how all points are being used. Here is my code so far, if anyone is interested
  var steps = 20;

for (var j = 0; j < steps; j++)
{
var t = j / steps;

var i = 1;  //

var half = 0.5;

var b0 = [ ((t * t) * half), (t * half), (1 * half) ];

var b1 = [ ( (b0[0] * 1)  + (b0[1] * -2) + (b0[2] * 1) ),
( (b0[0] * -2) + (b0[1] * 2)  + (b0[2] * 1) ),
( (b0[0] * 1)  + (b0[1] * 0)  + (b0[2] * 0) )  ];

var b2 = [ ( (b1[0] * list[i-1].locH) + (b1[1] * list.locH) + (b1[2] * list[i+1].locH) ),
( (b1[0] * list[i-1].locv) + (b1[1] * list.locv) + (b1[2] * list[i+1].locv) )  ]

var xPos = b2[0];
var yPos = b2[1];
}


Also, it it correct that if I have a curve with 3 points, the curves does not start at p0 or end at p2 (when you draw it)? Its floating in the middle? Could anyone give me a helping hand here?

##### Share on other sites
Every section of a B-spline use d+1 control points (where d is the degree). So suppose you have n points. The first section use the points from P0 to Pd, the second from P1 to Pd+1 and so on. The last section from Pn-d to Pn.
The curve doesn’t pass from the first and last control points. It’s the correct behavior of a uniform B-spline.

##### Share on other sites

Is there anyway of making the curve start at p0 and end at pn? I tried using p0 twice for the start point, but then I dont get a equal spacing of points along the curve.

##### Share on other sites
The equal spacing isn’t between points but between knots.

A general B-spline is defined by a sequence of non decreasing real numbers {u0, u1 ... um} called knot vector and a sequence of control points {P0, P1 ... Pn}. The degree of the B-spline is d = m - n - 1. A B-spline is defined in the interval [ud, um-d].

The knot vector of a uniform B-spline have the following property: ui+1 = ui + Δ, where Δ is a constant. Usually u0 = 0 and Δ = 1. So the knot vector becomes the sequence of the first m+1 natural numbers {0, 1, ... m}.

If you want the curve to start at P0 and end at Pn you have to use a non-uniform B-spline. In particular the curve start at P0 if u0 = u1 = ... = ud and end at Pn if um-d = um-d+1 = ... = um. But the definition of the B-spline basis functions becomes more complicated. They aren’t anymore the same curve translated. To robustly evaluate a B-spline the de Boor algorithm can be used.

##### Share on other sites
Thanks a lot :)

One last question, is it possible to create a function out of the b spline curve in the form f(u)? I would like to have something follow the curve.

##### Share on other sites
A B-spline is a function of the type f(u) where u is between the values I have written earlier.

##### Share on other sites
Im sorry, but I dont understand how to to this.

Could anyone take a look at my code and give me a hint, or maybe give me a link with an example or explanation?

  // Conrol points (x,y)  var list =  Array( cp0,cp1,cp2, cp3,cp4,cp5,cp6,cp7,cp0,cp1 );     var steps = 30;    for(var i = 1; i < (list.length - 1); i++)  {    for (var j = 0; j < steps; j++)    {       var t = j / steps;         var half = 0.5;       var half_t = t * half;           var b0 = [ (t * half_t), (half_t), ( half) ];                         var b1 = [ ( (b0[0])      + (b0[1] * -2) + (b0[2]) ),                  ( (b0[0] * -2) + (b0[1] * 2)  + (b0[2]) ),                  ( (               b0[0]               ) )  ];                           var xPos = (b1[0] * list[i-1].locH) + (b1[1] * list.locH) + (b1[2] * list[i+1].locH)       var yPos = (b1[0] * list[i-1].locv) + (b1[1] * list.locv) + (b1[2] * list[i+1].locv)        // Draw the sprites    }  }

##### Share on other sites
Your formula looks correct. I don’t understand what’s the problem. What do you want to obtain?

As I have previously said you can also use the de Boor algorithm. The following is a code that use it to find a point on a section of a uniform quadratic B-spline (not tested):
var a11 = 0.5*(t + 1.0);var a12 = 0.5*t;var a22 = t;var b11 = (1.0 - a11)*list[i-1] + a11*list;var b12 = (1.0 - a12)*list + a12*list[i+1];var b22 = (1.0 - a22)*b11 + a22*b12;

The formula you have used is correct, so you should obtain the same result.

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 9
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633717
• Total Posts
3013513
×