How this calculation works
Fit the largest-area ellipse that lies inside a convex polygon. Its center, symmetric shape matrix, semiaxes and side clearances expose the containment geometry and the numerical stopping quality.
maximize log det A; ||A n_i||+n_i·c≤b_i; E={c+A u:||u||≤1}, A positive definite.A worked example
For the rectangle [−2,2]×[−1,1], the maximum-area inscribed ellipse is centered at zero with semiaxes2 and1. Its area is2π≈6.28318531. The interior-barrier solve approaches these contacts from inside, with a small reported log-area gap.
Good to know
3–20 consecutive convex vertices, full-dimensional and numerically resolved. Convex log-determinant barrier/Newton fit after normalization. Reports a barrier log-area gap estimate and Newton decrement; numerical tolerance is not a rigorous exact arithmetic certificate. No nonconvex polygons or enclosure objective.
Reference: Method reference (opens in a new tab) ↗
An inscribed ellipse reverses the enclosure question
An enclosing ellipse must cover the supplied points. This problem requires every point of the ellipse to remain inside the polygon, so a visually similar outer fit answers the opposite question.
Write the ellipse as c+A u for unit-disk vectors u, with A symmetric positive definite. This representation includes rotation through the off-diagonal entry while keeping determinant proportional to area.
Compare this with the Minimum enclosing ellipse calculator for planar points. An enclosing ellipse reverses containment and answers a different optimization objective.
A whole ellipse can be checked against each side
For a side inequality n·x≤b, the largest ellipse projection is n·c+norm(A n). Requiring that support value to stay below b checks the entire ellipse, not a finite collection of sampled perimeter points.
The form is invariant under multiplying a side inequality by a positive constant. The implementation uses unit normals so the reported slack is a distance. It verifies every side after recovering the original coordinate scale.
Why the optimization has a global mathematical objective
The logarithm of determinant is concave on positive-definite matrices and each support constraint is convex. Maximizing log determinant over these constraints therefore has the convex-optimization structure needed for a global mathematical optimum.
The implementation follows an interior barrier with Newton steps and backtracking. It increases the objective weight while remaining strictly feasible. The mathematical structure does not eliminate floating-point error, so convergence diagnostics accompany the ellipse.
Check the rectangle before arbitrary shapes
A centered axis-aligned ellipse with semiaxes2 and1 reaches all four rectangle sides. Its determinant is2, and area equalsπ times that determinant. The symmetry also fixes the optimal center.
The barrier solution is slightly smaller because its side slacks remain positive. An area just below2π is expected; an ellipse outside a side or an area above the known value would indicate a failed containment calculation.
Interpret the shape matrix and the gap
Eigenvalues of the symmetric shape matrix are the semiaxis lengths, and its eigenvectors determine their directions. They are not the squared axes of a quadratic-form matrix, a common source of incorrect reconstruction.
The reported log-area gap uses the barrier parameter and number of side constraints. It is a numerical stopping diagnostic after a small Newton decrement, rather than an exact interval proof that accounts for all floating-point roundoff.
Reject a flat or unresolved polygon
A polygon with empty interior cannot contain a positive-area ellipse. Very narrow regions make the Hessian poorly conditioned and can defeat the bounded solver even when their geometric area is positive.
Repeated edges, unordered concave input, failed line search or an iteration cap produce errors. The page does not replace an unresolved optimum with an enclosing ellipse or quietly regularize the polygon into a different shape.
Compare designs through contact and area
Near-zero side slacks show which boundaries constrain expansion. Other sides may remain inactive even though all polygon vertices contribute to the input. More vertices do not necessarily change the ellipse.
Use area to compare alternative feasible regions, then inspect semiaxes for directional capacity. Physical clearance, axis restrictions and a fixed center would change the optimization problem and should be modeled separately.
A few questions, answered
Is the ellipse allowed outside the polygon?
No. Every side is checked using the ellipse support function.
Are the matrix eigenvalues squared semiaxes?
No. Here A maps the unit disk, so its positive eigenvalues are semiaxis lengths.
Why is the rectangle answer slightly below2π?
The numerical barrier keeps a small positive distance from each active boundary.
Does this accept concave polygons?
No. The supporting-half-plane model requires a convex polygon.