円が別の円の内側にあるかどうかを確認するこれらの 3 つの方法があります。交差する円が内側と交差しているとマークされているという事実を除いて、すべてが機能します。私は記事を読んできましたが、提案されたオプションのどれも正しく機能していないようです。ここに私の方法があります:
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;
}
}