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

31 lines
638 B
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.
# Vector2::Normalize
```cpp
static Vector2 Normalize(const Vector2& v)
```
将向量归一化为单位长度。如果向量长度接近零(小于 EPSILON返回零向量以避免除零错误。
**参数:**
- `v` - 要归一化的向量
**返回:** `Vector2` - 归一化后的单位向量
**线程安全:**
**异常:** (无)
**复杂度:** O(1)
**示例:**
```cpp
Vector2 dir = Vector2::Normalize(Vector2(3.0f, 4.0f)); // (0.6f, 0.8f)
```
## 相关文档
- [Vector2](vector2.md) - 返回类总览
- [Magnitude](Magnitude.md) - 计算向量长度
- [Normalized](normalized.md) - 实例方法归一化