Re-Calculate Rectangle Width/Height After Translating One Coordinate

988 Views Asked by At

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.

enter image description here

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.

1

There are 1 best solutions below

0
On BEST ANSWER

Okay ,

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$ .

I assume you know how to find the slope and equation of the line when two points are given .