# Calculate bounding size to fit rectangle

I hope I have phrased my question correctly.

Let's assume I have a rectangle with a width and height of X and Y.
Then I pick an aspect ratio of 0.56.
How can I calculate the size of the rectangle that bounds the original rectangle, without shrinking it?

In other words, I want to keep the original rectangle as is, and "place" it inside a canvas that obeys the aspect ratio, I'm trying to calculate the canvas size.

Any help would be highly appreciated.

Best regards,
Roi

• If I have understood your question. it suffices to preserve the ratio H/W=0.56. – user Jun 25 '18 at 21:05
• @gimusi Yes. The canvas ratio should be the selected ratio. – Roi Mulia Jun 25 '18 at 21:06
• What is your fixed dimension for H or W or for the Area? – user Jun 25 '18 at 21:07
• Assuming you have aspect ratio is height over width, then I think you would need a rectangle of size $\max(X, Y/0.56)\times\max(Y,0.56 X)$. See if that works. – Adrian Keister Jun 25 '18 at 21:07
• The fixed dimension is the source rectangle (I'm building an app, the source rectangle is the video rectangle which I'm trying to "fit" inside a canvas) – Roi Mulia Jun 25 '18 at 21:08

Let $x, y$ be the dimensions of the window that you want to fit into a canvas with aspect ratio $r$. Let the desired dimensions of the canvas be $x', y'$. In all cases, we must have $y'/x' = r$. Three cases:
• if $y/x = r$, then both dimensions fit just right: let $x' = x, y' = y$.
• if $y/x > r$, the rectangle is tall, so we fit the y-dimension: $y' = y$ and since $y'/x' = r$, we have $y/x' = r \implies x'= y/r$.
• if $y/x < r$, then we fit the x-dimension: $x' = x$ and since $y'/x' = r$, we have $y'/x = r \implies y' = xr$.