Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ellipse bounding a rectangle [closed]

Tags:

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.

like image 986
Scotty Avatar asked Jan 11 '09 18:01

Scotty


People also ask

What are the 3 properties of an ellipse?

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.


2 Answers

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:

  • x = cos(theta) * sqrt(2) * rect.width + x.center;
  • y = sin(theta) * sqrt(2) * rect.height + y.center;

where rect.width and rect.height are the half widths of the relevant sides.

like image 194
Alnitak Avatar answered Sep 21 '22 20:09

Alnitak


  1. Ellipse formula is (x/A)^2+(y/B)^2=1, where A and B are radiuses of ellipse
  2. Rectangle sides are Rw and Rh
  3. Let's assume we want ellipse with same proportions as rectangle; then, if we image square in circle (A=B,Rq=Rh) and squeeze it, we well keep ratio of ellipse A/B same as ratio of rectangle sides Rw/Rh;

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:
ellipse

like image 36
setec Avatar answered Sep 20 '22 20:09

setec