Resizing Handles On A Rotated Element
Solution 1:
http://en.wikipedia.org/wiki/Cartesian_coordinate_system#Distance_between_two_points gives you the method for finding the length of a1 to a2
var len=Math.sqrt(Math.pow(a2x-a1x,2)+Math.pow(a2y-a1y,2));
Then looking at the triangle formed by the intersection of the grey and black lines (Lets call that point H) and a1 and a2. You can use trigonometry to solve. So the angle formed by the line d1 to c1 with the bottom lets call that the angle of rotation(R). That means the R is equal to angle at a2 and the angle at a1 is equal to 90-R. To find the sides then you go
//line from a2 to H var hDif=Math.sin(R)*len;
//line from a1 to Hvar wDif=Math.cos(R)*len;
You can then use these to find the new length and height. There will a few more calculations to see if you are adding or subtracting to the old width and height.
Solution 2:
I have another idea:
Consider that your rectangle is rotated by 30 degress anticlockwise with respect to the origin.
When the user clicks on one of the edges or corners, do the following:
1) Let StartPt = the point where the mouse starts. 2) Get the point where the mouse moves to. Let it be EndPt. 3) Rotate each of the vertex of the Rectangle by -30 so that now it becomes an unrotated rectangle. (Do not draw the unrotated rectangle, it is for calculcation purpose only) 4) Rotate the StartPt and EndPt by -30 degrees. Calculate the change in the width and height of the rectangle when the point. 5) Add the change to the rotated vertices of the rectangle. 6) Rotate the vertices of the Rectangle by +30 degrees. Now draw the Rectangle.
Post a Comment for "Resizing Handles On A Rotated Element"