62,636
社区成员




import java.awt.Point;
public class Main {
public static void main(String args[]){
RectangeDemo r1 = new RectangeDemo(new Point(1,2),5,5);
RectangeDemo r2 = new RectangeDemo(new Point(10,8),5,5);
checkRelation(r1,r2);
}
static class RectangeDemo{
Point center;
double width;
double height;
public RectangeDemo(Point point, int width, int height) {
this.center = point;
this.width = width;
this.height = height;
}
}
public static void checkRelation(RectangeDemo r1,RectangeDemo r2){
if(Math.abs(r1.center.x -r2.center.x) > r1.width/2 + r2.width/2
&& Math.abs(r1.center.y -r2.center.y) > r1.height/2 + r2.height/2 ){
System.out.println("相离");
}
else if(Math.abs(r1.center.x - r2.center.x) < Math.abs(r1.width/2 - r2.width/2)
&& Math.abs(r1.center.y -r2.center.y) > Math.abs(r1.height/2 - r2.height/2)){
System.out.println("包含");
}
else{
System.out.println("相交");
}
import java.awt.Point;
public class Main {
public static void main(String args[]){
RectangeDemo r1 = new RectangeDemo(new Point(1,2),5,5);
RectangeDemo r2 = new RectangeDemo(new Point(10,8),5,5);
checkRelation(r1,r2);
}
static class RectangeDemo{
Point center;
double width;
double height;
public RectangeDemo(Point point, int width, int height) {
this.center = point;
this.width = width;
this.height = height;
}
}
public static void checkRelation(RectangeDemo r1,RectangeDemo r2){
if(Math.abs(r1.center.x -r2.center.x) > r1.width + r2.width
&& Math.abs(r1.center.y -r2.center.y) > r1.height + r2.height ){
System.out.println("相离");
}
else if(Math.abs(r1.center.x - r2.center.x) < Math.abs(r1.width - r2.width)
&& Math.abs(r1.center.y -r2.center.y) > Math.abs(r1.height - r2.height)){
System.out.println("包含");
}
else{
System.out.println("相交");
}
}
}