#ifndef GEOMETRY_UTILS_MATRIX3X3_H #define GEOMETRY_UTILS_MATRIX3X3_H #include "MatrixNxNBase.h" namespace geometry_utils { template struct Matrix3x3Base : MatrixNxNBase { Matrix3x3Base() : MatrixNxNBase() {} Matrix3x3Base(T val) : MatrixNxNBase(val) {} Matrix3x3Base(const Matrix3x3Base& in) : MatrixNxNBase(in.data) {} Matrix3x3Base(const boost::array& in) : MatrixNxNBase(in) {} Matrix3x3Base(T (&in)[9]) : MatrixNxNBase(in) {} Matrix3x3Base(const Eigen::Matrix& in) : MatrixNxNBase(in) {} Matrix3x3Base(const MatrixNxNBase& in) : MatrixNxNBase(in) {} Matrix3x3Base(const MatrixNxMBase& in) : MatrixNxNBase(in) {} Matrix3x3Base(T R11, T R12, T R13, T R21, T R22, T R23, T R31, T R32, T R33) { this->data[0] = R11; this->data[1] = R12; this->data[2] = R13; this->data[3] = R21; this->data[4] = R22; this->data[5] = R23; this->data[6] = R31; this->data[7] = R32; this->data[8] = R33; } inline T Det() const { T a = this->data[0]; T b = this->data[1]; T c = this->data[2]; T d = this->data[3]; T e = this->data[4]; T f = this->data[5]; T g = this->data[6]; T h = this->data[7]; T i = this->data[8]; return (-(c * e * g) + b * f * g + c * d * h - a * f * h - b * d * i + a * e * i); } virtual inline MatrixNxNBase Inv() const { if (math::fabs(Det()) < std::numeric_limits::denorm_min()) throw std::runtime_error("Matrix3x3Base: appears singular"); T a = this->data[0]; T b = this->data[1]; T c = this->data[2]; T d = this->data[3]; T e = this->data[4]; T f = this->data[5]; T g = this->data[6]; T h = this->data[7]; T i = this->data[8]; T tmp[9] = {(f * h - e * i) / (c * e * g - b * f * g - c * d * h + a * f * h + b * d * i - a * e * i), (c * h - b * i) / (-(c * e * g) + b * f * g + c * d * h - a * f * h - b * d * i + a * e * i), (c * e - b * f) / (c * e * g - b * f * g - c * d * h + a * f * h + b * d * i - a * e * i), (f * g - d * i) / (-(c * e * g) + b * f * g + c * d * h - a * f * h - b * d * i + a * e * i), (c * g - a * i) / (c * e * g - b * f * g - c * d * h + a * f * h + b * d * i - a * e * i), (c * d - a * f) / (-(c * e * g) + b * f * g + c * d * h - a * f * h - b * d * i + a * e * i), (e * g - d * h) / (c * e * g - b * f * g - c * d * h + a * f * h + b * d * i - a * e * i), (b * g - a * h) / (-(c * e * g) + b * f * g + c * d * h - a * f * h - b * d * i + a * e * i), (b * d - a * e) / (c * e * g - b * f * g - c * d * h + a * f * h + b * d * i - a * e * i)}; return MatrixNxNBase(tmp); } }; inline Matrix3x3Base operator*(const float& lhs, const Matrix3x3Base& rhs) { return Matrix3x3Base(rhs.Scale(lhs)); } inline Matrix3x3Base operator*(const double& lhs, const Matrix3x3Base& rhs) { return Matrix3x3Base(rhs.Scale(lhs)); } typedef Matrix3x3Base Matrix3x3f; typedef Matrix3x3Base Mat33f; typedef Matrix3x3Base Matrix3x3d; typedef Matrix3x3Base Mat33d; typedef Matrix3x3Base Matrix3x3; typedef Matrix3x3Base Mat33; } #endif