Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding min/max of quadratic bezier with CoreGraphics

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?

like image 387
unscene Avatar asked Jun 16 '09 04:06

unscene


2 Answers

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.

like image 63
Naaff Avatar answered Oct 19 '22 23:10

Naaff


Calculus gives the standard box of tricks for finding the min/max of continuous, differentiable curves.

Here is a sample discussion.

like image 32
nsanders Avatar answered Oct 20 '22 00:10

nsanders