Bezier Curve Fitting

Can anyone point me to some C# code that can reduce a series of (x,y) points to fit a bezier, or connected set of bezier curves? The beziers can be an approximation - they don’t have to pass through the points.

There’s some code in this thread that implements Bezier curves and also Catmull-Rom splines. Either of them might be useful to you, depending on what you’re doing.

andeee,

Thanks for the reply. I was already using that code to render beziers, and it’s been very helpful. I modified it to use LineRenderer instead. I created a little Bezier curve editor that uses that code (I assume it’s yours) and adds draggable handles on the screen for each of the 4 points, similar to what most vector art programs provide. If you’re interested in me posting that code, I’ll clean it up and do so.

What I want to do is allow someone to free-form draw a line (which I have working), and then fit a Cubic Bezier to that set of points. I have a brute-force method that is extremely slow. I’m sure my algorithm is exponential run-time worse case because my strategy is to progammatically move the control points around and minimize the distance from each point to the bezier curve. I need a smarter method if you know of one.

Thanks,
Mike

Hi Mike, how did you end up solving this? There’s a c curvefitting algorithm in graphic gems. GitHub - erich666/GraphicsGems: Code for the "Graphics Gems" book series