请按照下图操作:
我想转换一个以 anchor 为中心的矩形,从 P1 点到 P1' 点。
我想计算旋转后的边界矩形。
我使用的解决方案是获得新的 4 点:P1 => P1' 和 P2 => P2' 等等... 但问题是:矩形(我希望得到)更大。 请告诉我正确获取它的方法。
谢谢。
最佳答案
left = min (Pi'.X for 1<=i<=4)
bottom = min (Pi'.Y for 1<=i<=4)
right = max (Pi'.X for 1<=i<=4)
top = max (Pi'.Y for 1<=i<=4)
width = top - bottom
height = right - left
bounding_rectangle = [left, bottom, width, height]
更新:
将点 p
围绕 center
旋转 angle
弧度:
v.x = p.x - center.x
v.y = p.y - center.y
newp = center.x + cos(angle) * v.x - sin(angle) * v.y, center.y + sin(angle) * v.x + cos(angle) * v.y
将此应用于每个 Pi 你得到 Pi'
关于c++ - 从P1到P1'的角旋转后如何得到边界矩形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5619448/