Maths101 question - does anyone know how to calculate an ellipse (width/height) that will enclose a given rectangle. Obviously there is no single ellipse - I'm after an algorithm that will give me various width/height combinations - or perhaps the smallest area of ellipse? It's for a GUI, so an aesthetically pleasing ratio of height/width is what I'm looking for.
Thanks in advance.
Properties of an EllipseAll ellipses have two foci or focal points. The sum of the distances from any point on the ellipse to the two focal points is a constant value. There is a center and a major and minor axis in all ellipses. The eccentricity value of all ellipses is less than one.
If you give your ellipse the same aspect ratio as the rectangle, you can work on the basis that what you want is a circle enclosing a square then stretched as if you've transformed the square into the required rectangle.
For a square with half side length = 1, the radius of the circle would be sqrt(2).
So, sweeping theta from 0 - 360', the ellipse's coordinate points will be:
where rect.width and rect.height are the half widths of the relevant sides.
This leads us to following system of equations:
(x/A)^2+(y/B)^2=1
A/B=Rw/Rh
Lets solve it:
A=B*(Rw/Rh)
(Rh/2B)^2+(Rh/2B)^2=1
Rh=sqrt(2)*B
And final solution:
A=Rw/sqrt(2)
B=Rh/sqrt(2)
Example:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With