Using Derivatives for BĂ©zier curves to find the extreme candidates useful for the bounding box.

In our quest to find the bounding box for BĂ©zier curves (i.e. the minimum area rectangle that has sides parallel to the coordinate axes and that fully contains the curve) we did a step ahead in Derivatives for BĂ©zier curves, because we found a way to easily find out the parameters of the derived polynomial.

Why the derivation? From calculus, we know that all values of $t$ where the derivative of a function is zero are candidate positions for either a minimum or a maximum. Hence, it suffices to find where the derivative components are equal to zero and we will have candidate values of the parameter $t$ to find the extreme points for either axes. We will of course also make sure that these values of $t$ are admissible (i.e. fall in the regular $[0,1]$ interval for it) and also check the values at the two sides of the interval for $t$ itself.

We left Derivatives for BĂ©zier curves with this formula to calculate the coefficients of the polynomials for the derivative in the two axes:

As anticipated, these matrices can be pre-calculated and used when necessary upon the specific set of control points $\hat{P}$, which of course depends on the specific BĂ©zier curve we are considering.

The generic solution would involve finding the zeros of a polynomial of any degree. For quadratic and cubic Béziers, instead, we are lucky because it’s very easy to find the roots.

Quadratic BĂ©zier curves

For quadratic BĂ©zier curves this means using the following matrix:

Multiplying this matrix by the matrix $\hat{P}$ obtained putting the three control points as row vectors we end up with the following:

The two row vectors $\mathbf{q}$ and $\mathbf{m}$ represent the intercept and the angular coefficient of the derivatives for the two components over the X and Y axes. Hence, it is trivial to find the two candidates for the bounding box:

Cubic BĂ©zier curves

For cubic BĂ©zier curves we have instead:

Again, we can multiply by the matrix of the control points and obtain:

Here, the three row vectors $\mathbf{a}$, $\mathbf{b}$, and $\mathbf{c}$ hold the parameters for the second-degree equations that allow us to find the zeros in the two dimensions X and Y. Note that $\mathbf{b}$ can be easily divided by $2$, so we can find the roots as follows: