Curves

Hello guys!!

Does anyone know how to generate curves, like cubic splines…

Any suggestions/or code sample, will be welcome.

Thank you for the moment

Best regards

Kurt

Will NURBS work? or Bezier curves?
The superBible discribes how to use these, though I have not tried them myself

Roach

Ok Ok, thank you for this information, but I already tried with NURBS, and it is not the curve that I need.
Does anyone know some math formula, to make the interpolation of a cubic splines then I will use GL_LINE_STRIP or something like this.

But anyway thank you for your reply.

Best regards

Kurt

Your topic is related to CAGD, Computer Aided Graphics Design. This can be challenging subject.

Many splines are not intended to p-a-s-s t-h-r-o-u-g-h a point set. Yes, cuplic spline interpolation will generate a curve that passes through. (i.e. Bezier & NURB splines use control points to create a “pleasing” curve that will not necessarily pass through.)

Look at Numerical Recipes in C, routines: spline & splint. The separate example book shows you how to call these. Break down your 2D (x,y) data parametrically into (x(t),y(t)) and pass x[1…t] and y[1…t] into the routines. (or (x(t),y(t),z(t))) You shoud decide what range the parametric value t will have. For example 0<=t<=1 could represent the beginning to end. Beware you also need to add recipe’s nrutil.c to deal with FORTRAN style vectors these scientists used in Recipes: their arrays default (yes in C) to [1…n] but you can fool the pointer before you pass it if you prefer [0…n-1]. You pass x in for your array on t and do the same for y on t. t could be computed as an accumulating distance between points (i.e. sqrt((x2-x1)**2 + (y2-y1)**2). You could then scale t to have 3*n points e.g. to generate a three times denser denser spline than the number of points you have. Therefore, when you connect the lines, they will appear to have curvature.

Even if you don’t use their code, the book tells you how to perform cubic spline interpolation. Many introductory computer graphics texts discuss this as well.

Take care if you need an open versus closed spline. You’ll need to connect the nth point back to the 0th.

Best of Luck. If this doesn’t make sense, try reading the intro texts as mentioned. The Graphics Gems series has solutions as well, but the above explanation better make sense before you tackle the advanced GEMS books.

Books:
Computer Graphics using OpenGL (Hill,FS)
good college level text


Advanced

Mathematical Elements for Computer Graphics (Rogers & Adams) a classic with good detail

CAGD (Farin) sophisticated treatment of splines

Numerical Recipes in C (Press et al) and
Example Book (Press et al)
A classic for engineers & physicists (graduate level text, not written for but used by comp sci grad students)
You can pull the C code right out and use it
(under the rules of their copyright and disclaimer)

[This message has been edited by iss (edited 10-16-2000).]