java - 相交算法与 Rectangle.intersects(Rectangle r) 的区别

标签 java collision-detection

我去的论坛上有人说我不应该使用 Rectangle.intersects 进行碰撞检测,而应该使用这个算法:

boolean rectangleIntersects(float rect1x, float rect1y, float rect1w, 
                            float rect1h, float rect2x, float rect2y, 
                            float rect2w, float rect2h)
{
    return (rect1x + rect1w >= rect2x &&
            rect1y + rect1h >= rect2y &&
            rect1x <= rect2x + rect2w &&
            rect1y <= rect2y + rect2h);
}

但是 Rectangle.intersects 算法不是有所不同,而且比这个更好吗?

最佳答案

Rectangle.intersects is basically the same只不过您的算法使用 float 而不是 double 并包含边界的相等条件。

关于java - 相交算法与 Rectangle.intersects(Rectangle r) 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4270572/

相关文章:

java - 多个JAVA JDK启动Elasticsearch服务的方法

java - Android 有什么更好的?定时器还是闹钟?

java - 在调用其他方法时调用一个方法

java - Android布局中string.xml中的字符串格式

java - Nifi 定制处理器显示错误 "the local variable flowfile cannot be assigned"

java - 旋转矩形中的碰撞检测

c - 开放寻址冲突解决

Swift Sprite 套件碰撞位掩码

c++ - 游戏碰撞处理

c++ - 圆的碰撞解决问题