If the major axis of the ellipse is vertical or horizontal, it's easy to calculate the bounding box, but what about when the ellipse is rotated?
The only way I can think of so far is to calculate all the points around the perimeter and find the max/min x and y values. It seems like there should be a simpler way.
If there's a function (in the mathematical sense) that describes an ellipse at an arbitrary angle, then I could use its derivative to find points where the slope is zero or undefined, but I can't seem to find one.
Edit: to clarify, I need the axis-aligned bounding box, i.e. it should not be rotated with the ellipse, but stay aligned with the x axis so transforming the bounding box won't work.
This is my function for finding tight fit rectangle to ellipse with arbitrary orientation
I have opencv rect and point for implementation:
cg - center of the ellipse
size - major, minor axis of ellipse
angle - orientation of ellipse
Here is the formula for the case if the ellipse is given by its foci and eccentricity (for the case where it is given by axis lengths, center and angle, see e. g. the answer by user1789690).
Namely, if the foci are (x0, y0) and (x1, y1) and the eccentricity is e, then
where
I derived the formulas from the answer by user1789690 and Johan Nilsson.
If you work with OpenCV/C++ and use
cv::fitEllipse(..)
function, you may need bounding rect of ellipse. Here I made a solution using Mike's answer: