# Re-Calculate Rectangle Width/Height After Translating One Coordinate

I'm trying to put resizing handles on the four corners of a rectangle, which can be dragged to resize the rectangle. What I'm having trouble with is calculating the new width, new height, and new points of the rectangle after I've translated one of the rectangle's points.

If the rectangle were not rotated, this would obviously be very easy because the width and height would change by the same amount as the offset on the x-axis and offset on the y-axis of the newly translated point. However, this rectangle CAN be rotated, so the translation of x and y don't match up directly to the changes in width/height. In the image above, I've represented information that I already have in solid black, and information I want to find in light grey. I've tried to show how the rectangle should change if I dragged the a1 corner up and to the right.

Could anyone help me figure out how to calculate the missing information?

Thanks for any help! It's much appreciated.

• Just one thing , a2 is known to us right ? – abkds Dec 4 '13 at 5:08
• @TrafalgarLaw yes, a2 is known. – Nick Budden Dec 4 '13 at 5:13
• I have written the answer . Have you checked it out ? – abkds Dec 4 '13 at 13:10
• @trafalgarlaw sorry opposite time zones, jut waking up, going to try it out this morning. – Nick Budden Dec 4 '13 at 13:26

Since we know the co-ordinates $a_1,b_1,c_1,d_1$ and $a_2$ and we have to find the co-ordinates of $b_2$ and $d_2$
Find the equation of the line passing from $d_1$and $c_1$ . Let $d_2$ be $(m,n)$ . Now $(m,n)$ satisfies the line formed by $d_1$and $c_1$ . Put it in the equation you will get one equation .
Now the line $a_2d_2$ is $\bot$ to $d_1c_1$ . Put the slope of line $a_2b_2$ multiplied to $d_1c_1$ = $-1$ . Therefore you will get two equations in $m,n$ and solve for them you will get the required value .
Repeat a similar excercise for $b_2$ .