GraceFt v2.3
开源图形引擎 EGE(Easy Graphics Engine) 的高层封装库
 
载入中...
搜索中...
未找到
GFt::Matrix< M, N, T > 模板类 参考

矩阵类模板 更多...

#include <Matrix.hpp>

Public 成员函数

constexpr Matrix (const Matrix &other)
 
constexpr Matrix (const T(&arr)[M][N])
 构造函数
 
constexpr Matrix (Matrix &&other)
 
constexpr Matrix (T val=0)
 构造函数
 
constexpr Matrix adjugate () const
 求矩阵的伴随矩阵
 
consteval size cols () const
 获取矩阵的列数
 
const Matrixcorrect (T eis=static_cast< T >(1e-6))
 执行矩阵误差修正操作
 
consteval size count () const
 获取矩阵的元素个数
 
constexpr T det () const
 求矩阵的行列式值
 
constexpr Matrix inverse () const
 求矩阵的逆矩阵
 
constexpr operator bool () const
 将矩阵转换到 bool 值
 
template<typename U >
requires std::is_arithmetic_v<U>
constexpr operator Matrix< M, N, U > () const
 矩阵类型转换函数
 
constexpr bool operator! () const
 逻辑非运算符重载
 
constexpr bool operator!= (const Matrix &other) const
 不等于比较运算符重载
 
constexpr Toperator() (size i, size j)
 以 Matrix(M,N) 的形式访问矩阵数据
 
constexpr const Toperator() (size i, size j) const
 以 Matrix(M,N) 的形式访问矩阵数据的 const 版本
 
template<size P>
requires (P > 0)
constexpr Matrix< M, P, Toperator* (const Matrix< N, P, T > &other) const
 矩阵乘法运算符重载
 
constexpr Matrix operator* (T scalar) const
 矩阵数乘运算符重载
 
constexpr Matrixoperator*= (T scalar)
 矩阵数乘且赋值运算符重载
 
constexpr Matrix operator+ () const
 矩阵加号运算符重载
 
constexpr Matrix operator+ (const Matrix &other) const
 矩阵加法运算符重载
 
constexpr Matrixoperator+= (const Matrix &other)
 矩阵加且赋值运算符重载
 
constexpr Matrix operator- () const
 矩阵负号运算符重载
 
constexpr Matrix operator- (const Matrix &other) const
 矩阵减法运算符重载
 
constexpr Matrixoperator-= (const Matrix &other)
 矩阵减且赋值运算符重载
 
constexpr Matrix operator/ (T scalar) const
 矩阵数乘(1/scalar)运算符重载
 
constexpr Matrixoperator/= (T scalar)
 矩阵数乘(1/scalar)且赋值运算符重载
 
constexpr Matrixoperator= (const Matrix &other)
 
constexpr Matrixoperator= (Matrix &&other)
 
constexpr bool operator== (const Matrix &other) const
 等于比较运算符重载
 
constexpr Toperator[] (size i)
 Matrix[M][N] 的形式访问矩阵数据
 
constexpr const Toperator[] (size i) const
 Matrix[M][N] 的形式访问矩阵数据的 const 版本
 
consteval size rows () const
 获取矩阵的行数
 
constexpr Matrix< N, M, Ttranspose () const
 求矩阵的转置矩阵
 

静态 Public 成员函数

static constexpr Matrix< M, N, TI ()
 

友元

constexpr Matrix operator* (T scalar, const Matrix &mat)
 矩阵数乘运算符重载
 

详细描述

template<size M, size N, typename T>
requires (M > 0 && N > 0) && std::is_arithmetic_v<T>
class GFt::Matrix< M, N, T >

矩阵类模板

此处采用行主序矩阵,即 data[i][j] 表示第 i 行第 j 列元素

模板参数
M行数
N列数
T数据类型

构造及析构函数说明

◆ Matrix() [1/4]

template<size M, size N, typename T >
GFt::Matrix< M, N, T >::Matrix ( T val = 0)
inlineconstexpr

构造函数

此构造函数将以指定值初始化矩阵,默认初始化为零矩阵

参数
val初始值

◆ Matrix() [2/4]

template<size M, size N, typename T >
GFt::Matrix< M, N, T >::Matrix ( const T(&) arr[M][N])
inlineconstexpr

构造函数

此构造函数将以给定数组初始化矩阵

参数
arr数组

◆ Matrix() [3/4]

template<size M, size N, typename T >
GFt::Matrix< M, N, T >::Matrix ( const Matrix< M, N, T > & other)
inlineconstexpr

◆ Matrix() [4/4]

