Files
XCEngine/docs/api/math/sphere/sphere.md
ssdfasd f5a34f8adc docs: 重构 API 文档 - components 和 scene 模块
- components: 修复英文标题为中文,添加缺失组件文档
  - 新增 camera-component, light-component, audio-source-component, audio-listener-component 类总览
  - 修复 get-position.md 格式
  - 更新 components.md 模块总览
- scene: 修复方法文档格式,新增缺失方法
  - 修复 find.md, create-game-object.md 英文标题
  - 新增 FindByID, SerializeToString, DeserializeFromString 方法文档
  - 更新 scene.md 类总览方法列表
2026-03-26 01:50:27 +08:00

55 lines
1.4 KiB
Markdown

# Sphere
**命名空间**: `XCEngine::Math`
**类型**: `struct`
**头文件**: `XCEngine/Core/Math/Sphere.h`
**描述**: 球体,用于碰撞检测和范围查询
## 概述
`Sphere` 是三维空间中的球体结构体,包含一个中心点 `center` 和半径 `radius`。主要用于碰撞检测和范围查询等几何计算场景。
## 结构体成员
| 成员 | 类型 | 描述 | 默认值 |
|------|------|------|--------|
| `center` | `Vector3` | 球体中心点 | `Vector3::Zero()` |
| `radius` | `float` | 球体半径 | `0.0f` |
## 公共方法
| 方法 | 描述 | 线程安全 | 复杂度 |
|------|------|----------|--------|
| [`Sphere()`](sphere-default-constructor.md) | 默认构造,零初始化 | ✅ | O(1) |
| [`Sphere(const Vector3&, float)`](sphere-constructor.md) | 从中心和半径构造球体 | ✅ | O(1) |
| [`Contains`](contains.md) | 检测点是否在球体内 | ✅ | O(1) |
| [`Intersects`](intersects.md) | 检测两个球体是否相交 | ✅ | O(1) |
## 使用示例
```cpp
#include <XCEngine/Core/Math/Sphere.h>
#include <XCEngine/Core/Math/Vector3.h>
using namespace XCEngine::Math;
Sphere sphere(Vector3(0.0f, 0.0f, 0.0f), 1.0f);
Vector3 point(0.5f, 0.5f, 0.0f);
if (sphere.Contains(point)) {
// point is inside the sphere
}
Sphere other(Vector3(1.5f, 0.0f, 0.0f), 1.0f);
if (sphere.Intersects(other)) {
// spheres intersect
}
```
## 相关文档
- [Math 模块总览](../math.md) - Math 模块总览