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,

  • $\begingroup$ If I have understood your question. it suffices to preserve the ratio H/W=0.56. $\endgroup$
    – user
    Jun 25, 2018 at 21:05
  • $\begingroup$ @gimusi Yes. The canvas ratio should be the selected ratio. $\endgroup$
    – Roi Mulia
    Jun 25, 2018 at 21:06
  • $\begingroup$ What is your fixed dimension for H or W or for the Area? $\endgroup$
    – user
    Jun 25, 2018 at 21:07
  • $\begingroup$ 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. $\endgroup$ Jun 25, 2018 at 21:07
  • $\begingroup$ 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) $\endgroup$
    – Roi Mulia
    Jun 25, 2018 at 21:08

1 Answer 1


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$.
  • $\begingroup$ I tried for hours to solve it, but i just saw that you said y' / x' = r, where I tried the opposite lol. Thank you sir! $\endgroup$
    – Roi Mulia
    Jun 26, 2018 at 9:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .