diff --git a/include/J3ML/LinearAlgebra/Matrix3x3.h b/include/J3ML/LinearAlgebra/Matrix3x3.h index e51a077..84840bd 100644 --- a/include/J3ML/LinearAlgebra/Matrix3x3.h +++ b/include/J3ML/LinearAlgebra/Matrix3x3.h @@ -26,6 +26,7 @@ namespace J3ML::LinearAlgebra { * vectors in the form M * v. This means that "Matrix3x3 M, M1, M2; M = M1 * M2;" gives a transformation M * that applies M2 first, followed by M1 second */ + class Matrix3x3 { public: enum { Rows = 3 }; @@ -137,7 +138,10 @@ namespace J3ML::LinearAlgebra { Vector4 Mul(const Vector4& rhs) const; Quaternion Mul(const Quaternion& rhs) const; - void IsColOrthogonal(); + // Returns true if the column vectors of this matrix are all perpendicular to each other. + bool IsColOrthogonal(float epsilon = 1e-3f) const; + // Returns true if the row vectors of this matrix are all perpendicular to each other. + bool IsRowOrthogonal(float epsilon = 1e-3f) const; protected: float elems[3][3]; diff --git a/src/J3ML/LinearAlgebra/Matrix3x3.cpp b/src/J3ML/LinearAlgebra/Matrix3x3.cpp index 4b5f24c..0896c0f 100644 --- a/src/J3ML/LinearAlgebra/Matrix3x3.cpp +++ b/src/J3ML/LinearAlgebra/Matrix3x3.cpp @@ -397,8 +397,18 @@ namespace J3ML::LinearAlgebra { return *this * rhs; } - void Matrix3x3::IsColOrthogonal() { + bool Matrix3x3::IsRowOrthogonal(float epsilon) const + { + return GetRow(0).IsPerpendicular(GetRow(1), epsilon) + && GetRow(0).IsPerpendicular(GetRow(2), epsilon) + && GetRow(1).IsPerpendicular(GetRow(2), epsilon); + } + bool Matrix3x3::IsColOrthogonal(float epsilon) const + { + return GetColumn(0).IsPerpendicular(GetColumn(1), epsilon) + && GetColumn(0).IsPerpendicular(GetColumn(2), epsilon) + && GetColumn(1).IsPerpendicular(GetColumn(2), epsilon); } }