I need a formula to scale a rectangle to fit into a bigger/wider rectangle. I only need to worry on the small rectangle.
The given values only I have are:
Big rectangle:
Small rectangle:
Values are relative to screen pixels.
Find
a = width1 / height1;
b = width2 / height2;
if(a>b)
{
scale = height1 / height2;
point.y = y; (from big rectangle)
point.x = (width1 - width2 * scale) / 2 + x;
}
else
{
scale = width1 / width2;
point.x = x; (from big rectangle)
point.y = (height1 - height2 * scale) / 2 + y;
}
From what I understand, this should do what you wanted.
Edit: See PureW answer for getting the scale only.