Files
XCEngine/docs/api/math/plane/plane.md

65 lines
2.0 KiB
Markdown
Raw Normal View History

# Plane
2026-03-20 02:35:15 +08:00
**命名空间**: `XCEngine::Math`
2026-03-20 02:35:15 +08:00
**类型**: `struct`
**头文件**: `XCEngine/Core/Math/Plane.h`
2026-03-20 02:35:15 +08:00
**描述**: 平面,用于 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
#include <XCEngine/Core/Math/Plane.h>
#include <XCEngine/Core/Math/Vector3.h>
#include <XCEngine/Core/Math/Sphere.h>
2026-03-20 02:35:15 +08:00
using namespace XCEngine::Math;
2026-03-20 02:35:15 +08:00
void PlaneExample() {
Plane plane(Vector3::Up(), 0.0f);
2026-03-20 02:35:15 +08:00
Vector3 point(1.0f, 2.0f, 0.0f);
float dist = plane.GetDistanceToPoint(point);
2026-03-20 02:35:15 +08:00
Vector3 closest = plane.GetClosestPoint(point);
2026-03-20 02:35:15 +08:00
bool onNormalSide = plane.GetSide(point);
2026-03-20 02:35:15 +08:00
Sphere sphere(Vector3(1.0f, 0.5f, 0.0f), 1.0f);
bool intersects = plane.Intersects(sphere);
}
```
## 相关文档
2026-03-20 02:35:15 +08:00
- [Math 模块总览](../math.md) - Math 模块总览
- [Sphere](../sphere/sphere.md) - 球体
- [Vector3](../vector3/vector3.md) - 三维向量