首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >快速最小-最大AABB碰撞检测

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

Stack Overflow用户
提问于 2014-08-17 01:38:39
回答 1查看 1.9K关注 0票数 2

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

Javascript:

代码语言: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) {
  ???
}
EN

回答 1

Stack Overflow用户

发布于 2014-08-17 02:29:03

刚刚发现了o_O

这是最快的解决方案:

代码语言:javascript
复制
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
  );
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25342237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档