docs: update math API docs

This commit is contained in:
2026-03-20 02:35:15 +08:00
parent e165dbea1c
commit c5b17239ca
243 changed files with 5307 additions and 1327 deletions

View File

@@ -1,40 +1,64 @@
# Plane
3D 平面结构体,由法线和距离表示。
**命名空间**: `XCEngine::Math`
**头文件:** `#include <XCEngine/Math/Plane.h>`
**类型**: `struct`
**命名空间:** `XCEngine::Math`
**头文件**: `XCEngine/Math/Plane.h`
## 结构体定义
**描述**: 平面,用于 3D 空间中的平面表示和相交测试
## 概述
`Plane` 结构体用于表示 3D 空间中的平面通过法线向量normal和距离值distance定义。平面方程为 `dot(normal, point) + distance = 0`。常用于碰撞检测、视锥体裁剪、射线投射等图形学基础运算。
默认构造创建一个朝上y 轴正方向)的单位平面。
## 结构体成员
| 成员 | 类型 | 描述 | 默认值 |
|------|------|------|--------|
| `normal` | `Vector3` | 平面法线向量 | `Vector3::Up()` |
| `distance` | `float` | 原点到平面的有符号距离 | `0.0f` |
## 公共方法
| 方法 | 描述 |
|------|------|
| [`Plane()`](constructor-default.md) | 默认构造函数,创建 y=0 平面 |
| [`Plane(normal, distance)`](constructor.md) | 从法线和距离构造平面 |
| [`FromPoints`](frompoints.md) | 从三个不共线点创建平面 |
| [`GetDistanceToPoint`](getdistancetopoint.md) | 计算点到平面的有符号距离 |
| [`GetClosestPoint`](getclosestpoint.md) | 计算平面上最接近给定点的点 |
| [`GetSide`](getside.md) | 判断点在平面的哪一侧 |
| [`Intersects`](intersects.md) | 检测与球体是否相交 |
## 使用示例
```cpp
struct Plane {
Vector3 normal = Vector3::Up();
float distance = 0.0f;
};
#include <XCEngine/Math/Plane.h>
#include <XCEngine/Math/Vector3.h>
#include <XCEngine/Math/Sphere.h>
using namespace XCEngine::Math;
void PlaneExample() {
Plane plane(Vector3::Up(), 0.0f);
Vector3 point(1.0f, 2.0f, 0.0f);
float dist = plane.GetDistanceToPoint(point);
Vector3 closest = plane.GetClosestPoint(point);
bool onNormalSide = plane.GetSide(point);
Sphere sphere(Vector3(1.0f, 0.5f, 0.0f), 1.0f);
bool intersects = plane.Intersects(sphere);
}
```
## 构造函数
- `Plane()` - 默认构造 (y=0 平面)
- `Plane(const Vector3& normal, float distance)` - 从法线和距离构造
## 静态工厂方法
| 方法 | 返回值 | 描述 |
|------|--------|------|
| [FromPoints(a, b, c)](frompoints.md) | `Plane` | 从三个不共线点创建 |
## 实例方法
| 方法 | 返回值 | 描述 |
|------|--------|------|
| [GetDistanceToPoint(point)](getdistancetopoint.md) | `float` | 点到平面的有符号距离 |
| [GetClosestPoint(point)](getclosestpoint.md) | `Vector3` | 平面上最接近给定点的点 |
| [GetSide(point)](getside.md) | `bool` | 点在平面的哪一侧 |
| [Intersects(sphere)](intersects.md) | `bool` | 与球体相交 |
## 相关文档
- [Math 模块总览](../math.md) - 返回 Math 模块总览
- [Math 模块总览](../math.md) - Math 模块总览
- [Sphere](../sphere/sphere.md) - 球体
- [Vector3](../vector3/vector3.md) - 三维向量