Board index » delphi » Cubic splines somehow?
David Wim
Delphi Developer 
Tue, 24 Jul 2001 03:00:00 GMT

David Wim
Delphi Developer 
Tue, 24 Jul 2001 03:00:00 GMT
Cubic splines somehow?
Delphi comes with a Bezier function but, apparently, no cubic
splines. Is this function available somewhere. 20 years ago, I took a class in which I learned how to generate the control points for Bezier curves to produce cubic splines. Guess what. I don't remember. Does anybody know where I might get this information. I would just do this from scratch but I need parametric splines and that make it a bit harder.  Define thine enemy and speak for him! 
Charles Hacke
Delphi Developer 
Wed, 25 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?No Delphi does NOT have a cubic spline function directly, and neither does QuoteDavid Wimp wrote: 
Joe C. Hech
Delphi Developer 
Wed, 25 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?QuoteDavid Wimp wrote: but you will have a tough time going the other direction! Joe 
Rene Tschaggela
Delphi Developer 
Wed, 25 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?There are approximating and interpolating splines. Both require a couple of equation systems to be solved. How many datapoints do you have to fit ? Rene QuoteDavid Wimp wrote: 
David Ullric
Delphi Developer 
Wed, 25 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?QuoteDavid Wimp wrote: a spline, but there's no problem using PolyBezier to draw splines. Um, "spline" means lots of different things: If you have a collection of points and tangent vectors there's no problem using PolyBezier to draw a curve through those points with the given tangent vectors at each point. (It seems to me that bezier curves are more general than this, you can have different righthand and lefthand tangent vectors with a bezier curve, hence corners if you want.) The following is not supposed to be elegant code or nice unit duNewBezier; interface uses Windows, Classes, Graphics; type PPoints = ^TPoints; procedure DrawCurveFromPointsAndTangents(C:TCanvas; const P,T:array of TPoint); implementation uses SysUtils; function LC(Pt1,Pt2:TPoint; c1,c2:extended):TPoint; procedure DrawCurveFromPointsAndTangents(C:TCanvas; const P,T:array of TPoint); GetMem(N, (3*H+1)*SizeOf(TPoint)); Quote> Dave David Ullrich sig.txt still not found 
David Wim
Delphi Developer 
Wed, 25 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?QuoteRene Tschaggelar wrote: form I need only has approximating splines. This is slowly coming back to me but I am having flashbacks of Jimmy Carter and the oil embargo. I have about 20 points.  
David Wim
Delphi Developer 
Wed, 25 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?QuoteJoe C. Hecht wrote: draw a Bezier that is a spline. I whipped out Bezier from Hermite. I am sure I can do splines when I am up to plodding through it. I realized that my Foley & Van Damm has this in it but listed under curves. They don't have interpolating splines, though.  Define thine enemy and speak for him! 
David Wim
Delphi Developer 
Wed, 25 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?This is Hermite interpolation, I think. I managed to do that. I am computing the tangent for P[i] as s*(P[i+1]  P[i1]) (pretending to be able to do vector arithmetic directly). I am now trying to find a reasonable way to compute the scale factor s. Eventually, I need to convert it to spline interpolation but this will do for now. I can appear to have solved the problem. Thanks.  Dave Define thine enemy and speak for him! 
David Ullric
Delphi Developer 
Thu, 26 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?QuoteDavid Wimp wrote: where the array P came from originally. If I recall correctly (worked this out long ago and never actually used it) the code I posted assumes that the tangents are derivatives with respect to "time", where time is scaled the same as the array index: P[i+1] is the point on the curve one second past the time it hit P[i]. So if you're actually sampling a curve in time intervals of length h, ie P[j] = theCurve[j*h], then I'm pretty sure what you want to plug in for the tangent would be h*(P[j+1]  P[j]), or better (h/2)*(P[j+1]  P[j1]). Pretty sure  if that's way off then I got something backwards just now and you want 2/h instead. I posted something here (or in the objectpascal section) a Quote> Eventually, I need to convert it to spline interpolation but this David Ullrich sig.txt still not found 
Rene Tschaggela
Delphi Developer 
Thu, 26 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?You can always use the approximating splines when you can tell them to fit closest. I have a book called : Rene QuoteDavid Wimp wrote: 
Geir Wikra
Delphi Developer 
Fri, 27 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?You should have had Robert F. Kauffmann's article "Implementing Uniform Trigonometric Spline Curves" from the Algorithm Alley of Dr. Dobb's Journal (http://www.ddj.com) in May 1997 (can be ordered at there web site for $5.00). Anyway, the demoprogram for the article, which demonstrates different http://www.ddj.com/ftp/1997/1997.05/aa597.zip Geir 
Charles Hacke
Delphi Developer 
Fri, 27 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?I got out a Numerical Computing book and programmed a cubic spline function. I teseted it and it works okay. The code is given below: private procedure TMainWin.DrawSpline(Sender: TObject); QuoteRene Tschaggelar wrote: 
David Ullric
Delphi Developer 
Fri, 27 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?Two updates: (i) Ralph found the thread I was referring to  look for Newsgroups: borland.public.delphi.graphics and followups on the details I left out there. (ii) In the situations I've had in mind I've had some points _and_  sig.txt still not found 
David Wim
Delphi Developer 
Fri, 27 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?QuoteDavid Ullrich wrote: generate the two Bezier points not interpolated by Bezier curves from 4 data points so that the resulting curve is a spline. I have gotten enough information to do this now but am busy on something else at the moment. I will post the solution when I can. Somebody in this thread posted some code from Dr. Dobbs that has the matrix in it that is needed to do this.  Dave Define thine enemy and speak for him! 
David Wim
Delphi Developer 
Fri, 27 Jul 2001 03:00:00 GMT
Re:Cubic splines somehow?QuoteGeir Wikran wrote: first link. I forgot the name of it. I would have spent a while figuring it out.  Define thine enemy and speak for him! 