I have three rectangles of different sizes side by side.

I want to scale them all (maintaining their aspect ratio) so they have the same height and don't exceed a total width.

I know I could find the optimal height by trial and error, but I'd like to find a formula that will work no matter what the sizes of the rectangles.

Can anyone point me in the right direction?


First, scale them all to the same height (tallest, first, some constant).
Second, add the (new) widths and divide the sum by the desired total width.
Third, scale them all by the inverse of this factor.


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.