The task is essentially simple (or maybe it seems to me), but something I can’t think of any algorithm for now. In general, you need to find the new dimensions of the inner rectangle contained in another whose dimensions change arbitrarily.

The dimensions of the outer and inner rectangle and the magnitude of the change in the outer are known. None of the rectangles is rotated - the sides of all the rectangles are always parallel to each other.

To clarify illustrate enter image description here

What are the solutions?

  • And why the dimensions of the inner rectangle did not remain the same? - VladD
  • @VladD it doesn’t matter, the inner rectangle will change in proportion to the outer one - ampawd
  • 2
    If the inner changes in proportion to the outer, you can count the change in the external ((W + a) / W, (H + b) / H). Then multiply w1, h1 by the obtained values. - Tolkachev Ivan
  • @VladD Ie if the width of the external one is changed to some value, then the width of the internal one also changes to some specific value, but to which one? the whole question is this (and the same with height) - ampawd

1 answer 1

w2=w1*(W+a)/W 

Similarly for height

PS I am sorry, the answer is already there (I did not notice the decision in the comments)

  • Can you explain to this formula? - ampawd
  • one
    Tolkachev Ivan explained in his commentary - vikttur