我有这三种方法来检查一个圆是否在另一个圆内,除了相交的圆被标记为内部和相交之外,一切正常。我一直在阅读文章,但建议的选项似乎都无法使其正常工作。这是我的方法:
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;
}
}