# Quaternion 四元数结构体,用于表示 3D 旋转,避免欧拉角的万向锁问题。 **头文件:** `#include ` **命名空间:** `XCEngine::Math` ## 结构体定义 ```cpp struct Quaternion { float x = 0.0f; float y = 0.0f; float z = 0.0f; float w = 1.0f; }; ``` ## 静态工厂方法 | 方法 | 返回值 | 描述 | |------|--------|------| | [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 模块总览