I am using CoreGraphics to draw a quadratic bezier but want to computer the min/max value of the curve. I am not from a mathematical background so this has become a bit troublesome. Does anyone have any articles or ideas about how to solve this?
Calculus gives the standard box of tricks for finding the min/max of continuous, differentiable curves.
Here is a sample discussion:
http://newsgroups.derkeiler.com/Archive/Comp/comp.graphics.algorithms/2005-07/msg00334.html
For a quadratic Bezier, this is actually quite simple.
Define your three control points as P0 = (x0,y0)
, P1 = (x2,y2)
and P2 = (x2,y2)
. To find the extrema in x
, solve this equation:
t = (x0 - x1) / (x0 - 2*x1 + x2)
If 0 <= t <= 1
, then evaluate your curve at t
and store the location as Px
. Do the same thing for y
:
t = (y0 - y1) / (y0 - 2*y1 + y2)
Again, if 0 <= t <= 1
, evaluate your curve at t
and store the location as Py
. Finally, find the axis-aligned bounding box containing P0
, P2
, Px
(if found) and Py
(if found). This bounding box will also tightly bound your 2D quadratic Bezier curve.