Files
XCEngine/docs/api/math/bounds/intersects.md
2026-03-20 02:35:15 +08:00

37 lines
837 B
Markdown

# Bounds::Intersects
```cpp
bool Intersects(const Bounds& other) const
```
检测该包围盒与另一个 Bounds 是否相交(重叠)。使用简化的 AABB 重叠检测算法,通过比较两个包围盒中心距离与它们 extents 之和来判断是否相交。
**参数:**
- `other` - 另一个 Bounds
**返回:** `bool` - true 表示两个 Bounds 相交
**线程安全:**
**复杂度:** O(1)
**示例:**
```cpp
#include <XCEngine/Math/Bounds.h>
#include <XCEngine/Math/Vector3.h>
using namespace XCEngine::Math;
Bounds a(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
Bounds b(Vector3(1.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
if (a.Intersects(b)) {
// a and b overlap
}
```
## 相关文档
- [Bounds](bounds.md) - 返回类总览
- [Contains](contains.md) - 检测点是否在盒内