gpt4 book ai didi

javascript - 快速最小-最大 AABB 碰撞检测

转载 作者:行者123 更新时间:2023-11-29 21:58:10 25 4
gpt4 key购买 nike

所以我想知道,检测 AABB 与 AABB 碰撞的最快方法是什么,其中 AABB 的结构基于最小点和最大点?

Javascript:

function Point(x, y) {
this.x = x || 0;
this.y = y || 0;
}


function AABB(min, max) {
this.min = min || new Point();
this.max = max || new Point();
}

AABB.prototype.intersects = function(other) {
???
}

最佳答案

刚发现o_O

这是最快的解决方案:

AABB.prototype.intersects = function(other) {
return !(
this.max.X < other.min.X ||
this.max.Y < other.min.Y ||
this.min.X > other.max.X ||
this.min.Y > other.max.Y
);
}

关于javascript - 快速最小-最大 AABB 碰撞检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25342237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com