Ellipse bounding a rectangle

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.


  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

Tags:

Math