Search code examples
mathgeometrycomputational-geometry

Resize a Rectangle in a Percent while maintaining its aspect ratio


I would like to resize the rectangle area by 50% Rect1 w1 x h1, I do not want to resize the width or height directly in half, because that gives me an area of 25%, what I need is find an equivalent rectangle, in aspect ratio, having an area equal to% 50 of the original. therefore what I need is to find the h2 x w2 of rectangle Rect2.

I have Rect1: w1, h1, a1 And I also have Rect2: a2

I need w2 and h2 (keeping the aspect ratio of Rect1)

Image


Solution

  • asuming your rectangle is definded by w1 and w2 just like in your picture, it follows:

    area = w1 * h1
    

    you want a rectangle with half the area but same aspect ratio, so there must be a divisor (d) that reduces w1 and w2 equally to result in the new area which is cut in half:

    area * 1/2 = (d * w1) * (d * h1)
    

    some simple math:

    d * w1 * d * w1 = w1 * h1 * 1/2
    => d * d = 1/2
    => d = sqrt(1/2)
    

    so the factor to reduce the rectangle and keep the proportions is sqrt(1/2)

    Example:

    w1 = 4, h1 = 3
    
    4 * 3 = 12
    
    => d * 4 * d *3 = sqrt(1/2) * 4 * sqrt(1/2) * 3 = 6