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?
For a quadratic Bezier, this is actually quite simple.
Define your three control points as P0 = (x0,y0)
, P1 = (x1,y1)
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.
Calculus gives the standard box of tricks for finding the min/max of continuous, differentiable curves.
Here is a sample discussion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With