简体   繁体   English

交点算法与Rectangle.intersects(Rectangle r)的区别

[英]Difference between intersection algorithm and Rectangle.intersects(Rectangle r)

Someone on a forum I go to said I shouldn't use Rectangle.intersects for my collision detection, and I should use this algorithm instead: 我去的论坛上有人说我不应该将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);
}

But isn't the Rectangle.intersects algorithm different, and better than this? 但是Rectangle.intersects算法是否有所不同,并且比这个更好?

Rectangle.intersects基本相同,除了您的算法使用float而不是double并包括边界的相等条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM