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

43 lines
984 B
Markdown

# Plane::GetDistanceToPoint
```cpp
float GetDistanceToPoint(const Vector3& point) const
```
计算点到平面的有符号距离。正值表示点在法线方向一侧,负值表示点在法线相反方向一侧,零值表示点在平面上。
**参数:**
- `point` - 要计算的点
**返回:** `float` - 点到平面的有符号距离
**线程安全:**
**复杂度:** O(1)
**示例:**
```cpp
#include <XCEngine/Math/Plane.h>
#include <XCEngine/Math/Vector3.h>
#include <cstdio>
using namespace XCEngine::Math;
void GetDistanceToPointExample() {
Plane plane(Vector3::Up(), 0.0f);
Vector3 point1(0.0f, 2.0f, 0.0f);
float dist1 = plane.GetDistanceToPoint(point1);
Vector3 point2(0.0f, -3.0f, 0.0f);
float dist2 = plane.GetDistanceToPoint(point2);
}
```
## 相关文档
- [Plane 类总览](plane.md) - 返回类总览
- [GetClosestPoint](getclosestpoint.md) - 计算平面上最接近点
- [GetSide](getside.md) - 判断点在哪一侧