views:

340

answers:

2

I'm looking for an algorithm to find bounding box (max/min points) of a closed quadratic bezier curve in Cartesian axis:

input: C (a closed bezier curve)
output: A B C D points

Image

Note: above image shows a smooth curve. it could be not smooth. (have corners)

+4  A: 

Well, I would say you start by adding all endpoints to your bounding box. Then, you go through all the bezier elements. I assume the formula in question is this one:

Quadratic Bezier from Wikipedia

From this extract two formulas for X, and Y respectively. Test both for extrema by taking the derivative (zero crossings). Then add the corresponding points to your bounding box as well.

ypnos
@ypnos: Thanks. how could i do test of extrema with a programming language? i think this needs a CAS and I don't have one! could introduce free one for python please?
Sorush Rabiee
It's easier to calculate the points where the derivative is zero directly as t0=(P1-P0)/(P0-2P1+P2).
tom10
Well the extrema test in your case is a rather simple formula and the number of solutions is known beforehand. So you will perhaps need one or two if statements, but the rest is just calculation. I don't do Python, sorry.
ypnos
+1  A: 

I believe that the control points of a Bezier curve form a convex hull that encloses the curve. If you just want a axis-aligned bounding box, I think you need to find the min and max of each (x, y) for each control point of all the segments.

I suppose that might not be a tight box. That is, the box might be slightly larger than it needs to be, but it's simple and fast to compute. I guess it depends on your requirements.

Adrian McCarthy
Yes it is true that the control points enclose the curve.
ypnos
@Adrian McCarthy: Thanks for answer. but I need to find a rectangle with minimum area.
Sorush Rabiee
The curve can be outside the bounds of the control points.
drawnonward
@drawnonward: [Wikipedia says][1]: "the curve is completely contained in the convex hull of its control points" [1]: http://en.wikipedia.org/wiki/B%C3%A9zier_curve
Adrian McCarthy