[英]Calculation of maximum rectangle size, arbitrary rotated, to fit within bounding box
[英]Scale rotated rectangle to fit inside bounding box
因此,我具有适用于非旋转矩形的调整大小功能,但我也需要使其适用于旋转矩形。.所以我的想法是调整旋转矩形的边界框的大小,然后将旋转矩形放入内部。我无法弄清楚..这是我拥有的变量:
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
所以我需要将旋转的矩形放入尺寸为nBW * nBH的边界框中
我认为nBW / nBH比可能与理想值不同。 因此,您必须从“垂直/水平”系数中选择最小值以正确适合旋转的矩形。
CoeffH = nbW / cBW
CoeffV = nbH / cBH
Coeff = Min(CoeffH, CoeffV)
现在将线性大小乘以Coeff。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.