我寫了這個函數來檢查兩個重疊元素
(它們是矩形的),
如下面的第一張圖所示。使用javascript檢查重疊圓形元素的函數?
問題是,我想使用圓形elelemts, 如下面的第二張圖所示。
所以我想我需要添加一些Math.PI和半徑計算, 希望得到任何幫助......
var checkOverlap = function (a, b) {
if (
((a.left < b.left && a.left + a.width > b.left) ||
(a.left > b.left && a.left + a.width < b.left + b.width) ||
(a.left > b.left && a.left + a.width > b.left + b.width)) &&
((a.top < b.top && a.top + a.height > b.top) ||
(a.top > b.top && a.top + a.height > b.top) ||
(a.top > b.top && a.top < b.top + b.height)) &&
(a.left < b.left + b.width) &&
(a.top < b.top + b.height)
) {
return true;
}
};
正確的金錢,謝謝。 –