Math Help - Find Rectangle

1. Find Rectangle

I need to enclose any given rectangle with another rectangle.

The enclosing rectangle must be of a specific ratio - eg width is twice its height for example. In actual fact the ratio I need for the enclosing rectagle is that the width is 1.62344 times the height.

So given any rectange r with heigh h and width w I need to find rectangle r2 with height h2 and width w2 such that r sits inside r2 and r2 is just big enough to enclose r but no bigger than it needs to be.

Many thanks

2. Re: Find Rectangle

Define the given rectangle

3. Re: Find Rectangle

Hi bjhopper

The rectangle to be enclosed is not defined. It can be any rectangle - well lets say any rectangle with a width >= 1 and < = 100000 and height >= 1 and <= 100000

Thanks

Dave

4. Re: Find Rectangle

Code:
  A          1.62344c          B

E         b           F
c
a

D                     G      C
Rectangle EFGD (height=a, width=b) is inside rectangle ABCD (height=c, width=1.62344c).
a and b are givens, with b>a.
Is this what you mean?

5. Re: Find Rectangle

Hello, daveywavey!

I need to enclose any given rectangle with another rectangle.

The enclosing rectangle must be of a specific ratio - e.g. width is twice its height, for example.
In actual fact, the ratio I need for the enclosing rectagle is that the width is 1.62344 times the height.

So given any rectange $R$ with height $h$ and width $w$,
I need to find rectangle $R_2$ with height $h_2$ and width $w_2$
such that $R$ sits inside $R_2$, and $R_2$ is just big enough to enclose $R$
. . but no bigger than it needs to be.

$\text{Let }r\text{ = the specified ratio (1.62344).}$

$\text{The "inner" rectangle is }R\text{, with width }w\text{ and height }h.$
$\text{There are two cases to consider.}$

$\text{(1) If }\frac{w}{h} > r,\,\text{ then: }\,w_2 = w,\;h_2 = \frac{h}{r}$

$\text{Example: }\,R\text{ is }3\times 1.$

$\text{Then: }\,w_2 \,=\, 3,\; h_2 \,=\,\frac{3}{r} \,\approx\,1.848$

Code:
      *-------------------*  -
|                   |  :
- *-------------------*  :
: |                   |1.848
1 |         R         |  :
: |                   |  :
- *-------------------*  -
: - - - - 3 - - - - :

$\text{(2) If }\frac{w}{h} < r,\,\text{ then: }\,w_2 \,=\,rh,\;h_2 \,=\,h$

$\text{Example: }\:R\text{ is }3\times2.$

$\text{Then: }\,w_2 \,=\,(r)(2) \:\approx\: 3.247$

Code:
      : - - 3 - - :
*-----------*---*
|           |   |
2 |     R     |   |
|           |   |
*-----------*---*
: - - 3.247 - - :

6. Re: Find Rectangle

Hi both and thanks for your help.

I needed this for some computer code I was writing and have already got it working with an algorithm which I guess is pretty simillar to Sorobans as follows:

private void MaintainAspectRatio()
{
double canvasWidth;
double canvasHeight;

canvasWidth = _croppedWidth + 4;
canvasHeight = canvasWidth * _aspectRatio;

if (canvasWidth < _croppedWidth || canvasHeight < _croppedHeight)
{
canvasHeight = _croppedHeight + 4;
canvasWidth = canvasHeight / _aspectRatio;
}
etc

Thanks for your solution though, I can make my test more elegant with this. I was also kind of wondering if this could be expressed in one formulae but I don't know if it can?

7. Re: Find Rectangle

Originally Posted by daveywavey
I was also kind of wondering if this could be expressed in one formulae but I don't know if it can?
Only in this style: IF [whatever] ELSE [whatever]

Like, impossible to have ONE straightforward formula giving you the cost of apples AND of bananas, right?

8. Re: Find Rectangle

Ok thanks Wilmer. I only did O level maths and some A level maths at college so I didn't know what you can do these days - I just remember Russell Crowe in a beautiful mind writing lots of algorithms and was thinking of that sort of thing I think!

Many thanks for youre help

Also this is my first question on here - are there protocols for expressing thanks, giving points etc? I'm sure there must be as I see it says 40 Thanks next to your name.

9. Re: Find Rectangle

If we let r = ratio (1.62344 in your example),
a = height inner rectangle, b = width inner rectangle,
u = height outer rectangle,v = width outer rectangle,

then you can use (assuming a*r <> b):

IF ar > b then u = a and v = a*r ELSE v = b and u = b/r

10. Re: Find Rectangle

Thanks Wilmer thats very succint, thanks!