docs: update math API docs
This commit is contained in:
@@ -1,20 +1,34 @@
|
||||
# Quaternion::Dot
|
||||
|
||||
```cpp
|
||||
float Dot(const Quaternion& other) const
|
||||
float Dot(const Quaternion& other) const;
|
||||
```
|
||||
|
||||
计算两个四元数的点积。
|
||||
计算两个四元数的点积(各分量相乘后求和)。
|
||||
|
||||
**参数:**
|
||||
- `other` - 另一个四元数
|
||||
|
||||
**返回:** `float` - 点积结果
|
||||
**返回:** 点积结果
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
float dot = quat1.Dot(quat2);
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q1 = Quaternion::Identity();
|
||||
Quaternion q2 = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(90.0f));
|
||||
|
||||
float dot = q1.Dot(q2);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [Magnitude](magnitude.md) - 求模长
|
||||
|
||||
35
docs/api/math/quaternion/from-axis-angle.md
Normal file
35
docs/api/math/quaternion/from-axis-angle.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Quaternion::FromAxisAngle
|
||||
|
||||
```cpp
|
||||
static Quaternion FromAxisAngle(const Vector3& axis, float radians);
|
||||
```
|
||||
|
||||
从轴角表示创建四元数。使用半角公式进行转换。
|
||||
|
||||
**参数:**
|
||||
- `axis` - 旋转轴(会被归一化)
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** 表示该旋转的四元数
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
#include <XCEngine/Math/Math.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(90.0f));
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [FromEulerAngles](from-euler-angles.md) - 从欧拉角创建
|
||||
- [LookRotation](look-rotation.md) - 创建看向目标的旋转
|
||||
44
docs/api/math/quaternion/from-euler-angles.md
Normal file
44
docs/api/math/quaternion/from-euler-angles.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Quaternion::FromEulerAngles
|
||||
|
||||
```cpp
|
||||
static Quaternion FromEulerAngles(float pitch, float yaw, float roll);
|
||||
static Quaternion FromEulerAngles(const Vector3& euler);
|
||||
```
|
||||
|
||||
从欧拉角创建四元数。使用 YXZ 顺序(先绕 Y 轴 yaw,再绕 X 轴 pitch,最后绕 Z 轴 roll)。
|
||||
|
||||
**参数:**
|
||||
- `pitch` - 绕 X 轴旋转角度(弧度)
|
||||
- `yaw` - 绕 Y 轴旋转角度(弧度)
|
||||
- `roll` - 绕 Z 轴旋转角度(弧度)
|
||||
- `euler` - 欧拉角向量 (pitch, yaw, roll)
|
||||
|
||||
**返回:** 表示该旋转的四元数
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
#include <XCEngine/Math/Math.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q1 = Quaternion::FromEulerAngles(
|
||||
Math::Radians(45.0f),
|
||||
Math::Radians(30.0f),
|
||||
Math::Radians(60.0f)
|
||||
);
|
||||
|
||||
Quaternion q2 = Quaternion::FromEulerAngles(Vector3(45, 30, 60) * DEG_TO_RAD);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [FromAxisAngle](from-axis-angle.md) - 从轴角创建
|
||||
- [ToEulerAngles](to-euler-angles.md) - 转换为欧拉角
|
||||
37
docs/api/math/quaternion/from-rotation-matrix.md
Normal file
37
docs/api/math/quaternion/from-rotation-matrix.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Quaternion::FromRotationMatrix
|
||||
|
||||
```cpp
|
||||
static Quaternion FromRotationMatrix(const Matrix4x4& matrix);
|
||||
```
|
||||
|
||||
从 4x4 旋转矩阵创建四元数。矩阵必须是正交矩阵且行列式为 1。
|
||||
|
||||
**参数:**
|
||||
- `matrix` - 旋转矩阵
|
||||
|
||||
**返回:** 对应的四元数
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
#include <XCEngine/Math/Matrix4.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 rotMatrix;
|
||||
rotMatrix.m[0][0] = 1; rotMatrix.m[0][1] = 0; rotMatrix.m[0][2] = 0;
|
||||
rotMatrix.m[1][0] = 0; rotMatrix.m[1][1] = 0; rotMatrix.m[1][2] = -1;
|
||||
rotMatrix.m[2][0] = 0; rotMatrix.m[2][1] = 1; rotMatrix.m[2][2] = 0;
|
||||
|
||||
Quaternion q = Quaternion::FromRotationMatrix(rotMatrix);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [ToMatrix4x4](to-matrix4x4.md) - 转换为矩阵
|
||||
@@ -1,21 +0,0 @@
|
||||
# Quaternion::FromAxisAngle
|
||||
|
||||
```cpp
|
||||
static Quaternion FromAxisAngle(const Vector3& axis, float radians)
|
||||
```
|
||||
|
||||
从轴角创建四元数。
|
||||
|
||||
**参数:**
|
||||
- `axis` - 旋转轴(应为单位向量)
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** `Quaternion` - 表示旋转的四元数
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion rot = Quaternion::FromAxisAngle(Vector3::Up(), 90.0f * DEG_TO_RAD);
|
||||
```
|
||||
@@ -1,25 +0,0 @@
|
||||
# Quaternion::FromEulerAngles
|
||||
|
||||
```cpp
|
||||
static Quaternion FromEulerAngles(float pitch, float yaw, float roll)
|
||||
static Quaternion FromEulerAngles(const Vector3& euler)
|
||||
```
|
||||
|
||||
从欧拉角创建四元数。角度以弧度为单位。
|
||||
|
||||
**参数:**
|
||||
- `pitch` - 俯仰角(X 轴旋转)
|
||||
- `yaw` - 偏航角(Y 轴旋转)
|
||||
- `roll` - 翻滚角(Z 轴旋转)
|
||||
- `euler` - 欧拉角向量 (pitch, yaw, roll)
|
||||
|
||||
**返回:** `Quaternion` - 表示旋转的四元数
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion rot = Quaternion::FromEulerAngles(0.0f, 90.0f * DEG_TO_RAD, 0.0f);
|
||||
Quaternion rot2 = Quaternion::FromEulerAngles(Vector3(0.0f, 90.0f * DEG_TO_RAD, 0.0f));
|
||||
```
|
||||
@@ -1,21 +0,0 @@
|
||||
# Quaternion::FromRotationMatrix
|
||||
|
||||
```cpp
|
||||
static Quaternion FromRotationMatrix(const Matrix4x4& matrix)
|
||||
```
|
||||
|
||||
从旋转矩阵创建四元数。
|
||||
|
||||
**参数:**
|
||||
- `matrix` - 旋转矩阵
|
||||
|
||||
**返回:** `Quaternion` - 表示相同旋转的四元数
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 rotMat = Matrix4::RotationY(90.0f * DEG_TO_RAD);
|
||||
Quaternion quat = Quaternion::FromRotationMatrix(rotMat);
|
||||
```
|
||||
@@ -1,17 +1,28 @@
|
||||
# Quaternion::Identity
|
||||
|
||||
```cpp
|
||||
static Quaternion Identity()
|
||||
static Quaternion Identity();
|
||||
```
|
||||
|
||||
返回恒等四元数(无旋转)。
|
||||
返回单位四元数 (0, 0, 0, 1),表示无旋转。
|
||||
|
||||
**返回:** `Quaternion` - 值为 (0, 0, 0, 1) 的四元数
|
||||
**返回:** 单位四元数
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion identity = Quaternion::Identity();
|
||||
// identity = (0, 0, 0, 1)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
|
||||
@@ -1,17 +1,31 @@
|
||||
# Quaternion::Inverse
|
||||
|
||||
```cpp
|
||||
Quaternion Inverse() const
|
||||
Quaternion Inverse() const;
|
||||
```
|
||||
|
||||
返回四元数的逆(对于单位四元数就是共轭)。
|
||||
求四元数的逆。如果四元数已归一化,逆等于共轭。
|
||||
|
||||
**返回:** `Quaternion` - 逆四元数
|
||||
**返回:** 四元数的逆
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion inv = quat.Inverse();
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(90.0f));
|
||||
Quaternion inv = q.Inverse();
|
||||
|
||||
Quaternion identity = q * inv;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [Normalized](normalized.md) - 归一化四元数
|
||||
|
||||
33
docs/api/math/quaternion/look-rotation.md
Normal file
33
docs/api/math/quaternion/look-rotation.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Quaternion::LookRotation
|
||||
|
||||
```cpp
|
||||
static Quaternion LookRotation(const Vector3& forward, const Vector3& up = Vector3::Up());
|
||||
```
|
||||
|
||||
创建使 forward 方向朝向目标的旋转四元数。
|
||||
|
||||
**参数:**
|
||||
- `forward` - 前向方向(会被归一化)
|
||||
- `up` - 向上方向,默认为 Y 轴正方向
|
||||
|
||||
**返回:** 使 forward 朝向目标的旋转四元数
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q = Quaternion::LookRotation(Vector3(1, 0, 0));
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [FromAxisAngle](from-axis-angle.md) - 从轴角创建
|
||||
@@ -1,21 +0,0 @@
|
||||
# Quaternion::LookRotation
|
||||
|
||||
```cpp
|
||||
static Quaternion LookRotation(const Vector3& forward, const Vector3& up = Vector3::Up())
|
||||
```
|
||||
|
||||
创建使 forward 方向朝向目标的旋转四元数。
|
||||
|
||||
**参数:**
|
||||
- `forward` - 前方向向量
|
||||
- `up` - 上方向向量(默认 Y 轴向上)
|
||||
|
||||
**返回:** `Quaternion` - 看向方向的旋转
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion lookAt = Quaternion::LookRotation(target - position);
|
||||
```
|
||||
@@ -1,17 +1,30 @@
|
||||
# Quaternion::Magnitude
|
||||
|
||||
```cpp
|
||||
float Magnitude() const
|
||||
float Magnitude() const;
|
||||
```
|
||||
|
||||
计算四元数的模长。
|
||||
计算四元数的模长(欧几里得范数)。
|
||||
|
||||
**返回:** `float` - 四元数的模长
|
||||
**返回:** 四元数的模长
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
float mag = quat.Magnitude();
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(90.0f));
|
||||
float mag = q.Magnitude();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [Normalized](normalized.md) - 返回归一化四元数
|
||||
- [Dot](dot.md) - 点积
|
||||
|
||||
32
docs/api/math/quaternion/normalize.md
Normal file
32
docs/api/math/quaternion/normalize.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Quaternion::Normalize
|
||||
|
||||
```cpp
|
||||
static Quaternion Normalize(const Quaternion& q);
|
||||
```
|
||||
|
||||
静态归一化方法,返回给定四元数的归一化副本。如果模长接近 0,返回单位四元数。
|
||||
|
||||
**参数:**
|
||||
- `q` - 要归一化的四元数
|
||||
|
||||
**返回:** 归一化后的四元数
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(90.0f));
|
||||
Quaternion normalized = Quaternion::Normalize(q);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [Normalized](normalized.md) - 实例归一化方法
|
||||
@@ -1,40 +1,30 @@
|
||||
# Quaternion::Normalized / Normalize
|
||||
|
||||
## 实例方法
|
||||
# Quaternion::Normalized
|
||||
|
||||
```cpp
|
||||
Quaternion Normalized() const
|
||||
Quaternion Normalized() const;
|
||||
```
|
||||
|
||||
返回当前四元数的归一化副本(不修改原四元数)。
|
||||
返回归一化(单位化)后的四元数。如果模长接近 0,返回单位四元数。
|
||||
|
||||
**返回:** `Quaternion` - 归一化后的四元数副本
|
||||
**返回:** 归一化后的四元数
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion unit = quat.Normalized(); // quat 保持不变
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(90.0f));
|
||||
Quaternion normalized = q.Normalized();
|
||||
```
|
||||
|
||||
## 静态方法
|
||||
## 相关文档
|
||||
|
||||
```cpp
|
||||
static Quaternion Normalize(const Quaternion& q)
|
||||
```
|
||||
|
||||
归一化四元数。
|
||||
|
||||
**参数:**
|
||||
- `q` - 要归一化的四元数
|
||||
|
||||
**返回:** `Quaternion` - 归一化后的四元数
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion unit = Quaternion::Normalize(quat);
|
||||
```
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [Normalize](normalize.md) - 静态归一化方法
|
||||
- [Magnitude](magnitude.md) - 求模长
|
||||
|
||||
40
docs/api/math/quaternion/operator-mul.md
Normal file
40
docs/api/math/quaternion/operator-mul.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Quaternion::operator*
|
||||
|
||||
```cpp
|
||||
Quaternion operator*(const Quaternion& other) const;
|
||||
Vector3 operator*(const Quaternion& q, const Vector3& v);
|
||||
```
|
||||
|
||||
四元数乘法运算符。
|
||||
|
||||
**成员函数版本(四元数 * 四元数):**
|
||||
- `other` - 另一个四元数
|
||||
- **返回:** 组合旋转后的四元数
|
||||
|
||||
**全局函数版本(四元数 * 向量):**
|
||||
- `q` - 四元数
|
||||
- `v` - 要旋转的三维向量
|
||||
- **返回:** 旋转后的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q1 = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(90.0f));
|
||||
Quaternion q2 = Quaternion::FromAxisAngle(Vector3::Right(), Math::Radians(90.0f));
|
||||
|
||||
Quaternion combined = q1 * q2;
|
||||
Vector3 rotated = q1 * Vector3::Forward();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
@@ -1,23 +0,0 @@
|
||||
# Quaternion * Vector3
|
||||
|
||||
```cpp
|
||||
Vector3 operator*(const Quaternion& q, const Vector3& v)
|
||||
```
|
||||
|
||||
用四元数旋转向量。
|
||||
|
||||
**参数:**
|
||||
- `q` - 旋转四元数
|
||||
- `v` - 要旋转的向量
|
||||
|
||||
**返回:** `Vector3` - 旋转后的向量
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion rot = Quaternion::FromEulerAngles(0.0f, 90.0f * DEG_TO_RAD, 0.0f);
|
||||
Vector3 forward = Vector3::Forward();
|
||||
Vector3 rotated = rot * forward;
|
||||
```
|
||||
@@ -1,61 +1,72 @@
|
||||
# Quaternion
|
||||
|
||||
四元数结构体,用于表示 3D 旋转,避免欧拉角的万向锁问题。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Quaternion.h>`
|
||||
**类型**: `struct`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/Math/Quaternion.h`
|
||||
|
||||
## 结构体定义
|
||||
**描述**: 四元数,用于表示三维旋转
|
||||
|
||||
## 概述
|
||||
|
||||
Quaternion 提供了一套完整的三维旋转表示和操作方法。四元数可以避免欧拉角的万向节锁问题,并提供平滑的旋转插值(Slerp)。
|
||||
|
||||
## 结构体成员
|
||||
|
||||
| 成员 | 类型 | 描述 | 默认值 |
|
||||
|------|------|------|--------|
|
||||
| `x` | `float` | X 分量 | `0.0f` |
|
||||
| `y` | `float` | Y 分量 | `0.0f` |
|
||||
| `z` | `float` | Z 分量 | `0.0f` |
|
||||
| `w` | `float` | W 分量(标量部分) | `1.0f` |
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Identity`](identity.md) | 返回单位四元数 |
|
||||
| [`FromAxisAngle`](from-axis-angle.md) | 从轴角创建四元数 |
|
||||
| [`FromEulerAngles`](from-euler-angles.md) | 从欧拉角创建四元数 |
|
||||
| [`FromRotationMatrix`](from-rotation-matrix.md) | 从旋转矩阵创建四元数 |
|
||||
| [`Slerp`](slerp.md) | 球面线性插值 |
|
||||
| [`LookRotation`](look-rotation.md) | 创建看向目标的旋转 |
|
||||
| [`ToEulerAngles`](to-euler-angles.md) | 转换为欧拉角 |
|
||||
| [`ToMatrix4x4`](to-matrix4x4.md) | 转换为 4x4 矩阵 |
|
||||
| [`operator*`](operator-mul.md) | 四元数乘法 |
|
||||
| [`Inverse`](inverse.md) | 求四元数逆 |
|
||||
| [`Dot`](dot.md) | 点积 |
|
||||
| [`Magnitude`](magnitude.md) | 求模长 |
|
||||
| [`Normalized`](normalized.md) | 返回归一化四元数 |
|
||||
| [`Normalize`](normalize.md) | 归一化四元数(静态) |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
struct Quaternion {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
float w = 1.0f;
|
||||
};
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
#include <XCEngine/Math/Math.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
// 从欧拉角创建
|
||||
Quaternion q1 = Quaternion::FromEulerAngles(0, Math::Radians(90.0f), 0);
|
||||
|
||||
// 从轴角创建
|
||||
Quaternion q2 = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(45.0f));
|
||||
|
||||
// 组合旋转
|
||||
Quaternion combined = q1 * q2;
|
||||
|
||||
// 旋转向量
|
||||
Vector3 rotated = q2 * Vector3::Forward();
|
||||
|
||||
// 球面插值
|
||||
Quaternion result = Quaternion::Slerp(q1, q2, 0.5f);
|
||||
```
|
||||
|
||||
## 静态工厂方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Identity()](identity.md) | `Quaternion` | 返回 (0, 0, 0, 1),恒等旋转 |
|
||||
| [FromAxisAngle(axis, radians)](fromaxisangle.md) | `Quaternion` | 从轴角创建 |
|
||||
| [FromEulerAngles(pitch, yaw, roll)](fromeulerangles.md) | `Quaternion` | 从欧拉角创建(弧度) |
|
||||
| [FromEulerAngles(euler)](fromeulerangles.md) | `Quaternion` | 从 Vector3 欧拉角创建 |
|
||||
| [FromRotationMatrix(matrix)](fromrotationmatrix.md) | `Quaternion` | 从旋转矩阵创建 |
|
||||
| [Slerp(a, b, t)](slerp.md) | `Quaternion` | 球面线性插值 |
|
||||
| [LookRotation(forward, up)](lookrotation.md) | `Quaternion` | 看向方向 |
|
||||
|
||||
## 实例方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [ToEulerAngles()](toeulerangles.md) | `Vector3` | 转换为欧拉角(弧度) |
|
||||
| [ToMatrix4x4()](tomatrix4x4.md) | `Matrix4` | 转换为 4x4 旋转矩阵 |
|
||||
| [Inverse()](inverse.md) | `Quaternion` | 共轭/逆四元数 |
|
||||
| [Dot(other)](dot.md) | `float` | 点积 |
|
||||
| [Magnitude()](magnitude.md) | `float` | 模长 |
|
||||
| [Normalized()](normalized.md) | `Quaternion` | 归一化副本 |
|
||||
|
||||
## 静态方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Normalize(q)](normalized.md) | `Quaternion` | 归一化四元数 |
|
||||
|
||||
## 运算符
|
||||
|
||||
| 运算符 | 描述 |
|
||||
|--------|------|
|
||||
| `operator*(Quaternion, Quaternion)` | 组合旋转 |
|
||||
|
||||
## 与 Vector3 的乘法
|
||||
|
||||
[Vector3 * Quaternion](quaternion-multiply.md) - 用四元数旋转向量
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
- [Math 模块总览](../math.md) - Math 模块概览
|
||||
- [Vector3](../vector3/vector3.md) - 三维向量
|
||||
- [Matrix4](../matrix4/matrix4.md) - 4x4 矩阵
|
||||
|
||||
@@ -1,22 +1,38 @@
|
||||
# Quaternion::Slerp
|
||||
|
||||
```cpp
|
||||
static Quaternion Slerp(const Quaternion& a, const Quaternion& b, float t)
|
||||
static Quaternion Slerp(const Quaternion& a, const Quaternion& b, float t);
|
||||
```
|
||||
|
||||
在两个四元数之间进行球面线性插值。
|
||||
球面线性插值,在两个四元数之间进行平滑旋转插值。参数 t 会被 clamp 到 [0, 1] 范围。
|
||||
|
||||
**参数:**
|
||||
- `a` - 起始四元数
|
||||
- `b` - 结束四元数
|
||||
- `t` - 插值因子(0-1)
|
||||
- `b` - 目标四元数
|
||||
- `t` - 插值参数 [0, 1],0 返回 a,1 返回 b
|
||||
|
||||
**返回:** `Quaternion` - 插值结果
|
||||
**返回:** 插值结果四元数
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion lerped = Quaternion::Slerp(rot1, rot2, 0.5f);
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
#include <XCEngine/Math/Math.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q1 = Quaternion::FromAxisAngle(Vector3::Up(), 0);
|
||||
Quaternion q2 = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(180.0f));
|
||||
|
||||
Quaternion result = Quaternion::Slerp(q1, q2, 0.5f);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [Normalized](normalized.md) - 归一化四元数
|
||||
|
||||
37
docs/api/math/quaternion/to-euler-angles.md
Normal file
37
docs/api/math/quaternion/to-euler-angles.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Quaternion::ToEulerAngles
|
||||
|
||||
```cpp
|
||||
Vector3 ToEulerAngles() const;
|
||||
```
|
||||
|
||||
将四元数转换为欧拉角。返回顺序为 (pitch, yaw, roll),单位为弧度。
|
||||
|
||||
**返回:** 欧拉角向量 (pitch, yaw, roll),单位为弧度
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
#include <XCEngine/Math/Math.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q = Quaternion::FromEulerAngles(
|
||||
Math::Radians(45.0f),
|
||||
Math::Radians(30.0f),
|
||||
Math::Radians(60.0f)
|
||||
);
|
||||
|
||||
Vector3 euler = q.ToEulerAngles();
|
||||
// euler.x ≈ 45°, euler.y ≈ 30°, euler.z ≈ 60°
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [FromEulerAngles](from-euler-angles.md) - 从欧拉角创建
|
||||
30
docs/api/math/quaternion/to-matrix4x4.md
Normal file
30
docs/api/math/quaternion/to-matrix4x4.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Quaternion::ToMatrix4x4
|
||||
|
||||
```cpp
|
||||
Matrix4x4 ToMatrix4x4() const;
|
||||
```
|
||||
|
||||
将四元数转换为 4x4 旋转矩阵。
|
||||
|
||||
**返回:** 4x4 旋转矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
#include <XCEngine/Math/Matrix4.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(90.0f));
|
||||
Matrix4 m = q.ToMatrix4x4();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Quaternion](quaternion.md) - 返回类总览
|
||||
- [FromRotationMatrix](from-rotation-matrix.md) - 从矩阵创建
|
||||
@@ -1,18 +0,0 @@
|
||||
# Quaternion::ToEulerAngles
|
||||
|
||||
```cpp
|
||||
Vector3 ToEulerAngles() const
|
||||
```
|
||||
|
||||
将四元数转换为欧拉角(弧度)。
|
||||
|
||||
**返回:** `Vector3` - 欧拉角 (pitch, yaw, roll)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion rot = ...;
|
||||
Vector3 euler = rot.ToEulerAngles();
|
||||
```
|
||||
@@ -1,18 +0,0 @@
|
||||
# Quaternion::ToMatrix4x4
|
||||
|
||||
```cpp
|
||||
Matrix4x4 ToMatrix4x4() const
|
||||
```
|
||||
|
||||
将四元数转换为 4x4 旋转矩阵。
|
||||
|
||||
**返回:** `Matrix4x4` - 旋转矩阵
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion rot = ...;
|
||||
Matrix4 mat = rot.ToMatrix4x4();
|
||||
```
|
||||
Reference in New Issue
Block a user