Find corners of a rotated rectangle

空扰寡人 提交于 2020-01-03 03:01:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!