0
我有這三種方法來檢查一個圓是否在另一個圓內,除了相交圓標記爲內部和相交。我一直在閱讀文章,但沒有任何建議的選項似乎使其正常工作。這裏是我的方法:試圖檢查一個圓是否與第二個圓重疊,位於第二個圓之內或之外
public boolean isInside(Circle c2) {
// get the distance between the two center points
double distance = Math.sqrt((x - c2.x) * (x - c2.x) + (y - c2.y) * (y - c2.y));
// check to see if we are inside the first circle, if so then return
// true, otherwise return false.
if (distance <= ((radius) + (c2.radius))) {
System.out.println(distance);
return true;
} else {
return false;
}
}
public boolean isOutside(Circle c2) {
double distance = Math.sqrt((x - c2.x) * (x - c2.x) + (y - c2.y) * (y - c2.y));
if (distance > ((radius) + (c2.radius))) {
System.out.println(distance);
return true;
} else {
return false;
}
}
public boolean isIntersecting(Circle c2) {
double distance = Math.sqrt((x - c2.x) * (x - c2.x) + (y - c2.y) * (y - c2.y));
if (Math.abs((radius - c2.radius)) <= distance && distance <= (radius + c2.radius)) {
System.out.println(distance);
return true;
} else {
return false;
}
}
稀釋是,就是這樣,完美!非常感謝! – Kynian
沒問題,很高興幫助。 –