Implement Matrix3x3::IsRowOrthogonal IsColOrthogonal

This commit is contained in:
2024-03-21 18:37:43 -04:00
parent 802c321115
commit 06bb959e3f
2 changed files with 16 additions and 2 deletions

View File

@@ -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 * 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 * that applies M2 first, followed by M1 second
*/ */
class Matrix3x3 { class Matrix3x3 {
public: public:
enum { Rows = 3 }; enum { Rows = 3 };
@@ -137,7 +138,10 @@ namespace J3ML::LinearAlgebra {
Vector4 Mul(const Vector4& rhs) const; Vector4 Mul(const Vector4& rhs) const;
Quaternion Mul(const Quaternion& 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: protected:
float elems[3][3]; float elems[3][3];

View File

@@ -397,8 +397,18 @@ namespace J3ML::LinearAlgebra {
return *this * rhs; 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);
} }
} }