[英]Scale rotated rectangle to fit inside bounding box
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的边界框中
I assume that nBW / nBH ratio may differ from ideal one. 我认为nBW / nBH比可能与理想值不同。 So you have to choose minimal value from Vertical/Horizontal coefficients to fit rotated rectangle properly. 因此,您必须从“垂直/水平”系数中选择最小值以正确适合旋转的矩形。
CoeffH = nbW / cBW
CoeffV = nbH / cBH
Coeff = Min(CoeffH, CoeffV)
Now multiply linear sizes by Coeff. 现在将线性大小乘以Coeff。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.