inscribing a rectangle in an ellipse? PLS HELP!

EndivioR

New member
Joined
Jan 2, 2011
Messages
2
Take up computer programming and your ignorance of trig will come back to haunt you.

I am writing software in VB.NET. In that language, you can draw an ellipse on the screen by specifying the following properties of a "bounding rectangle": the x and y coordinates (in pixels) of the top left corner, and the width and height. Passing these values to the appropriate command will produce an ellipse with its major axis coinciding with the x or y plane (ie not lopsided), inscribed inside the bounding rectangle. Thus, the only properties of the ellipse I have readily available are the width and height at the centre, and I can also calculate the centre coordinates by adding to the top left coordinate of the bounding rectangle half the width and half the height, respectively.

Now, what I need is to draw another rectangle, but this one should be inscribed INSIDE the ellipse. It should have the same ratio of width to height as the original "bounding" rectangle, and should touch the ellipse at each of its four corners. To draw it, I need to specify the top left coordinate (x, y), and the width and height, just as I did for the bounding rectangle of the ellipse. In practice, since its centre will obviously coincide with that of the bounding rectangle and of the ellipse, and since the width/height ratio is the same as that of the bounding rectangle, all I need is just ONE of those values, the width or the height, or for that matter the x and y coordinates of the top left corner (ie the point where a line drawn from the centre to the top left corner of the bounding rectangle would cross the ellipse) from which deriving the others would be trivial, even for a duffer like me. But I have no idea where to start, except the suspicion that the solution will involve some combination of sines, cosines and square roots.

In case anyone's wondering about the point of this, the idea is to define an area inside an elliptical "speech bubble", drawn by the user, into which text can be written. Once I have the basic formula for the single inscribed rectangle (which would only be optimal for a single line of text) I will then try to adapt it to deal with multiple lines... but that's still some way off.

Many thanks in advance for any help anyone can offer
 
Thanks for the reply. Obviously I'd already searched Google and come up with a lot of pages of detailed discussion on ellipses, all of which seemed to assume I had a "formula" for calculating my ellipse, which I wasn't aware of having. Thus, in desperation I came here. However, reviewing a random Google pick just now I came up with a possible solution, which I've just tested and seems to work OK. It's actually as simple as dividing both the original width and height of the bounding rectangle by the same number, viz. the square root of 2. What an amazing number that is. I can't think why I haven't seen its praises sung before.

Thanks again.
 
Maybe finding the rectangle of max area that can be inscribed in an ellipse would help?.

If we have an ellipse, x2a2+y2b2=1\displaystyle \frac{x^{2}}{a^{2}}+\frac{y^{2}}{b^{2}}=1 centered at the origin,

then, the rectangle of max area could be A=2xy. Where 'a' is the length of the semi-major axis and 'b' is the length of the semi-minor axis.

In this case, the rectangle of max area would have side lengths of x=a2,   y=b2\displaystyle x=\frac{a}{\sqrt{2}}, \;\ y=\frac{b}{\sqrt{2}}

There is your 2\displaystyle \sqrt{2} again:).

This gives an area of the rectangle as A=ab.

The area of an ellipse can be found by using Ae=πab\displaystyle A_{e}={\pi}ab

Perhaps this will be of some interest. Just throwing it out there.
 
Take up computer programming and your ignorance of trig will come back to haunt you.

I am writing software in VB.NET. In that language, you can draw an ellipse on the screen by specifying the following properties of a "bounding rectangle": the x and y coordinates (in pixels) of the top left corner, and the width and height. Passing these values to the appropriate command will produce an ellipse with its major axis coinciding with the x or y plane (ie not lopsided), inscribed inside the bounding rectangle. Thus, the only properties of the ellipse I have readily available are the width and height at the centre, and I can also calculate the centre coordinates by adding to the top left coordinate of the bounding rectangle half the width and half the height, respectively.

Now, what I need is to draw another rectangle, but this one should be inscribed INSIDE the ellipse. It should have the same ratio of width to height as the original "bounding" rectangle, and should touch the ellipse at each of its four corners. To draw it, I need to specify the top left coordinate (x, y), and the width and height, just as I did for the bounding rectangle of the ellipse. In practice, since its centre will obviously coincide with that of the bounding rectangle and of the ellipse, and since the width/height ratio is the same as that of the bounding rectangle, all I need is just ONE of those values, the width or the height, or for that matter the x and y coordinates of the top left corner (ie the point where a line drawn from the centre to the top left corner of the bounding rectangle would cross the ellipse) from which deriving the others would be trivial, even for a duffer like me. But I have no idea where to start, except the suspicion that the solution will involve some combination of sines, cosines and square roots.

In case anyone's wondering about the point of this, the idea is to define an area inside an elliptical "speech bubble", drawn by the user, into which text can be written. Once I have the basic formula for the single inscribed rectangle (which would only be optimal for a single line of text) I will then try to adapt it to deal with multiple lines... but that's still some way off.

Many thanks in advance for any help anyone can offer

dont know the correct answer but u try these website http://vb.net-informations.com , www.codeproject.com

chris.
 
Part of your problem may be this- given any rectange, there exist a unique ellipse inscribed in it. But given an ellipse, there exist an infinite number of rectangles that can be inscribed in it. Given, any length, up to the length of the major axis, you can calculate a width so the rectangle will be inscribed in the ellipse.

Specifically, if a rectangle has length 2a and width 2b, we can construct a coordinate system with origin at the center of the rectangle, x-axis parallel to the length, and y-axis parallel to the width. In that coordinate system, the inscribed ellipse will have equation x2a2+y2b2=1\displaystyle \frac{x^2}{a^2}+ \frac{y^2}{b^2}= 1. Given any positive x< a, there is an inscribed rectangle with vertices at (x,b1x2a2)\displaystyle (x, b\sqrt{1- \frac{x^2}{a^2}}), (x,b1x2a2)\displaystyle (x, -b\sqrt{1- \frac{x^2}{a^2}}), (x,b1x2a2)\displaystyle (-x, b\sqrt{1- \frac{x^2}{a^2}}), and (x,b1x2a2)\displaystyle (-x, -b\sqrt{1- \frac{x^2}{a^2}}).
 
The rectangle above will have maximum area when x = a2\displaystyle x \ = \ \dfrac{a}{\sqrt{2}}

Geometrically, to draw this inscribed maximum rectangle:

1) draw the outside rectangle.

2) draw the diagonals of this rectangle

3) the intersection points (±a/√2, ±b/√2) of these diagonals and the ellipse are the four vertices of the inscribed maximum rectangle.

However, the OP did not mention "maximum".

In pixel geometry, the introduction of irrational √2 can (will) create Diophantine problem. However, that may not be important in a "game" simulation problem.
 
Last edited by a moderator:
Top