View Full Version : Curves
10-12-2000, 07:09 PM
Does anyone know how to generate curves, like cubic splines...
Any suggestions/or code sample, will be welcome.
Thank you for the moment
10-13-2000, 04:24 AM
Will NURBS work? or Bezier curves?
The superBible discribes how to use these, though I have not tried them myself
10-13-2000, 06:28 PM
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.
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 http://www.opengl.org/discussion_boards/ubb/frown.gif 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. http://www.opengl.org/discussion_boards/ubb/wink.gif
Computer Graphics using OpenGL (Hill,FS)
good college level text
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).]
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.