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

85 lines
2.2 KiB
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.
# Matrix3 / Matrix3x3
**命名空间**: `XCEngine::Math`
**类型**: `struct`
**头文件**: `XCEngine/Math/Matrix3.h`
**描述**: 3x3 矩阵,用于旋转变换和线性代数运算。
## 概述
Matrix3别名 Matrix3x3是一个 3x3 浮点矩阵结构体,主要用于图形引擎中的旋转变换和线性代数运算。
**设计目的:**
- 旋转变换(绕 X/Y/Z 轴)
- 缩放变换
- 矩阵运算(乘法、转置、求逆、行列式计算)
**存储方式:** 行优先存储 (row-major)
```
m[row][col]
m[0][0] m[0][1] m[0][2]
m[1][0] m[1][1] m[1][2]
m[2][0] m[2][1] m[2][2]
```
**类型别名:**
```cpp
using Matrix3 = Matrix3x3;
```
## 结构体成员
| 成员 | 类型 | 描述 |
|------|------|------|
| `m[3][3]` | `float` | 矩阵元素数组,行优先存储 |
## 公共方法
| 方法 | 描述 |
|------|------|
| [`Identity()`](identity.md) | 获取单位矩阵 |
| [`Zero()`](zero.md) | 获取零矩阵 |
| [`RotationX()`](rotation-x.md) | 创建绕 X 轴旋转矩阵 |
| [`RotationY()`](rotation-y.md) | 创建绕 Y 轴旋转矩阵 |
| [`RotationZ()`](rotation-z.md) | 创建绕 Z 轴旋转矩阵 |
| [`Scale()`](scale.md) | 创建缩放矩阵 |
| [`operator*(Matrix3)`](operator-mul-matrix3.md) | 矩阵乘法 |
| [`operator*(Vector3)`](operator-mul-vector3.md) | 矩阵-向量乘法 |
| [`Transpose()`](transpose.md) | 转置矩阵 |
| [`Inverse()`](inverse.md) | 逆矩阵 |
| [`Determinant()`](determinant.md) | 行列式 |
| [`operator[]`](./operator-subscript.md) | 访问矩阵元素 |
## 使用示例
```cpp
#include <XCEngine/Math/Matrix3.h>
#include <XCEngine/Math/Vector3.h>
using namespace XCEngine::Math;
// 创建绕 Y 轴旋转 45 度的矩阵
Matrix3 rotation = Matrix3::RotationY(0.785f); // PI/4
// 对向量进行变换
Vector3 v(1.0f, 0.0f, 0.0f);
Vector3 rotated = rotation * v;
// 矩阵运算
Matrix3 m1 = Matrix3::RotationX(0.5f);
Matrix3 m2 = Matrix3::RotationY(0.3f);
Matrix3 combined = m1 * m2;
// 求逆矩阵
Matrix3 inv = combined.Inverse();
float det = combined.Determinant();
```
## 相关文档
- [Matrix4](../matrix4/matrix4.md) - 4x4 矩阵
- [Vector3](../vector3/vector3.md) - 三维向量
- [Math 模块总览](../math.md) - 返回模块总览