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
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.
CoeffH = nbW / cBW
CoeffV = nbH / cBH
Coeff = Min(CoeffH, CoeffV)
Now multiply linear sizes by Coeff.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.