Vous êtes sur la page 1sur 2

Stack Overflow is a question and answ er site for professional and enthusiast programmers.

It's 100% free, no registration required.

Tell me more

Reverse engineering a bezier curve

Given a few sample points on a bzier curve points may lie on?

, is it possible to work out the set of possible curves these

In my specific application there is a limited set of endpoints the curve may have, so I want to generate the set of possible curves, enumerate all of them and pick out all the ones which may end on a valid end point. Some people have asked for more detail. I have a set of points which I know are on a quadratic bezier curve, I want to calculate the formula of the curve and be able to extrapolate new points on the curve.
algorithm language-agnostic math bezier bezier-curv e

edited Jun 14 '10 at 18:41

asked Jun 13 '10 at 16:28 Martin 4,105 1 22 61

fitting the points using a single bezier curve... of course it can be done (the same way as you would fit points using a function - bezier curve "is" a function) and the link you provided already speaks about "RE" a bezier curve ShinTakezou Jun 13 '10 at 16:33 Yes, but I want to know all possible curves these points lie on. The curve starting at the first point and ending at the last point is just one of many curves. Martin Jun 13 '10 at 17:21 with quadratic bezier curves you either have only one curve or less then four points through which the curve goes through. Also if you have more then four independent points you will not be able to find a single quadratic bezier curve that will pass through all of them. Unreason Jun 15 '10 at 14:28

2 Answers
Bezier curves will always go through starting and ending control points. If the degree of the curve is equal to the number of sample points then there will be only one curve that will pass through all your points (in a normal case, where all points are different and they don't lie on a bezier curve of a lesser degree). If the degree of a curve is less then the number of the sample points then, in general case, you will not be able to make the curve go through all the points (in a normal case). If the degree of a curve is higher then the number of the sample points then, in general case, you will be able to draw infinite number of curves. In the wiki article you will find references to control points only, but still I believe that I remember the above properties correctly and that they hold for the points on the curves as well. I think you need to redefine your question and exactly define what type of curves (and of which degree) do you need. Also as Georg pointed out you might be looking for paths - a combination of curves. EDIT: First a correction - curve is defined with degree plus one number of control points points (quadratic need three). Control points are not the same as points on the curve - and for three points on the curve and quadratic curve you could have infinite number of solutions (see this for quadratic curve and four points) As for the solution (but still under assumption that you are looking at a single curve):

For an equation for single quadratic curve you have B(t) = (1-t)^2*P0 + 2*(1-t)*t*P1 + t^2*P2 Capital letters above are vectors, and P0 corresponds to starting control point (first point), P2 corresponds to ending control point (last point), so you still need to find P1. The variable t is scalar that ranges from 0 to 1. If working with 2D curves the above vector equation gives two scalar equations for each point on the curve. Still there is t as an unknown, so you should take 2 more points (4 in total) which will give you 4 unknowns (t for first point, t for second point, x and y of the P1, middle control point) and 4 equation to solve (2 from each sample point). Solve that with your favourite numerical method and you will get the original curve on which the points came from. If you still think that you can get more curves and that you will have to choose something then you are not working with bezier curves, but with bezier splines (in a sense of multiple curves joined together). Still the same principle applies and if you work out a way to solve a single curve from the above equations (and if you have enough points) then you can divide the problem into n-segments of actual bezier curves and solve each as outlined above. If it turns out that you don't have enough points then look at the linked article again - you are probably looking for the smoothest curve and there are some suggestions in the article on how to get there as looking for the exact solution (shortest curve/smoothest curve) seems to be rather complex. edited Jun 15 '10 at 12:27 answered Jun 14 '10 at 14:17 Unreason 8,113 10 23

I added a little extra to the question as you asked :) Martin Jun 15 '10 at 10:38 I added a little extra to the answer I provided :) Unreason Jun 15 '10 at 14:17 Thanks, this looks pretty good. I'll see about trying it out in the next few days. Martin Jun 15 '10 at 23:22

Here they are: http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Examination_of_cases answered Jun 13 '10 at 16:49 FractalizeR 10.7k 2 25 66 I think it's not that simple. Most of the times, people say curve but actually mean many adjacent curves forming a path . Georg Schlly Jun 13 '10 at 17:39 We are talking about very concrete curves here. Exactly bezier curves. FractalizeR Jun 13 '10 at 20:10 How would I use this to calculate the set of all possible curves my sample points can lie on? Martin Jun 14 '10 at 8:50

Not the answer you're looking for? Browse other questions tagged algorithm
language-agnostic math bezier bezier-curve or ask your own question.

Vous aimerez peut-être aussi