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

65 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Plane
**命名空间**: `XCEngine::Math`
**类型**: `struct`
**头文件**: `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
#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);
}
```
## 相关文档
- [Math 模块总览](../math.md) - Math 模块总览
- [Sphere](../sphere/sphere.md) - 球体
- [Vector3](../vector3/vector3.md) - 三维向量