Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have 2 rectangles that can scale in size. They both scale from there own center point. The blue rect can be positioned any where on the canvas.

enter image description here

After upscaling I get something like this.

enter image description here

However I want the blue rectangle to respect its original position relative to the red rectangle. So my question is what formula can I use to correct the blue rectangle position. The Image below reflects the corrected position.

enter image description here

The following values are given. The position(X), width(A) and height(B) of the red rectangle. The position(Y), width(C) and height(D) of the red rectangle.

share|improve this question
    
From the drawings it looks like the distance between the centers stays the same after the transformation is applied. Is this the case? –  Abramo Dec 10 '13 at 11:05
    
The rectangles scale from there centers so yes the distance between the centers stay the same in the first transformation. However after the scaling I want to do a new transformation thats sets to the position of the blue rect to relatively the same position as it was. –  Baijs Dec 10 '13 at 11:54
    
It's not clear what "respect the original position" means for you. You want to keep fixed the distance between the boundaries? –  Emanuele Paolini Dec 10 '13 at 12:15

1 Answer 1

up vote 2 down vote accepted

Let $x$ and $y$ denote the centers of $X$ and $Y$, respectively. The vector connecting them can be computed as $$ v = y-x. $$ If $s$ is the scaling factor, to achieve what you need you just need to modify the center of $Y$, namely replacing $y$ with the new center $$ a + s\cdot v = (a_1, a_2) + (s\cdot v_1,\; s\cdot v_2). $$ See the pictures below for the geometric intuition.

Original After scaling After the fix

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.