HP Forums
finding the minimum bounding box of a Bézier curve - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: Not HP Calculators (/forum-7.html)
+--- Forum: Not remotely HP Calculators (/forum-9.html)
+--- Thread: finding the minimum bounding box of a Bézier curve (/thread-20798.html)



finding the minimum bounding box of a Bézier curve - brouhaha - 11-08-2023 01:35 AM

I needed a way to compute the minimum bounding box for a cubic Bézier curve. For somewhat dumb reasons, this is involved in preparing my new SVG scalable graphics for Nonpareil II. Most or all vector drawing programs, including Inkscape), allow you to use cubic Bézier curves, usually by positioning control points. There are four control points for a cubic Bézier curve; the first and last are the end points of the curve, and other two control points affect how the curve behaves between the endpoints. It is a property of the Bézier curve that the curve never goes outside the convex hull of the control points. However, the minimum bounding box in many cases is much smaller, and it is often useful to have a bounding rectangle parallel to the coordinate axes, rather than an arbitrary convex hull.

I wanted to experiment with this, and the existing graphics programs and interactive web pages didn't quite do what I wanted, so I wrote a new C++ program using Qt, which will show a curve, allow you to drag the points around, shows the coordinates of the control points in a second pane, and can optionally show the bounding box of the control points, the convex hull of the control points, and the minimum bounding box of the curve.

It's open source, and the source code and a Windows .msi can be found at:
https://github.com/brouhaha/bezier-hack

A Bézier curve is defined by parametric equations, one per dimension of the curve, for a parameter t that ranges from 0 to 1. The way to find the minimum bounding box is to generate the polynomials for the parametric equations, differentiate them, and solve the differentials for zeros. Complex solutions can be discarded. The real solutions between 0 and 1 indicate at what parameter value(s) the cuve has minima or maxima. The minimum bounding box is then the minimum rectangle that contains the first and last control point, and any minima and maxima points.

It's probably very easy to do this on a graphing calculator that has symbolic differentiation, but I've only done it in C++ so far.


RE: finding the minimum bounding box of a Bézier curve - floppy - 11-08-2023 12:21 PM

Open curves examples.. https://cubic-bezier.com/#.17,.67,.83,.67
Lea VEROU could perhaps support?
Could not see in your request if this is a closed or an open curve or what you want to achieve (a graph would be good).


RE: finding the minimum bounding box of a Bézier curve - brouhaha - 11-08-2023 06:31 PM

Thanks, but I wasn't requesting anything. The program is written and released as open source.