So I have resize functionality which works on non-rotated rectangles, but I need to make it work on rotated ones too.. So my idea is to resize the bounding box of a rotated rectangle and then fit the rotated rectangle inside.. Unfortunately, I can't figure it out.. Here are the variables which I have:
所以我调整了非旋转矩形的功能,但是我需要让它在旋转的矩形上工作。所以我的想法是调整旋转矩形的边界框然后将旋转的矩形调整到内部..不幸的是,我无法弄清楚..以下是我的变量:
cW = currentRotatedRectangleWidth
cH = currentRotatedRectangleHeight
rad = angleOfRotation
cBW = currentRotatedRectangleBoundingWidth
cBW = Math.abs(cH * Math.sin(rad)) + Math.abs(cW * Math.cos(rad))
cBH = currentRotatedRectangleBoundingHeight
cBH = Math.abs(cH * Math.sin(rad)) + Math.abs(cW * Math.cos(rad))
nBW = newBoundingWidth
nBH = newBoundingHeight
dx = differenceWidth = (cBW - cW) / 2
dy = differenceHeight = (cBH - cH) / 2
So I need to fit the rotated rectangle into the bounding box with dimensions nBW * nBH
所以我需要将旋转的矩形拟合到尺寸为nBW * nBH的边界框中
1 个解决方案
#1
0
I assume that nBW / nBH ratio may differ from ideal one. So you have to choose minimal value from Vertical/Horizontal coefficients to fit rotated rectangle properly.
我假设nBW / nBH比率可能与理想值不同。因此,您必须从垂直/水平系数中选择最小值,以适当地调整旋转矩形。
CoeffH = nbW / cBW
CoeffV = nbH / cBH
Coeff = Min(CoeffH, CoeffV)
Now multiply linear sizes by Coeff.
现在用Coeff乘以线性尺寸。
#1
0
I assume that nBW / nBH ratio may differ from ideal one. So you have to choose minimal value from Vertical/Horizontal coefficients to fit rotated rectangle properly.
我假设nBW / nBH比率可能与理想值不同。因此,您必须从垂直/水平系数中选择最小值,以适当地调整旋转矩形。
CoeffH = nbW / cBW
CoeffV = nbH / cBH
Coeff = Min(CoeffH, CoeffV)
Now multiply linear sizes by Coeff.
现在用Coeff乘以线性尺寸。