java判断两个矩形是否相交_如何检查两个矩形几何形状之间的空间关系中使用Java...

如果测试矩形为参考矩形

如果测试矩形内被重叠的基准矩形

如果测试矩形仅与参考矩形

IF测试矩形和参考矩形是不同的共享边界

参考矩形和测试矩形都以其中心坐标(x,y)及其宽度和高度定义。

我相信我有正确的第一个检查编码,但我无法弄清楚重叠,共享边界和完全不同的最后三个检查的数学。

这里是我的四个检查,到目前为止的代码:

//returns true if the specified rectangle is inside this rectangle

public boolean contains(MyRectangle2D r){

if(this.x > r.x + r.width && x + width < r.x && y > r.y +r.height && y + height < r.y){

return true;

}

else{

return false;

}

}

//returns true if the specified rectangle overlaps with this rectangle

public boolean overlaps(MyRectangle2D r) {

if (this.x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y){

return true;

}

else{

return false;

}

}

//returns true if only the boundaries touch

public boolean abut(MyRectangle2D r) {

if(this.x = r.x + r.width && x + width = r.x || y = r.y +r.height && y + height = r.y){

return true;

}

else{

return false;

}

}

//returns true if the rectangles are not touching at all

public boolean distinct(MyRectangle2D r) {

}

2016-08-06

S Zapata

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值