0
$\begingroup$

I have a rectangle with more than 800 width and 600 height. It can be 1000 x 600, 2000 x 1000 and etc. I want to scale it to 800 x 600. I want to determine which one matches first, the height or the width and also get the other value that didn't meet first.

|                |
|  |800x600   |  |
|  |inners rec|  |
|                |outer rectangle(1000 x 1000) if I resize which one will hit the boundaries of the inner rectangle left and right or top and bottom.

updated

I used the term square When it should be rectangle.

$\endgroup$
  • $\begingroup$ Look at the ratios of width to width or height to height. Pick the larger or smaller one, depending on your numerator and denominator. $\endgroup$ – Michael Burr Sep 13 '17 at 14:07
  • $\begingroup$ Your comment ins an answer in its own right: "Look at the ratios of width to width or height to height. Pick the larger or smaller one". $\endgroup$ – Diego Alves Sep 13 '17 at 15:39
0
$\begingroup$

Take the ratio in each axis and use the smaller one. So if you start with $2000 \times 1000$ the horizontal is $\frac {800}{2000}=0.4$, the vertial is $\frac {600}{1000}=0.6$. So you scale by a factor $0.4$ and the vertical is $0.4 \cdot 1000=400$. These are rectangles, not squares.

$\endgroup$
  • $\begingroup$ That's exactly what I wanted! \o/. Great answer! $\endgroup$ – Diego Alves Sep 13 '17 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.