docs: update math API docs
This commit is contained in:
@@ -12,6 +12,8 @@ static float Angle(const Vector3& from, const Vector3& to)
|
||||
|
||||
**返回:** `float` - 两向量之间的夹角(0-180度)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -21,3 +23,7 @@ Vector3 a(1.0f, 0.0f, 0.0f);
|
||||
Vector3 b(0.0f, 1.0f, 0.0f);
|
||||
float angle = Vector3::Angle(a, b); // 90.0f
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
|
||||
@@ -6,8 +6,12 @@ static Vector3 Back()
|
||||
|
||||
返回后方向向量 (0, 0, -1)。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `Vector3` - 值为 (0, 0, -1) 的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +19,8 @@ static Vector3 Back()
|
||||
```cpp
|
||||
Vector3 back = Vector3::Back();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`Forward`](forward.md) - 前向向量
|
||||
|
||||
@@ -12,6 +12,8 @@ static Vector3 Cross(const Vector3& a, const Vector3& b)
|
||||
|
||||
**返回:** `Vector3` - 叉积结果,垂直于 a 和 b 的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -21,3 +23,7 @@ Vector3 right(1.0f, 0.0f, 0.0f);
|
||||
Vector3 up(0.0f, 1.0f, 0.0f);
|
||||
Vector3 forward = Vector3::Cross(right, up); // (0, 0, 1)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
|
||||
@@ -12,6 +12,8 @@ static float Dot(const Vector3& a, const Vector3& b)
|
||||
|
||||
**返回:** `float` - 点积结果 a.x * b.x + a.y * b.y + a.z * b.z
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -21,3 +23,7 @@ Vector3 a(1.0f, 0.0f, 0.0f);
|
||||
Vector3 b(0.0f, 1.0f, 0.0f);
|
||||
float dot = Vector3::Dot(a, b); // 0.0f
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
|
||||
@@ -6,8 +6,12 @@ static Vector3 Down()
|
||||
|
||||
返回下方向向量 (0, -1, 0)。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `Vector3` - 值为 (0, -1, 0) 的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +19,8 @@ static Vector3 Down()
|
||||
```cpp
|
||||
Vector3 down = Vector3::Down();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`Up`](up.md) - 上向量
|
||||
|
||||
@@ -6,8 +6,12 @@ static Vector3 Forward()
|
||||
|
||||
返回前方向向量 (0, 0, 1)。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `Vector3` - 值为 (0, 0, 1) 的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +19,9 @@ static Vector3 Forward()
|
||||
```cpp
|
||||
Vector3 forward = Vector3::Forward();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`Back`](back.md) - 后向向量
|
||||
- [`Up`](up.md) - 上向量
|
||||
|
||||
@@ -6,8 +6,12 @@ static Vector3 Left()
|
||||
|
||||
返回左方向向量 (-1, 0, 0)。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `Vector3` - 值为 (-1, 0, 0) 的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +19,8 @@ static Vector3 Left()
|
||||
```cpp
|
||||
Vector3 left = Vector3::Left();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`Right`](right.md) - 右向量
|
||||
|
||||
@@ -13,6 +13,8 @@ static Vector3 Lerp(const Vector3& a, const Vector3& b, float t)
|
||||
|
||||
**返回:** `Vector3` - 插值结果
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -22,3 +24,7 @@ Vector3 start(0.0f, 0.0f, 0.0f);
|
||||
Vector3 end(10.0f, 10.0f, 10.0f);
|
||||
Vector3 mid = Vector3::Lerp(start, end, 0.5f); // (5.0f, 5.0f, 5.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
|
||||
@@ -14,6 +14,8 @@ float Magnitude() const
|
||||
|
||||
**返回:** `float` - 向量长度 sqrt(x * x + y * y + z * z)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -23,3 +25,8 @@ Vector3 v(1.0f, 2.0f, 2.0f);
|
||||
float len = v.Magnitude(); // 3.0f
|
||||
float len2 = Vector3::Magnitude(v); // 3.0f
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`SqrMagnitude`](sqrmagnitude.md) - 计算长度的平方
|
||||
|
||||
@@ -13,6 +13,8 @@ static Vector3 MoveTowards(const Vector3& current, const Vector3& target, float
|
||||
|
||||
**返回:** `Vector3` - 移动后的位置
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -22,3 +24,7 @@ Vector3 current(0.0f, 0.0f, 0.0f);
|
||||
Vector3 target(10.0f, 0.0f, 0.0f);
|
||||
Vector3 moved = Vector3::MoveTowards(current, target, 3.0f); // (3.0f, 0, 0)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
|
||||
@@ -11,6 +11,8 @@ static Vector3 Normalize(const Vector3& v)
|
||||
|
||||
**返回:** `Vector3` - 归一化后的单位向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -18,3 +20,8 @@ static Vector3 Normalize(const Vector3& v)
|
||||
```cpp
|
||||
Vector3 dir = Vector3::Normalize(Vector3(3.0f, 4.0f, 0.0f)); // (0.6f, 0.8f, 0)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`Normalized`](normalized.md) - 实例方法版本
|
||||
|
||||
@@ -8,6 +8,8 @@ Vector3 Normalized() const
|
||||
|
||||
**返回:** `Vector3` - 归一化后的向量副本
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -16,3 +18,8 @@ Vector3 Normalized() const
|
||||
Vector3 v(3.0f, 4.0f, 0.0f);
|
||||
Vector3 unit = v.Normalized(); // (0.6f, 0.8f, 0), v 保持不变
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`Normalize`](normalize.md) - 静态方法版本
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
static Vector3 One()
|
||||
```
|
||||
|
||||
返回单位向量 (1, 1, 1)。
|
||||
返回分量为 (1, 1, 1) 的向量。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `Vector3` - 值为 (1, 1, 1) 的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +19,7 @@ static Vector3 One()
|
||||
```cpp
|
||||
Vector3 unit = Vector3::One();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
|
||||
30
docs/api/math/vector3/operator_add.md
Normal file
30
docs/api/math/vector3/operator_add.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Vector3::operator+
|
||||
|
||||
```cpp
|
||||
Vector3 operator+(const Vector3& other) const
|
||||
```
|
||||
|
||||
向量加法,将两个向量的对应分量相加。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要加的向量
|
||||
|
||||
**返回:** `Vector3` - 相加结果
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 a(1.0f, 2.0f, 3.0f);
|
||||
Vector3 b(4.0f, 5.0f, 6.0f);
|
||||
Vector3 c = a + b; // (5.0f, 7.0f, 9.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`operator-`](operator_sub.md) - 减法运算
|
||||
- [`operator+=`](operator_add_assign.md) - 加法赋值
|
||||
29
docs/api/math/vector3/operator_add_assign.md
Normal file
29
docs/api/math/vector3/operator_add_assign.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector3::operator+=
|
||||
|
||||
```cpp
|
||||
Vector3& operator+=(const Vector3& other)
|
||||
```
|
||||
|
||||
向量加法赋值,将 `other` 的分量加到当前向量。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要加的向量
|
||||
|
||||
**返回:** `Vector3&` - 引用到修改后的当前向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 v(1.0f, 2.0f, 3.0f);
|
||||
v += Vector3(4.0f, 5.0f, 6.0f); // v = (5.0f, 7.0f, 9.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`operator+`](operator_add.md) - 加法运算
|
||||
- [`operator-=`](operator_sub_assign.md) - 减法赋值
|
||||
40
docs/api/math/vector3/operator_div.md
Normal file
40
docs/api/math/vector3/operator_div.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Vector3::operator/
|
||||
|
||||
```cpp
|
||||
Vector3 operator/(float scalar) const
|
||||
Vector3 operator/(const Vector3& other) const
|
||||
```
|
||||
|
||||
向量除法。支持向量与标量相除,以及向量分量对应相除。
|
||||
|
||||
**参数:**
|
||||
- `scalar` - 标量值(用于第一个重载)
|
||||
- `other` - 向量(用于第二个重载,分量相除)
|
||||
|
||||
**返回:** `Vector3` - 除法结果
|
||||
|
||||
**异常:** 第二个重载中,如果 `other` 的任一分量为零,结果为无穷大
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 v(6.0f, 8.0f, 10.0f);
|
||||
|
||||
// 标量除法
|
||||
Vector3 scaled = v / 2.0f; // (3.0f, 4.0f, 5.0f)
|
||||
|
||||
// 分量相除
|
||||
Vector3 a(6.0f, 8.0f, 10.0f);
|
||||
Vector3 b(2.0f, 2.0f, 2.0f);
|
||||
Vector3 componentwise = a / b; // (3.0f, 4.0f, 5.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`operator*`](operator_mul.md) - 乘法运算
|
||||
- [`operator/=`](operator_div_assign.md) - 除法赋值
|
||||
31
docs/api/math/vector3/operator_div_assign.md
Normal file
31
docs/api/math/vector3/operator_div_assign.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Vector3::operator/=
|
||||
|
||||
```cpp
|
||||
Vector3& operator/=(float scalar)
|
||||
```
|
||||
|
||||
向量标量除法赋值,将当前向量的每个分量除以标量值。
|
||||
|
||||
**参数:**
|
||||
- `scalar` - 标量值(不能为零)
|
||||
|
||||
**返回:** `Vector3&` - 引用到修改后的当前向量
|
||||
|
||||
**异常:** 如果 `scalar` 为零,结果为无穷大
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 v(6.0f, 8.0f, 10.0f);
|
||||
v /= 2.0f; // v = (3.0f, 4.0f, 5.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`operator/`](operator_div.md) - 除法运算
|
||||
- [`operator*=`](operator_mul_assign.md) - 乘法赋值
|
||||
32
docs/api/math/vector3/operator_eq.md
Normal file
32
docs/api/math/vector3/operator_eq.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Vector3::operator==
|
||||
|
||||
```cpp
|
||||
bool operator==(const Vector3& other) const
|
||||
```
|
||||
|
||||
判断两个向量是否相等。使用 EPSILON 进行浮点数比较。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要比较的向量
|
||||
|
||||
**返回:** `bool` - 如果两个向量相等返回 true,否则返回 false
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 a(1.0f, 2.0f, 3.0f);
|
||||
Vector3 b(1.0f, 2.0f, 3.0f);
|
||||
Vector3 c(1.0f, 2.0f, 3.00001f);
|
||||
|
||||
bool equal1 = (a == b); // true
|
||||
bool equal2 = (a == c); // true(因为差异在 EPSILON 内)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`operator!=`](operator_neq.md) - 不等比较
|
||||
35
docs/api/math/vector3/operator_index.md
Normal file
35
docs/api/math/vector3/operator_index.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Vector3::operator[]
|
||||
|
||||
```cpp
|
||||
float operator[](int index) const
|
||||
float& operator[](int index)
|
||||
```
|
||||
|
||||
通过索引访问向量的分量。0 = x, 1 = y, 2 = z。
|
||||
|
||||
**参数:**
|
||||
- `index` - 分量索引(0、1 或 2)
|
||||
|
||||
**返回:** `float` 或 `float&` - 对应分量的值(const 版本返回值,non-const 版本返回引用)
|
||||
|
||||
**异常:** 如果 index 超出范围(< 0 或 > 2),行为未定义
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 v(1.0f, 2.0f, 3.0f);
|
||||
|
||||
float x = v[0]; // 1.0f
|
||||
float y = v[1]; // 2.0f
|
||||
float z = v[2]; // 3.0f
|
||||
|
||||
v[0] = 10.0f; // v = (10.0f, 2.0f, 3.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
39
docs/api/math/vector3/operator_mul.md
Normal file
39
docs/api/math/vector3/operator_mul.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Vector3::operator*
|
||||
|
||||
```cpp
|
||||
Vector3 operator*(float scalar) const
|
||||
Vector3 operator*(const Vector3& other) const
|
||||
```
|
||||
|
||||
向量乘法。支持向量与标量相乘,以及向量分量对应相乘。
|
||||
|
||||
**参数:**
|
||||
- `scalar` - 标量值(用于第一个重载)
|
||||
- `other` - 向量(用于第二个重载,分量相乘)
|
||||
|
||||
**返回:** `Vector3` - 乘法结果
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 v(1.0f, 2.0f, 3.0f);
|
||||
|
||||
// 标量乘法
|
||||
Vector3 scaled = v * 2.0f; // (2.0f, 4.0f, 6.0f)
|
||||
|
||||
// 分量相乘
|
||||
Vector3 a(1.0f, 2.0f, 3.0f);
|
||||
Vector3 b(2.0f, 3.0f, 4.0f);
|
||||
Vector3 componentwise = a * b; // (2.0f, 6.0f, 12.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`operator/`](operator_div.md) - 除法运算
|
||||
- [`operator*=`](operator_mul_assign.md) - 乘法赋值
|
||||
- [Quaternion * Vector3](quaternion-multiply.md) - 四元数旋转向量
|
||||
29
docs/api/math/vector3/operator_mul_assign.md
Normal file
29
docs/api/math/vector3/operator_mul_assign.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector3::operator*=
|
||||
|
||||
```cpp
|
||||
Vector3& operator*=(float scalar)
|
||||
```
|
||||
|
||||
向量标量乘法赋值,将当前向量的每个分量乘以标量值。
|
||||
|
||||
**参数:**
|
||||
- `scalar` - 标量值
|
||||
|
||||
**返回:** `Vector3&` - 引用到修改后的当前向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 v(1.0f, 2.0f, 3.0f);
|
||||
v *= 2.0f; // v = (2.0f, 4.0f, 6.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`operator*`](operator_mul.md) - 乘法运算
|
||||
- [`operator/=`](operator_div_assign.md) - 除法赋值
|
||||
30
docs/api/math/vector3/operator_neq.md
Normal file
30
docs/api/math/vector3/operator_neq.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Vector3::operator!=
|
||||
|
||||
```cpp
|
||||
bool operator!=(const Vector3& other) const
|
||||
```
|
||||
|
||||
判断两个向量是否不相等。使用 EPSILON 进行浮点数比较。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要比较的向量
|
||||
|
||||
**返回:** `bool` - 如果两个向量不相等返回 true,否则返回 false
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 a(1.0f, 2.0f, 3.0f);
|
||||
Vector3 b(4.0f, 5.0f, 6.0f);
|
||||
|
||||
bool notEqual = (a != b); // true
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`operator==`](operator_eq.md) - 相等比较
|
||||
30
docs/api/math/vector3/operator_sub.md
Normal file
30
docs/api/math/vector3/operator_sub.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Vector3::operator-
|
||||
|
||||
```cpp
|
||||
Vector3 operator-(const Vector3& other) const
|
||||
```
|
||||
|
||||
向量减法,将两个向量的对应分量相减。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要减的向量
|
||||
|
||||
**返回:** `Vector3` - 相减结果
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 a(5.0f, 7.0f, 9.0f);
|
||||
Vector3 b(1.0f, 2.0f, 3.0f);
|
||||
Vector3 c = a - b; // (4.0f, 5.0f, 6.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`operator+`](operator_add.md) - 加法运算
|
||||
- [`operator-=`](operator_sub_assign.md) - 减法赋值
|
||||
29
docs/api/math/vector3/operator_sub_assign.md
Normal file
29
docs/api/math/vector3/operator_sub_assign.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector3::operator-=
|
||||
|
||||
```cpp
|
||||
Vector3& operator-=(const Vector3& other)
|
||||
```
|
||||
|
||||
向量减法赋值,从当前向量减去 `other` 的分量。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要减的向量
|
||||
|
||||
**返回:** `Vector3&` - 引用到修改后的当前向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 v(5.0f, 7.0f, 9.0f);
|
||||
v -= Vector3(1.0f, 2.0f, 3.0f); // v = (4.0f, 5.0f, 6.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`operator-`](operator_sub.md) - 减法运算
|
||||
- [`operator+=`](operator_add_assign.md) - 加法赋值
|
||||
@@ -12,6 +12,8 @@ static Vector3 Project(const Vector3& vector, const Vector3& onNormal)
|
||||
|
||||
**返回:** `Vector3` - 投影结果。如果法线长度为 0,返回零向量。
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -21,3 +23,8 @@ Vector3 v(1.0f, 1.0f, 0.0f);
|
||||
Vector3 normal(1.0f, 0.0f, 0.0f);
|
||||
Vector3 projected = Vector3::Project(v, normal); // (1, 0, 0)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`ProjectOnPlane`](projectonplane.md) - 投影到平面上
|
||||
|
||||
@@ -12,6 +12,8 @@ static Vector3 ProjectOnPlane(const Vector3& vector, const Vector3& planeNormal)
|
||||
|
||||
**返回:** `Vector3` - 平面上的投影向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -21,3 +23,8 @@ Vector3 v(1.0f, 1.0f, 1.0f);
|
||||
Vector3 normal(0.0f, 1.0f, 0.0f); // XZ 平面
|
||||
Vector3 projected = Vector3::ProjectOnPlane(v, normal); // (1, 0, 1)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`Project`](project.md) - 投影到法线上
|
||||
|
||||
@@ -12,6 +12,8 @@ Vector3 operator*(const Quaternion& q, const Vector3& v)
|
||||
|
||||
**返回:** `Vector3` - 旋转后的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -21,3 +23,7 @@ Quaternion rot = Quaternion::FromEulerAngles(0.0f, 90.0f * DEG_TO_RAD, 0.0f);
|
||||
Vector3 forward = Vector3::Forward();
|
||||
Vector3 rotated = rot * forward; // 绕 Y 轴旋转 90 度
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
|
||||
@@ -12,6 +12,8 @@ static Vector3 Reflect(const Vector3& inDirection, const Vector3& inNormal)
|
||||
|
||||
**返回:** `Vector3` - 反射方向
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -21,3 +23,7 @@ Vector3 incoming(1.0f, -1.0f, 0.0f);
|
||||
Vector3 normal(0.0f, 1.0f, 0.0f);
|
||||
Vector3 reflected = Vector3::Reflect(incoming, normal); // (1, 1, 0)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
|
||||
@@ -6,8 +6,12 @@ static Vector3 Right()
|
||||
|
||||
返回右方向向量 (1, 0, 0)。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `Vector3` - 值为 (1, 0, 0) 的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +19,8 @@ static Vector3 Right()
|
||||
```cpp
|
||||
Vector3 right = Vector3::Right();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`Left`](left.md) - 左向量
|
||||
|
||||
@@ -14,6 +14,8 @@ float SqrMagnitude() const
|
||||
|
||||
**返回:** `float` - 向量长度平方 x * x + y * y + z * z
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -23,3 +25,8 @@ Vector3 v(1.0f, 2.0f, 2.0f);
|
||||
float sqlen = v.SqrMagnitude(); // 9.0f
|
||||
float sqlen2 = Vector3::SqrMagnitude(v); // 9.0f
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`Magnitude`](magnitude.md) - 计算向量长度
|
||||
|
||||
@@ -6,8 +6,12 @@ static Vector3 Up()
|
||||
|
||||
返回上方向向量 (0, 1, 0)。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `Vector3` - 值为 (0, 1, 0) 的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +19,8 @@ static Vector3 Up()
|
||||
```cpp
|
||||
Vector3 up = Vector3::Up();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
- [`Down`](down.md) - 下向量
|
||||
|
||||
39
docs/api/math/vector3/vector3-constructor.md
Normal file
39
docs/api/math/vector3/vector3-constructor.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Vector3::Vector3
|
||||
|
||||
```cpp
|
||||
Vector3() = default;
|
||||
constexpr Vector3(float x, float y, float z);
|
||||
```
|
||||
|
||||
构造一个三维向量。
|
||||
|
||||
**参数:**
|
||||
- `x` - X 分量,默认为 0.0f
|
||||
- `y` - Y 分量,默认为 0.0f
|
||||
- `z` - Z 分量,默认为 0.0f
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
Vector3 a;
|
||||
Vector3 b(1.0f, 2.0f, 3.0f);
|
||||
Vector3 c(4.5f, 5.5f, 6.5f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
@@ -1,69 +1,87 @@
|
||||
# Vector3
|
||||
|
||||
3D 向量结构体,用于表示 3D 空间中的点、方向、颜色或法线。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Vector3.h>`
|
||||
**类型**: `struct`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/Math/Vector3.h`
|
||||
|
||||
## 结构体定义
|
||||
**描述**: 三维向量,用于 3D 图形和游戏开发中的位置、方向和缩放计算
|
||||
|
||||
```cpp
|
||||
struct Vector3 {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
};
|
||||
```
|
||||
## 概述
|
||||
|
||||
## 静态工厂方法
|
||||
Vector3 是 XCEngine 中用于表示三维向量的核心类型,支持常见的向量运算。它广泛用于 3D 图形编程中的位置、方向、速度、缩放等计算场景。
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Zero()](zero.md) | `Vector3` | 返回 (0, 0, 0) |
|
||||
| [One()](one.md) | `Vector3` | 返回 (1, 1, 1) |
|
||||
| [Forward()](forward.md) | `Vector3` | 返回 (0, 0, 1),前方向(Z+) |
|
||||
| [Back()](back.md) | `Vector3` | 返回 (0, 0, -1),后方向 |
|
||||
| [Up()](up.md) | `Vector3` | 返回 (0, 1, 0),上方向 |
|
||||
| [Down()](down.md) | `Vector3` | 返回 (0, -1, 0),下方向 |
|
||||
| [Right()](right.md) | `Vector3` | 返回 (1, 0, 0),右方向 |
|
||||
| [Left()](left.md) | `Vector3` | 返回 (-1, 0, 0),左方向 |
|
||||
## 结构体成员
|
||||
|
||||
## 静态数学方法
|
||||
| 成员 | 类型 | 描述 | 默认值 |
|
||||
|------|------|------|--------|
|
||||
| `x` | `float` | X 分量 | `0.0f` |
|
||||
| `y` | `float` | Y 分量 | `0.0f` |
|
||||
| `z` | `float` | Z 分量 | `0.0f` |
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Dot(a, b)](dot.md) | `float` | 点积 |
|
||||
| [Cross(a, b)](cross.md) | `Vector3` | 叉积(垂直于 a 和 b) |
|
||||
| [Normalize(v)](normalize.md) | `Vector3` | 归一化向量 |
|
||||
| [Magnitude(v)](magnitude.md) | `float` | 向量长度 |
|
||||
| [SqrMagnitude(v)](sqrmagnitude.md) | `float` | 长度平方 |
|
||||
| [Lerp(a, b, t)](lerp.md) | `Vector3` | 线性插值 |
|
||||
| [MoveTowards(current, target, maxDistance)](movetowards.md) | `Vector3` | 朝目标移动 |
|
||||
| [Project(vector, onNormal)](project.md) | `Vector3` | 投影到法线上 |
|
||||
| [ProjectOnPlane(vector, planeNormal)](projectonplane.md) | `Vector3` | 投影到平面上 |
|
||||
| [Angle(from, to)](angle.md) | `float` | 两向量夹角(度) |
|
||||
| [Reflect(inDirection, inNormal)](reflect.md) | `Vector3` | 反射 |
|
||||
## 公共方法
|
||||
|
||||
## 实例方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Magnitude()](magnitude.md) | `float` | 获取向量长度 |
|
||||
| [SqrMagnitude()](sqrmagnitude.md) | `float` | 获取长度平方 |
|
||||
| [Normalized()](normalized.md) | `Vector3` | 获取归一化副本 |
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Zero`](zero.md) | 返回零向量 (0, 0, 0) |
|
||||
| [`One`](one.md) | 返回单位向量 (1, 1, 1) |
|
||||
| [`Forward`](forward.md) | 返回前向向量 (0, 0, 1) |
|
||||
| [`Back`](back.md) | 返回后向向量 (0, 0, -1) |
|
||||
| [`Up`](up.md) | 返回上向量 (0, 1, 0) |
|
||||
| [`Down`](down.md) | 返回下向量 (0, -1, 0) |
|
||||
| [`Right`](right.md) | 返回右向量 (1, 0, 0) |
|
||||
| [`Left`](left.md) | 返回左向量 (-1, 0, 0) |
|
||||
| [`Dot`](dot.md) | 计算点积 |
|
||||
| [`Cross`](cross.md) | 计算叉积 |
|
||||
| [`Normalize`](normalize.md) | 返回归一化向量 |
|
||||
| [`Magnitude`](magnitude.md) | 计算向量长度 |
|
||||
| [`SqrMagnitude`](sqrmagnitude.md) | 计算向量长度的平方 |
|
||||
| [`Lerp`](lerp.md) | 线性插值 |
|
||||
| [`MoveTowards`](movetowards.md) | 移向目标点 |
|
||||
| [`Project`](project.md) | 投影到法向量上 |
|
||||
| [`ProjectOnPlane`](projectonplane.md) | 投影到平面上 |
|
||||
| [`Angle`](angle.md) | 计算两个向量之间的夹角 |
|
||||
| [`Reflect`](reflect.md) | 反射向量 |
|
||||
| [`Normalized`](normalized.md) | 返回归一化副本(实例方法) |
|
||||
|
||||
## 运算符
|
||||
|
||||
- 算术: `+`, `-`, `*` (scalar/memberwise), `/` (scalar/memberwise)
|
||||
- 复合赋值: `+=`, `-=`, `*=`, `/=`
|
||||
- 下标: `operator[]` (0=x, 1=y, 2=z)
|
||||
- 比较: `==`, `!=`
|
||||
| 运算符 | 描述 |
|
||||
|--------|------|
|
||||
| [`+`](operator_add.md), [`-`](operator_sub.md) | 向量加减 |
|
||||
| [`*`](operator_mul.md), [`/`](operator_div.md) | 向量与标量或分量相乘/相除 |
|
||||
| [`*=`](operator_mul_assign.md), [`/=`](operator_div_assign.md) | 复合赋值运算符 |
|
||||
| [`[]`](./operator_index.md) | 下标访问 x, y, z 分量 |
|
||||
| [`==`](operator_eq.md), [`!=`](operator_neq.md) | 相等性比较 |
|
||||
| [`* (Quaternion)`](quaternion-multiply.md) | 用四元数旋转向量 |
|
||||
|
||||
## 与 Quaternion 的乘法
|
||||
## 使用示例
|
||||
|
||||
[Vector3 * Quaternion](quaternion-multiply.md) - 用四元数旋转向量
|
||||
```cpp
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
Vector3 position(1.0f, 2.0f, 3.0f);
|
||||
Vector3 direction = Vector3::Forward();
|
||||
|
||||
float dot = Vector3::Dot(position, direction);
|
||||
Vector3 cross = Vector3::Cross(position, direction);
|
||||
Vector3 normalized = position.Normalized();
|
||||
|
||||
std::cout << "Position: (" << position.x << ", " << position.y << ", " << position.z << ")\n";
|
||||
std::cout << "Dot product: " << dot << "\n";
|
||||
std::cout << "Normalized: (" << normalized.x << ", " << normalized.y << ", " << normalized.z << ")\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
- [Math 模块总览](../math.md) - Math 模块总览
|
||||
- [Vector2](../vector2/vector2.md) - 二维向量
|
||||
- [Vector4](../vector4/vector4.md) - 四维向量
|
||||
|
||||
@@ -6,8 +6,12 @@ static Vector3 Zero()
|
||||
|
||||
返回零向量 (0, 0, 0)。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `Vector3` - 值为 (0, 0, 0) 的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +19,7 @@ static Vector3 Zero()
|
||||
```cpp
|
||||
Vector3 origin = Vector3::Zero();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 类总览](vector3.md) - 返回类总览
|
||||
|
||||
Reference in New Issue
Block a user