定义一个平面中的Circle类
代码:
public class Point {
double x,y,r;
public Point() {
this.x=0;
this.y=0;
this.r=1;
}
public Point(double x, double y, double r) {
this.x = x;
this.y = y;
this.r = r;
}
public boolean overlap(Point p) {
return Math.sqrt((p.x-this.x)*(p.x-this.x)+(p.y-this.y)*(p.y-this.y))<(p.r+this.r);
}
public static void main(String[] args) {
Point p1=new Point();
Point P2=new Point(1,1,0.5);
Point P3=new Point(3,8,1);
System.out.println(p1.overlap(P2));
System.out.println(p1.overlap(P3));
System.out.println(P2.overlap(P3));
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
运行结果:
true
false
false