Scale a rectangle by a percentage

geometry

I'm doing something in a computer program and I feel like this has an easy math answer but it is eluding me for one reason or another. I have an image that is rather large and I am making a copy of it and scaling it down by 50% then performing calculations upon it that yields a rectangle that corresponds to an area inside of the smaller image. I would then like to scale this rectangle up so that it's correctly resized for the image that is 50% bigger.

I actually have this working by calculating the percentage difference in size and converting that to pixels and then adding this value times 2 to the height and width, however the scaling factor is fixed at 2 which correlates to the 50% reduction.

So I think my question is how do I calculate that scaling factor, but I may have the terminology wrong and thus what I am wanting is a formula/explanation for increasing the rectangle by the proper amount so that it matches the bigger image. As for where the rectangle is, in terms of position in the xy coordinates doesn't matter here as I am finding it by calculating the percentages for both images.

What I'd like is a generic way of expressing this but I am missing something easy in the math. Thanks.

Best Answer

Drop percentages and replace them with ordinary fractions.

Suppose you have an image 1000 units wide. If you scale it down to 50% of its original size, you scale it by factor $\frac 12$, and get an image 500 units wide.

If you want to scale it up to the original size, that is from 500 units back to 1000, you need to scale it by $2 = 1/\tfrac 12$
This is actually making the image 200% of the decreased size or, equivalently, increasing by 100% – but certainly not '50% bigger'!

Related Question