Comments on: Generating B?zier curves from discrete point sets
http://ask.metafilter.com/50554/Generating-B?zier-curves-from-discrete-point-sets/
Comments on Ask MetaFilter post Generating B?zier curves from discrete point setsThu, 09 Nov 2006 14:05:14 -0800Thu, 09 Nov 2006 14:05:14 -0800en-ushttp://blogs.law.harvard.edu/tech/rss60Question: Generating Bézier curves from discrete point sets
http://ask.metafilter.com/50554/Generating-B?zier-curves-from-discrete-point-sets
What is a good algorithm for generating smooth curves from discrete points? <br /><br /> For example, I have a set of time series data. I can easily draw a jagged line by plotting each point and connecting with straight lines. However, I'd like to make a pretty graph with smooth, interpolated lines using cubic or quadratic Bézier curves.<br>
<br>
I've looked over the <a href="http://archive.dojotoolkit.org/nightly/tests/charting/test_engine.html">Dojo Charting Engine</a>, which does pretty much what I want, simply calculating the delta along the X-axis, and multiplying by a constant "tension" factor to determine the position of the control points.<br>
<br>
Can you point me to any other, similar algorithms?post:ask.metafilter.com,2006:site.50554Thu, 09 Nov 2006 13:56:26 -0800ijoshuabeziercurvepointschartingchartgraphinggraphmathBy: vacapinta
http://ask.metafilter.com/50554/Generating-B?zier-curves-from-discrete-point-sets#766089
You should read up on <a href="http://www.google.com/search?hl=en&lr=&q=splines&btnG=Search">Splines</a>.comment:ask.metafilter.com,2006:site.50554-766089Thu, 09 Nov 2006 14:05:14 -0800vacapintaBy: Neiltupper
http://ask.metafilter.com/50554/Generating-B?zier-curves-from-discrete-point-sets#766099
Take a look at <a href="http://curveexpert.webhop.biz/">CurveExpert.</a> It's shareware with a 30 day evaluation period.comment:ask.metafilter.com,2006:site.50554-766099Thu, 09 Nov 2006 14:11:30 -0800NeiltupperBy: dseaton
http://ask.metafilter.com/50554/Generating-B?zier-curves-from-discrete-point-sets#766198
Do you have access to Mathematica? If so, you can use the Interpolation command. It works pretty well for what you want.comment:ask.metafilter.com,2006:site.50554-766198Thu, 09 Nov 2006 15:27:19 -0800dseatonBy: bonehead
http://ask.metafilter.com/50554/Generating-B?zier-curves-from-discrete-point-sets#766243
If you don't know the functional form of your data, a spline fit (see above) is often the "best" answer. <a href="http://en.wikipedia.org/wiki/B%C3%A9zier_spline">Bézier "curves"</a> are a form of splines. the trick to fitting splines is boundary conditions: if you don't get the derivatives right at the ends you sometimes end up with really weird curves (You didn't know you were doing calculus in Photoshop when you were tweaking nodes, now did you?)<br>
<br>
If you know a bit more about how your data should behave (no inflection points, for example), you can use a better candidate function to fit your dataset. The simplest way to do this is the linearize you data in terms of the function, <em>e.g.</em>, if fittiing an exponential, take the log of your data, then fitting a line, doing the back transform and finally plotting. This only works for farily simple functions though (like splines). Otherwise you're stuck with a non-linear fit.comment:ask.metafilter.com,2006:site.50554-766243Thu, 09 Nov 2006 16:06:10 -0800boneheadBy: bonehead
http://ask.metafilter.com/50554/Generating-B?zier-curves-from-discrete-point-sets#766259
On rethink: are you plotting data real-time, and/or don't really care about how the fit looks and just want a nice line? In that case, the cheap and nasty way to do it is a <a href="http://en.wikipedia.org/wiki/Moving_average">moving-average</a> calculation, sort of the red-headed stepchild of a real spline fit. I've found that a five-point trailing average is enough to fake out most obersevers for real-time stuff. Computationally, a moving average is way cheaper than even a spline fit.<br>
<br>
Technically, this isn't a fitting so much as a smoothing technique, but if that's what you need, it will serve much the same job.comment:ask.metafilter.com,2006:site.50554-766259Thu, 09 Nov 2006 16:21:55 -0800boneheadBy: ijoshua
http://ask.metafilter.com/50554/Generating-B?zier-curves-from-discrete-point-sets#766351
Nailtupper and dseaton, thanks, but I'm not looking for software to do the job for me. I'm interested in the math behind the process because I'm generating dynamic charts, most likely targeting SVG.<br>
<br>
My input data most likely doesn't fit any particular functional form — it's a time series of website statistics, e.g. number of active sessions per hour of a day. It isn't a real-time plot, either.<br>
<br>
I don't think a moving average is what I want, either. I want the line to fit the data pretty accurately, because I'm only analyzing a few dozen samples (or "knots," I guess) at once.comment:ask.metafilter.com,2006:site.50554-766351Thu, 09 Nov 2006 17:47:32 -0800ijoshuaBy: bonehead
http://ask.metafilter.com/50554/Generating-B?zier-curves-from-discrete-point-sets#767725
A last comment: if you are concerned about understanding your data trends, you may want to consider using something other (or in addition to) splines. Splines will give you a pretty picture, because splines will fit just about anything given enough nodes and boundary condition freedom. They're also quite light-weight numerically. They are very hard to interpret, however. What does the trend line mean? Splines won't tell you.<br>
<br>
If you're trying for a functional descritption of your data, you need to try other things and that typically means either tranforming your data, e.g. Fourier transforms to look for periodicity, or using non-linear functional fits. A reasonably practical starting place for both approaches are the "Numerical Recipies in C/C++/Fortran" books, if that's what you're after.comment:ask.metafilter.com,2006:site.50554-767725Sat, 11 Nov 2006 11:16:04 -0800boneheadBy: iconjack
http://ask.metafilter.com/50554/Generating-B?zier-curves-from-discrete-point-sets#785310
Check out these nice articles by Don Lancaster:<br>
http://www.tinaja.com/cubic01.aspcomment:ask.metafilter.com,2006:site.50554-785310Wed, 29 Nov 2006 11:36:45 -0800iconjack