Jogging Song
Jogging Song

Reputation: 573

number of control points for B spline curve

I am trying to use B spline curve fitting. The order of B spline curve is 4. When I have many control points, it works well. However if the number of control points is small such as two, my program will crash. I realize that the number of control points is related to number of knots and the order. Can anyone help me clarify the relationship or give some links on it?

Upvotes: 3

Views: 11786

Answers (3)

Mario
Mario

Reputation: 36537

Sounds like you're simply reading out of bounds, which is not a specific issue of calculating splines. To calculate a b-spline of degree n, you'll need at least n + 1 points.

To simplify and show the issue:

  • The easiest way of interpolation is linear interpolation - just draw a line between two points.

  • If you've got only one point, you can't interpolate anything, simply due to the fact that you don't know where to draw.

  • For a quadratic interpolation, you'll need at least three points, etc.

  • In a similar way, you'll need at least 5 points for a b-spline of 4th degree.

A really nice online demo can be found here:

Example screenshot of NURBSdemo.swf

  • Pick any b-spline demo on the lower left side, I'd just go for the linear one.
  • On the right you're now able to set the number of control points as well as the degree of the curve.
  • Feel free to try around, also by moving the points around with your mouse.

Upvotes: 4

Foivos
Foivos

Reputation: 545

As others stated, the number of control points is equal to the number of knots minus the order of the bspline basis. Thus you cannot have an arbitrary combination of order, say k, and knot vector for your bspline function/curve once you fix the control points.

A very useful link for theory on b-splines and nurbs curves is the following: http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/index.html

There you can find the relationship of number of control points with dimensionality of knot vector etc as well as detailed examples and some algorithms.

Depending on your needs, you may also wish to check "The NURBS book" by Piegl and Tiller http://www.amazon.com/NURBS-Book-Monographs-Visual-Communication/dp/3540615458

they have done an amazing job and in their book they include working algorithms.

The curve fitting problem of a b-spline to data is a rather large subject since you have to take care to avoid over/under fitting. There are several approaches, and most involve including a curvature penalty term. The literature is vast, but you can find a lot of information and a great starting point in the book by Hastie et. al. "The elements of statistical learning" which you can legally download from the authors site: http://statweb.stanford.edu/~tibs/ElemStatLearn/

The curve fitting problem is covered to some extent in all references I gave. Good luck.

Upvotes: 2

fang
fang

Reputation: 3633

Two control points is not sufficient to define a B-spline of order 4. For B-splines, the number of knots needs to equal the sum of number of control points and order. A single segment degree 3 B-spline will require 4 control points and 8 knot values. So, to calculate a B-spline with order N, you at least need N points. That will give you a B-spline with single segment. If you have more points, then the resulting B-spline will have more segments.

Upvotes: 3

Related Questions