作业帮 > 综合 > 作业

这个用 “java条件语句”该怎么写?

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/01 14:36:57
这个用 “java条件语句”该怎么写?
平面上的两矩形物体左上角坐标分别为(x,y)和(x1,y1),两物体的宽高分别为(w,h)和(w1,h1),写出两物体在平面有重叠(部分重叠也算)的判定条件.
给个最简单的碰撞检测你:
public Rectangle getRect() {
return new Rectangle(x,y,w,h);
}
public Rectangle getRect1() {
return new Rectangle(x1,y1,w1,h1);
}
if (this.getRect().intersects(this.getRect1())) { }
再问: 我是java新手,只刚学到条件语句--!
再答: 好的,那我给个只有if else的你: public class Temp { public static void main(String[] args) { int temp=0; temp = new Temp().getreturn(); if(temp == 1) { System.out.println("两个平面相交!"); } else { System.out.println("两个平面不相交!"); } } public int getreturn() { double x=0, y=0, x1=0, y1=0, w=0, h=0, w1=0, h1=0; if(x >= x1) { if(y >= y1) { if(x1 + w1 >= x && y1 + h1 >= y) { return 1; } } else { if(x1 + w1 >= x && y + h >=y1) { return 1; } } } else { if(y >= y1) { if(x + w >= x1 && y1 + h1 >= y) { return 1; } } else { if(x + w >= x1 && y + h >= y1) { return 1; } } } return 0; } } 至于那些x,y,w,h的取值,你重新取吧。