Results 1 to 10 of 10

Math Help - Find Rectangle

  1. #1
    Newbie
    Joined
    Jul 2012
    From
    UK
    Posts
    6

    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
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member
    Joined
    Nov 2007
    From
    Trumbull Ct
    Posts
    917
    Thanks
    27

    Re: Find Rectangle

    Define the given rectangle
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jul 2012
    From
    UK
    Posts
    6

    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
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    Dec 2007
    From
    Ottawa, Canada
    Posts
    3,113
    Thanks
    68

    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?
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Super Member

    Joined
    May 2006
    From
    Lexington, MA (USA)
    Posts
    11,857
    Thanks
    739

    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 - - :
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Newbie
    Joined
    Jul 2012
    From
    UK
    Posts
    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?
    Follow Math Help Forum on Facebook and Google+

  7. #7
    MHF Contributor
    Joined
    Dec 2007
    From
    Ottawa, Canada
    Posts
    3,113
    Thanks
    68

    Re: Find Rectangle

    Quote Originally Posted by daveywavey View Post
    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?
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Newbie
    Joined
    Jul 2012
    From
    UK
    Posts
    6

    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.
    Follow Math Help Forum on Facebook and Google+

  9. #9
    MHF Contributor
    Joined
    Dec 2007
    From
    Ottawa, Canada
    Posts
    3,113
    Thanks
    68

    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
    Follow Math Help Forum on Facebook and Google+

  10. #10
    Newbie
    Joined
    Jul 2012
    From
    UK
    Posts
    6

    Re: Find Rectangle

    Thanks Wilmer thats very succint, thanks!
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 2
    Last Post: June 28th 2012, 07:07 AM
  2. Find the area of the rectangle
    Posted in the Algebra Forum
    Replies: 3
    Last Post: May 25th 2011, 09:37 PM
  3. How to find the Rectangle Intersection
    Posted in the Geometry Forum
    Replies: 3
    Last Post: June 2nd 2009, 06:07 PM
  4. find x in this rectangle
    Posted in the Geometry Forum
    Replies: 2
    Last Post: April 4th 2009, 05:37 AM
  5. Find Rectangle Dimensions
    Posted in the Pre-Calculus Forum
    Replies: 2
    Last Post: July 30th 2008, 02:21 PM

Search Tags


/mathhelpforum @mathhelpforum