查找旋转矩形的角 [英] Find corners of a rotated rectangle
问题描述
我正在尝试调整旋转矩形的大小,只需将图像从1个角拖出(或拖入),该1个角的对角线将保持在原来的位置.
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.
所以我知道旋转的角度(弧度)和彼此对角的2个角,现在我想找到另外两个角.
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.
我试图用三角法计算em,但我失败了,所以如何计算其他2点.
I've tried to calculate em with Trigonometry but I failed miserably, so how can u calculate those other 2 points.
推荐答案
使用伪代码:
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)
这是在恢复旋转的矩形边的长度r
,然后使用该长度来计算其他两个点应相对于您已经拥有的两个点的位置.
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.
这篇关于查找旋转矩形的角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!