问题
I'm trying to resize a rotated rectangle, you just drag the image out (or in) from 1 corner, and the corner diagonal of that 1 will stay in the old position.
So I know the angle(radians) of rotation and 2 corners diagonal of each other, now I would like to find the other two corners.
I've tried to calculate em with Trigonometry but I failed miserably, so how can u calculate those other 2 points.
回答1:
In pseudocode:
r = (x2 - x1)*sin(a) - (y2 - y1)*cos(a)
x3 = x1 + r*sin(a)
y3 = y1 - r*cos(a)
x4 = x2 - r*sin(a)
y4 = y2 + r*cos(a)
What this is doing is recovering the length r
of the side of the rotated rectangle, then using that length to calculate where the two other points should be, relative to the two points that you have already.
来源:https://stackoverflow.com/questions/9447749/find-corners-of-a-rotated-rectangle