![](/img/trans.png)
[英]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.