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 complete calculation is in the attached notebook. The optimization was carried out as a local search using MathOptimizer Professional
as FindMinimum does not converge for the calculation.
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.
I can now pack 3 ellipses into an ellipse. Details to follow
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 discovered that my approach for packing ellipses into an ellipse does not work for all situations.
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:
latest results for packing ellipses into circles. the calculation for the attached plot took about 12 seconds.
20 ellipses takes about 6 minutes, using a Mathematica interface to the COIN-OR local solver Ipopt.