2

I have a list of (x, y) points. I know how to make a list of Bézier curves which pass through all of those points and have a continuous first (and second, though less important) derivative. However, the list that I end up with is far too long. I would prefer to approximate the points I have if it lets me cut down on the number of curves I have. I would like to be able to pass a parameter of either how close an approximation I get or a maximum number of curves, preferably the former.

The reason I want this is that the end result will have a graphical UI where users can edit the Bézier curves, and it isn't critical that the curves pass through each point exactly, as long as they are close. More curves makes it harder to edit.

EDIT: Some more information about the purpose of this. I'm trying to make image editing software. When someone loads a bitmap, I want to be able to trace a center line. Potrace is what I would use to trace the outline of a shape, but it won't work for tracing strokes. I've been able to identify lots of points along the center line, and I want to turn this data into a list of connected Bézier curves. The reason I don't want to make a Bézier spline is that there will be too many control points for this to be easy to edit. "Too many" is not an easy-to-define term, but I would like to be able to pass a parameter to limit the number of curves. Either a function that minimizes how far the curves are from the points based on a maximum number of curves or a function that minimizes the number of curves based on a maximum deviation from the points.

Pi Fisher
  • 260
  • 1
  • 11
  • 1
    [Ramer-Douglas-Peuker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm) looks like it might be a good solution. – Pi Fisher Nov 18 '16 at 21:06
  • 1
    Does it have to be separate Bezier curves? Otherwise, you are just looking for spline fitting. – Nico Schertler Nov 18 '16 at 22:49
  • That's a pretty broad question - do you have some concrete details of what you're doing? What does the list represent? Why do you need Bezier curves, specifically? What does "too long" mean? If the points can be approximations, what aspect of them is important to preserve? etc. etc. – Mike 'Pomax' Kamermans Nov 19 '16 at 18:28
  • @NicoSchertler, the problem with spline fitting is that it will be too many curves, because I'll have only one fewer curve than the number of points. – Pi Fisher Nov 21 '16 at 14:24
  • No, spline fitting will give you one curve. And you can specify the number of control points and the degree of that curve. – Nico Schertler Nov 21 '16 at 14:55
  • @NicoSchertler My understanding is that spline fitting is when you construct a C^2 curve that is piecewise defined by cubic Bézier curves such that the curve passes through all the points in order. Are you referring to something else? – Pi Fisher Nov 21 '16 at 22:16
  • 1
    A spline is much more general. You can also use splines that approximate the points (i.e. it does not necessarily pass through all of them). Both degree (i.e. the continuity) and number of segments can be specified. I assume that you are referring to the latter as number of curves. – Nico Schertler Nov 22 '16 at 00:31
  • Can you provide a link to an implementation or a description of one? I'm just finding definitions that ask to minimize over an integral. – Pi Fisher Nov 22 '16 at 14:22

1 Answers1

4

Several approaches exist for achieving what you want to do:

1) Use RDP algorithm to reduce the number of points, then create a list of Bezier curves passing thru the remaining points.

2) Use curve fitting algorithms (for example, Schneider algorithm) to produce multiple Bezier curves that are connected with G1 (tangent) continuity. Check out Schneider algorithm implementation in this link.

3) Use least square fitting with B-spline to produce a single B-spline curve.

From implementation point of view, approach 1 is probably the easiest one for you as you already know how to create Bezier curves interpolating a list of points. Approach 3 will be much more difficult to implement and you probably will have to convert the B-spline curve into Bezier curves so as to use them at the UI level. Please refer to this SO article for detailed discussion.

Community
  • 1
  • 1
fang
  • 3,473
  • 1
  • 13
  • 19