template<size M, size N, typename T >
GFt::Matrix< M, N, T >::Matrix ( Matrix< M, N, T > && other)
inlineconstexpr

成员函数说明

◆ adjugate()

template<size M, size N, typename T >
Matrix GFt::Matrix< M, N, T >::adjugate ( ) const
inlineconstexpr

求矩阵的伴随矩阵

采用伴随矩阵定义式求伴随矩阵

返回
伴随矩阵

◆ cols()

template<size M, size N, typename T >
size GFt::Matrix< M, N, T >::cols ( ) const
inlineconsteval

获取矩阵的列数

返回
矩阵的列数

◆ correct()

template<size M, size N, typename T >
const Matrix & GFt::Matrix< M, N, T >::correct ( T eis = static_cast<T>(1e-6))
inline

执行矩阵误差修正操作

此操作为将矩阵元素与最近邻整数差值小于 eis 的元素都置为最近邻整数

对于非浮点数矩阵,此操作无效

参数
eis误差范围

◆ count()

template<size M, size N, typename T >
size GFt::Matrix< M, N, T >::count ( ) const
inlineconsteval

获取矩阵的元素个数

返回
矩阵的元素个数

◆ det()

template<size M, size N, typename T >
T GFt::Matrix< M, N, T >::det ( ) const
inlineconstexpr

求矩阵的行列式值

采用定义式求行列式值

若矩阵不是方阵,则返回零值

返回
矩阵的行列式值

◆ I()

template<size M, size N, typename T >
static constexpr Matrix< M, N, T > GFt::Matrix< M, N, T >::I ( )
inlinestaticconstexpr

◆ inverse()

template<size M, size N, typename T >
Matrix GFt::Matrix< M, N, T >::inverse ( ) const
inlineconstexpr

求矩阵的逆矩阵

采用伴随矩阵法求逆矩阵

若矩阵不可逆,则返回零矩阵

返回
逆矩阵

◆ operator bool()

template<size M, size N, typename T >
GFt::Matrix< M, N, T >::operator bool ( ) const
inlineexplicitconstexpr

将矩阵转换到 bool 值

若矩阵为零矩阵,则返回 false;否则返回 true

返回
转换结果

◆ operator Matrix< M, N, U >()

template<size M, size N, typename T >
template<typename U >
requires std::is_arithmetic_v<U>
GFt::Matrix< M, N, T >::operator Matrix< M, N, U > ( ) const
inlineexplicitconstexpr

矩阵类型转换函数

矩阵类型转换函数,将矩阵的元素类型转换为 U 类型

模板参数
U目标类型
返回
转换后的矩阵对象

◆ operator!()

template<size M, size N, typename T >
bool GFt::Matrix< M, N, T >::operator! ( ) const
inlineconstexpr

逻辑非运算符重载

相当于 !static_cast<bool>(*this)

返回
逻辑非运算结果

◆ operator!=()

template<size M, size N, typename T >
bool GFt::Matrix< M, N, T >::operator!= ( const Matrix< M, N, T > & other) const
inlineconstexpr

不等于比较运算符重载

相当于 !(*this == other)

参数
other另一个矩阵
返回
不等比较结果

◆ operator()() [1/2]

template<size M, size N, typename T >
T & GFt::Matrix< M, N, T >::operator() ( size i,
size j )
inlineconstexpr

以 Matrix(M,N) 的形式访问矩阵数据

返回
T 的引用

◆ operator()() [2/2]

template<size M, size N, typename T >
const T & GFt::Matrix< M, N, T >::operator() ( size i,
size j ) const
inlineconstexpr

以 Matrix(M,N) 的形式访问矩阵数据的 const 版本

返回
T 的 const 引用

◆ operator*() [1/2]

template<size M, size N, typename T >
template<size P>
requires (P > 0)
Matrix< M, P, T > GFt::Matrix< M, N, T >::operator* ( const Matrix< N, P, T > & other) const
inlineconstexpr

矩阵乘法运算符重载

执行矩阵乘法时要确保左操作数的列数等于右操作数的行数

模板参数
P另一个矩阵的列数
参数
other另一个矩阵
返回
矩阵乘法结果

◆ operator*() [2/2]

template<size M, size N, typename T >
Matrix GFt::Matrix< M, N, T >::operator* ( T scalar) const
inlineconstexpr

矩阵数乘运算符重载

矩阵数乘运算,返回矩阵与标量相乘结果

参数
scalar标量
返回
矩阵数乘结果

◆ operator*=()

template<size M, size N, typename T >
Matrix & GFt::Matrix< M, N, T >::operator*= ( T scalar)
inlineconstexpr

矩阵数乘且赋值运算符重载

相当于 this = this * scalar

参数
scalar标量
返回
矩阵数乘且赋值结果

◆ operator+() [1/2]

template<size M, size N, typename T >
Matrix GFt::Matrix< M, N, T >::operator+ ( ) const
inlineconstexpr

矩阵加号运算符重载

返回
自身

◆ operator+() [2/2]

template<size M, size N, typename T >
Matrix GFt::Matrix< M, N, T >::operator+ ( const Matrix< M, N, T > & other) const
inlineconstexpr

矩阵加法运算符重载

矩阵加法运算,返回矩阵相加结果

参数
other另一个矩阵
返回
矩阵加法结果

◆ operator+=()

template<size M, size N, typename T >
Matrix & GFt::Matrix< M, N, T >::operator+= ( const Matrix< M, N, T > & other)
inlineconstexpr

矩阵加且赋值运算符重载

相当于 this = this + other

参数
other另一个矩阵
返回
矩阵加且赋值结果

◆ operator-() [1/2]

template<size M, size N, typename T >
Matrix GFt::Matrix< M, N, T >::operator- ( ) const
inlineconstexpr

矩阵负号运算符重载

相当于 0 - this

返回
矩阵负号运算结果

◆ operator-() [2/2]

template<size M, size N, typename T >
Matrix GFt::Matrix< M, N, T >::operator- ( const Matrix< M, N, T > & other) const
inlineconstexpr

矩阵减法运算符重载

矩阵减法运算,返回矩阵相减结果

参数
other另一个矩阵
返回
矩阵减法结果

◆ operator-=()

template<size M, size N, typename T >
Matrix & GFt::Matrix< M, N, T >::operator-= ( const Matrix< M, N, T > & other)
inlineconstexpr

矩阵减且赋值运算符重载

相当于 this = this - other

参数
other另一个矩阵
返回
矩阵减且赋值结果

◆ operator/()

template<size M, size N, typename T >
Matrix GFt::Matrix< M, N, T >::operator/ ( T scalar) const
inlineconstexpr

矩阵数乘(1/scalar)运算符重载

矩阵数乘(1/scalar)运算,返回矩阵与标量相乘结果

参数
scalar标量
返回
矩阵数乘(1/scalar)结果

◆ operator/=()

template<size M, size N, typename T >
Matrix & GFt::Matrix< M, N, T >::operator/= ( T scalar)
inlineconstexpr

矩阵数乘(1/scalar)且赋值运算符重载

相当于 this = this / scalar

参数
scalar标量
返回
矩阵数乘(1/scalar)且赋值结果

◆ operator=() [1/2]

template<size M, size N, typename T >
Matrix & GFt::Matrix< M, N, T >::operator= ( const Matrix< M, N, T > & other)
inlineconstexpr

◆ operator=() [2/2]

template<size M, size N, typename T >
Matrix & GFt::Matrix< M, N, T >::operator= ( Matrix< M, N, T > && other)
inlineconstexpr

◆ operator==()

template<size M, size N, typename T >
bool GFt::Matrix< M, N, T >::operator== ( const Matrix< M, N, T > & other) const
inlineconstexpr

等于比较运算符重载

矩阵相等比较,若所有元素都相等则返回 true,否则返回 false

此函数对于浮点数比较是安全的

参数
other另一个矩阵
返回
相等比较结果

◆ operator[]() [1/2]

template<size M, size N, typename T >
T * GFt::Matrix< M, N, T >::operator[] ( size i)
inlineconstexpr

Matrix[M][N] 的形式访问矩阵数据

返回
T[M] 的引用

◆ operator[]() [2/2]

template<size M, size N, typename T >
const T * GFt::Matrix< M, N, T >::operator[] ( size i) const
inlineconstexpr

Matrix[M][N] 的形式访问矩阵数据的 const 版本

返回
const T[M] 的引用

◆ rows()

template<size M, size N, typename T >
size GFt::Matrix< M, N, T >::rows ( ) const
inlineconsteval

获取矩阵的行数

返回
矩阵的行数

◆ transpose()

template<size M, size N, typename T >
Matrix< N, M, T > GFt::Matrix< M, N, T >::transpose ( ) const
inlineconstexpr

求矩阵的转置矩阵

返回
转置矩阵

友元及相关符号说明

◆ operator*

template<size M, size N, typename T >
Matrix operator* ( T scalar,
const Matrix< M, N, T > & mat )
friend

矩阵数乘运算符重载

矩阵数乘运算,返回矩阵与标量相乘结果

参数
scalar标量
返回
矩阵数乘结果