3 回答

TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊
我意識到你要求ActionScript,但是,如果有人來到這里尋找iOS或OS-X答案,它是這樣的:
+ (CGRect) boundingRectAfterRotatingRect: (CGRect) rect toAngle: (float) radians{ CGAffineTransform xfrm = CGAffineTransformMakeRotation(radians); CGRect result = CGRectApplyAffineTransform (rect, xfrm); return result;}
如果您的操作系統(tǒng)為您提供了所有艱苦的工作,那就試試吧!:)
迅速:
func boundingRectAfterRotatingRect(rect: CGRect, toAngle radians: CGFloat) -> CGRect { let xfrm = CGAffineTransformMakeRotation(radians) return CGRectApplyAffineTransform (rect, xfrm)}

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊
MarkusQ概述的方法非常有效,但請記住,如果已經(jīng)有A點(diǎn),則不需要轉(zhuǎn)換其他三個(gè)角。
另一種更有效的方法是測試旋轉(zhuǎn)角度所在的象限,然后直接計(jì)算答案。這樣做效率更高,因?yàn)槟阒挥袃蓚€(gè)if語句的最壞情況(檢查角度),而另一個(gè)方法的最差情況是12個(gè)(當(dāng)檢查其他三個(gè)角以查看它們是否大于當(dāng)前時(shí),每個(gè)組件為6個(gè))我認(rèn)為最大或小于當(dāng)前最小值。
基本算法僅使用了畢達(dá)哥拉斯定理的一系列應(yīng)用,如下所示。我用theta表示了旋轉(zhuǎn)角度,并以度為單位表示檢查,因?yàn)樗莻未a。
ct = cos( theta );st = sin( theta );hct = h * ct;wct = w * ct;hst = h * st;wst = w * st;if ( theta > 0 ){ if ( theta < 90 ) { // 0 < theta < 90 y_min = A_y; y_max = A_y + hct + wst; x_min = A_x - hst; x_max = A_x + wct; } else { // 90 <= theta <= 180 y_min = A_y + hct; y_max = A_y + wst; x_min = A_x - hst + wct; x_max = A_x; }}else{ if ( theta > -90 ) { // -90 < theta <= 0 y_min = A_y + wst; y_max = A_y + hct; x_min = A_x; x_max = A_x + wct - hst; } else { // -180 <= theta <= -90 y_min = A_y + wst + hct; y_max = A_y; x_min = A_x + wct; x_max = A_x - hst; }}
這種方法假設(shè)你擁有你所說的你所擁有的東西,即A點(diǎn)和theta的值,它位于[-180,180]的范圍內(nèi)。我還假設(shè)theta在順時(shí)針方向上增加,因?yàn)樵趫D中旋轉(zhuǎn)了30度的矩形似乎表明你正在使用,我不確定右邊的部分試圖表示什么。如果這是錯(cuò)誤的方法,那么只需交換對稱子句以及st術(shù)語的符號。
添加回答
舉報(bào)