Added way to check if matrix is orthogonal
This commit is contained in:
parent
548de30100
commit
af0572cc87
|
@ -44,6 +44,7 @@ public:
|
||||||
|
|
||||||
bool IsInvertable();
|
bool IsInvertable();
|
||||||
bool IsSquare();
|
bool IsSquare();
|
||||||
|
bool IsOrthogonal();
|
||||||
|
|
||||||
|
|
||||||
// Transformation / arithmetic functions
|
// Transformation / arithmetic functions
|
||||||
|
@ -80,6 +81,8 @@ public:
|
||||||
Matrix operator*(const Matrix& other);
|
Matrix operator*(const Matrix& other);
|
||||||
void operator*=(const Matrix& other);
|
void operator*=(const Matrix& other);
|
||||||
|
|
||||||
|
bool operator==(const Matrix& other);
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& stream, const Matrix& other);
|
friend std::ostream& operator<<(std::ostream& stream, const Matrix& other);
|
||||||
private:
|
private:
|
||||||
doubleMatrix m_matrix;
|
doubleMatrix m_matrix;
|
||||||
|
@ -226,6 +229,19 @@ bool Matrix::IsSquare()
|
||||||
return m_rows == m_cols;
|
return m_rows == m_cols;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////
|
||||||
|
/// \brief Returns wether the matrix is orthogonal
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////
|
||||||
|
bool Matrix::IsOrthogonal()
|
||||||
|
{
|
||||||
|
if (!IsSquare())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return ((*this * _transpose(*this)) == Identity(m_rows));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
/// \brief Prints the whole matrix to the console
|
/// \brief Prints the whole matrix to the console
|
||||||
|
@ -699,6 +715,25 @@ void Matrix::operator*=(const Matrix& other)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Matrix::operator==(const Matrix& other)
|
||||||
|
{
|
||||||
|
DimensionsFitting(*this, other);
|
||||||
|
|
||||||
|
bool equal = true;
|
||||||
|
|
||||||
|
for (int row = 0; row < m_rows; row++) {
|
||||||
|
for (int col = 0; col < m_cols; col++) {
|
||||||
|
if (m_matrix[row][col] == other.GetNumber(row, col)) {
|
||||||
|
equal = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return equal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& stream, const Matrix& other)
|
std::ostream& operator<<(std::ostream& stream, const Matrix& other)
|
||||||
{
|
{
|
||||||
for (uint row = 0; row < other.m_rows; row++)
|
for (uint row = 0; row < other.m_rows; row++)
|
||||||
|
|
|
@ -20,8 +20,7 @@ int main(int argc, char** argv)
|
||||||
myMatrix.SetNumber(2, 1, 0);
|
myMatrix.SetNumber(2, 1, 0);
|
||||||
myMatrix.SetNumber(2, 2, 1);
|
myMatrix.SetNumber(2, 2, 1);
|
||||||
|
|
||||||
Matrix inverse = myMatrix;
|
Matrix inverse = Invert(myMatrix);
|
||||||
inverse.Invert();
|
|
||||||
|
|
||||||
|
|
||||||
std::cout << myMatrix << std::endl;
|
std::cout << myMatrix << std::endl;
|
||||||
|
@ -30,6 +29,10 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
std::cout << mul(myMatrix, inverse) << std::endl;
|
std::cout << mul(myMatrix, inverse) << std::endl;
|
||||||
|
|
||||||
|
std::cout << Transpose(myMatrix) << std::endl;
|
||||||
|
std::cout << Transpose(myMatrix) * myMatrix << std::endl;
|
||||||
|
std::cout << myMatrix.IsOrthogonal() << std::endl;
|
||||||
|
|
||||||
getchar();
|
getchar();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue