public static void main(String[] args) {
checkOverLap checkOverLap = new checkOverLap();
System.out.println(checkOverLap.souluteTool(1,1,1,1,2,-3,-1));
}
public boolean souluteTool(int radius, int x, int y, int x1, int x2, int y1, int y2) {
// 1. 判断哪一点到圆心最近
double distance = 10 * 10 * 10 * 10;
for (int i = x1; i <= x2; i++) {
for (int k = y1; k <= y2; k++) {
int distance1 = Math.abs(x-i) * Math.abs(x-i) + Math.abs(y-k) * Math.abs(y-k);
double distance2 = Math.sqrt(distance1);
我觉得你这个方法效率有点低,步长是1,误差大
这个题就几种情况,判断一下比穷举快一些
1,圆心在矩形内,ture
2,圆心在矩形外,且x_c+r<x1 or y_c+r<y1 or x_c-r > x2 or y_c-r>y2, false
3, 圆与部分矩形相交,这个稍复杂些,就是写的多点,但肯定比穷举快