用我的眼睛,我可以立即確定一個物體是位于盒子的上半部分還是下半部分。

馬上就會說白盒位于藍盒的下部。
但是我怎樣才能以有效的方式計算呢?
我是否將藍色盒子分成上半部分和下半部分,然后為白色盒子和兩個部分創建相交的矩形,然后看看哪個相交的矩形是體積最大的?
謝謝!
謝謝!
uj5u.com熱心網友回復:
您的方法很好,也是最好的,Windows API 可以幫助我們。代碼比自己撰寫所有需要的比較更簡單。
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
Private Sub Command1_Click()
Dim UpperArea As RECT
Dim LowerArea As RECT
Dim WhiteBox As RECT
Dim IntersectUpper As RECT
Dim IntersectLower As RECT
'define rectangles for upper area, lower area, and the white box
SetRect UpperArea, Frame1.Left, Frame1.Top, Frame1.Left Frame1.Width, Frame1.Top (Frame1.Height * 0.5)
SetRect LowerArea, Frame1.Left, Frame1.Top (Frame1.Height * 0.5), Frame1.Left Frame1.Width, Frame1.Top Frame1.Height
SetRect WhiteBox, Frame2.Left, Frame2.Top, Frame2.Left Frame2.Width, Frame2.Top Frame2.Height
'check where the white box is located
If IntersectRect(IntersectUpper, UpperArea, WhiteBox) > 0 Or IntersectRect(IntersectLower, LowerArea, WhiteBox) > 0 Then
If IntersectUpper.Bottom - IntersectUpper.Top > IntersectLower.Bottom - IntersectLower.Top Then
MsgBox "More in the upper"
Else
MsgBox "More in the lower"
End If
Else
MsgBox "Outside the box"
End If
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/431639.html
上一篇:回傳Nan的向量之間的角度
