flex 矩形碰撞

2021-08-26 06:23:03 字數 974 閱讀 2880

先上圖:

[img]

應用:判斷乙個canvas所覆蓋區域中所有控制項(相交包含) 當然這個canvas漂浮在其他控制項之上的

案例分析:

[img]

矩形 rectangle1 的 中心座標 (x1,y1)

矩形 rectangle2 的 中心座標 (x2,y2)

1.相交的情況也就是兩個 矩形的中心座標垂直間距=x2-x1

2.如果小於這個間距就表示已經相交,如果大於這個間距就表示沒有相交

當然判斷座標的方法寫起來有點煩

可以使用flex rectangle 內建的方法判斷,問題就解決了

var secondrect1:rectangle = new rectangle(x, y, width, height);

var secondrect2:rectangle = new rectangle(x, y, width, height);

//構造乙個矩形

secondrect1.containsrect(secondrect2)

//判斷乙個矩形(secondrect2)是否完全在包含在另乙個矩形(secondrect1)中

下面是兩個矩形相交的情況處理

var temp:rectangle=secondrect1.intersection(secondrect2);

//當然返回是相交部分不用是說是乙個矩形

[img]

public function intersection(tointersect:rectangle):rectangle

如果在 tointersect 引數中指定的 rectangle 物件與此 rectangle 物件相交,則返回交集區域作為 rectangle 物件。如果矩形不相交,則此方法返回乙個空的 rectangle 物件,其屬性設定為 0。 要排除為0的情況也就是

if(temp!=null&&temp.width!=0&&temp.height!=0)

2021 03 16 矩形的碰撞

矩形的碰撞 標頭檔案 ifndef rectangle h define rectangle h class crctangle endif矩形cpp檔案,實現矩形是否碰撞。原理 矩形的中心點距離與兩矩形長或寬的一半之和比較。include rectangle.h include using nam...

矩形和圓碰撞 方法

arcx,arcy表示圓的繪製座標,就是左上角座標 arcr為圓半徑 rectx,recty,rectw,recth分別表示矩形的繪製座標與寬高 private static final boolean isarcrectcollides int arcx,int arcy,int arcr,int...

矩形與圓碰撞檢測

說下演算法思想。判斷三種情況。1.矩形四個頂點在圓內。2.判斷圓的內接正方形與矩形是否碰撞 3.判斷圓上的水平左右 豎直上下四個點是否在矩形內。其中1比較簡單,只需比較點到圓心距離與圓半徑即可。3也簡單,判斷點是否在矩形內的思想是,若點在矩形內,則任意選定矩形四個頂點中的乙個與該點連線,其他3點必不...