Packing ellipses into a circumscribing circle is more complex than packing circles, since there is no formula for the minimum distance between two ellipses or the maximum distance from the center of the circumscribing circle to an ellipse. This is overcome by embedding constraints using Lagrange multipliers into the problem to locate the most distant point from the origin of an ellipse and the points on pairs of ellipses closest to each other. A result of a packing, showing the ellipses and the determined points is shown here:
The hard part of the magic trick is done well here, but not the easy part.
The easy part – select three arbitrary ellipses. What is the best packing for those three arbitrary ellipses?
If the ellipses aren’t arbitrary – if you have a circle and some random points of tangency, then it’s pretty easy to find non-arbitrary ellipses that pack well based on those points.
How many arbitrary ellipses can your program pack?
Now that the basic approach has been worked out, I’m going to add more ellipses and also replace the circumscribing circle with an ellipse. For packing arbitrary ellipses, the trivial solution is to have one large circle and make the other ellipses very small, so more specification is needed.
The notebook showing the packing of three ellipses into the circumscribing ellipse is attached. Pairs of closest points on all pairs of ellipses were determined using embedded Lagrange multiplier equations and then the values of the ellipse equations for the nearest points on the other ellipses were used to ensure no overlap.
I’ve developed a slightly simpler method for packing ellipses in a circle. For preventing ellipse overlap, the point on one ellipse which minimizes the equation of the second ellipse is found. Here’s an example: