1 #ifndef ACG_MATH_MATRIX3X3T_HH_ 2 #define ACG_MATH_MATRIX3X3T_HH_ 6 #include <ACG/Math/VectorT.hh> 10 #if defined(_MSC_VER) && _MSC_VER < 1900 12 typedef unsigned char uint_fast8_t;
20 template<
typename Scalar>
64 values_(
std::move(row_major)) {}
66 constexpr
bool operator==(
const Matrix3x3T &rhs)
const {
67 return values_ == rhs.values_;
76 constexpr
static uint_fast8_t
indexof(uint_fast8_t r, uint_fast8_t c) {
80 constexpr
const Scalar &operator() (uint_fast8_t r, uint_fast8_t c)
const {
84 Scalar &operator() (uint_fast8_t r, uint_fast8_t c) {
89 constexpr
const Scalar &
operator[] (uint_fast8_t i)
const {
98 Vec3 getRow(uint_fast8_t r)
const {
99 return Vec3((*
this)(r,0), (*
this)(r,1), (*
this)(r,2));
101 Vec3 getCol(uint_fast8_t c)
const {
102 return Vec3((*
this)(0,c), (*
this)(1,c), (*
this)(2,c));
107 (*this)(0, 0) * rhs(0, 0) + (*this)(0, 1) * rhs(1, 0) + (*this)(0, 2) * rhs(2, 0),
108 (*this)(0, 0) * rhs(0, 1) + (*this)(0, 1) * rhs(1, 1) + (*this)(0, 2) * rhs(2, 1),
109 (*this)(0, 0) * rhs(0, 2) + (*this)(0, 1) * rhs(1, 2) + (*this)(0, 2) * rhs(2, 2),
111 (*this)(1, 0) * rhs(0, 0) + (*this)(1, 1) * rhs(1, 0) + (*this)(1, 2) * rhs(2, 0),
112 (*this)(1, 0) * rhs(0, 1) + (*this)(1, 1) * rhs(1, 1) + (*this)(1, 2) * rhs(2, 1),
113 (*this)(1, 0) * rhs(0, 2) + (*this)(1, 1) * rhs(1, 2) + (*this)(1, 2) * rhs(2, 2),
115 (*this)(2, 0) * rhs(0, 0) + (*this)(2, 1) * rhs(1, 0) + (*this)(2, 2) * rhs(2, 0),
116 (*this)(2, 0) * rhs(0, 1) + (*this)(2, 1) * rhs(1, 1) + (*this)(2, 2) * rhs(2, 1),
117 (*this)(2, 0) * rhs(0, 2) + (*this)(2, 1) * rhs(1, 2) + (*this)(2, 2) * rhs(2, 2),
121 constexpr Vec3 operator*(
const Vec3 &rhs)
const {
123 (*
this)(0, 0) * rhs[0] + (*
this)(0, 1) * rhs[1] + (*
this)(0, 2) * rhs[2],
124 (*
this)(1, 0) * rhs[0] + (*
this)(1, 1) * rhs[1] + (*
this)(1, 2) * rhs[2],
125 (*
this)(2, 0) * rhs[0] + (*
this)(2, 1) * rhs[1] + (*
this)(2, 2) * rhs[2]
129 constexpr
friend Vec3 operator*(Vec3 v,
const Matrix3x3T &rhs) {
131 rhs(0, 0) * v[0] + rhs(0, 1) * v[1] + rhs(0, 2) * v[2],
132 rhs(1, 0) * v[0] + rhs(1, 1) * v[1] + rhs(1, 2) * v[2],
133 rhs(2, 0) * v[0] + rhs(2, 1) * v[1] + rhs(2, 2) * v[2]
137 constexpr
Matrix3x3T operator*(Scalar c)
const {
139 (*this)[0] * c, (*this)[1] * c, (*this)[2] * c,
140 (*this)[3] * c, (*this)[4] * c, (*this)[5] * c,
141 (*this)[6] * c, (*this)[7] * c, (*this)[8] * c,
147 rhs[0] * c, rhs[1] * c, rhs[2] * c,
148 rhs[3] * c, rhs[4] * c, rhs[5] * c,
149 rhs[6] * c, rhs[7] * c, rhs[8] * c,
155 (*this)[0] + rhs[0], (*this)[1] + rhs[1], (*this)[2] + rhs[2],
156 (*this)[3] + rhs[3], (*this)[4] + rhs[4], (*this)[5] + rhs[5],
157 (*this)[6] + rhs[6], (*this)[7] + rhs[7], (*this)[8] + rhs[8],
163 (*this)[0] - rhs[0], (*this)[1] - rhs[1], (*this)[2] - rhs[2],
164 (*this)[3] - rhs[3], (*this)[4] - rhs[4], (*this)[5] - rhs[5],
165 (*this)[6] - rhs[6], (*this)[7] - rhs[7], (*this)[8] - rhs[8],
171 -values_[0], -values_[1], -values_[2],
172 -values_[3], -values_[4], -values_[5],
173 -values_[6], -values_[7], -values_[8]
178 (*this) = operator*(rhs);
182 constexpr Scalar det()
const {
183 return (*
this)(0, 0) * ((*
this)(1, 1) * (*
this)(2, 2) - (*
this)(2, 1) * (*
this)(1, 2)) -
184 (*this)(0, 1) * ((*
this)(1, 0) * (*
this)(2, 2) - (*
this)(1, 2) * (*
this)(2, 0)) +
185 (*this)(0, 2) * ((*
this)(1, 0) * (*
this)(2, 1) - (*
this)(1, 1) * (*
this)(2, 0));
197 constexpr Scalar trace()
const {
198 return (*
this)[0] + (*this)[4] + (*this)[8];
202 std::swap(values_[1], values_[3]);
203 std::swap(values_[2], values_[6]);
204 std::swap(values_[5], values_[7]);
209 values_[0], values_[3], values_[6],
210 values_[1], values_[4], values_[7],
211 values_[2], values_[5], values_[8],
220 const Scalar invdet = 1.0 / det();
222 ((*this)(1, 1) * (*
this)(2, 2) - (*
this)(2, 1) * (*
this)(1, 2)) * invdet,
223 ((*this)(0, 2) * (*
this)(2, 1) - (*
this)(0, 1) * (*
this)(2, 2)) * invdet,
224 ((*this)(0, 1) * (*
this)(1, 2) - (*
this)(0, 2) * (*
this)(1, 1)) * invdet,
225 ((*this)(1, 2) * (*
this)(2, 0) - (*
this)(1, 0) * (*
this)(2, 2)) * invdet,
226 ((*this)(0, 0) * (*
this)(2, 2) - (*
this)(0, 2) * (*
this)(2, 0)) * invdet,
227 ((*this)(1, 0) * (*
this)(0, 2) - (*
this)(0, 0) * (*
this)(1, 2)) * invdet,
228 ((*this)(1, 0) * (*
this)(2, 1) - (*
this)(2, 0) * (*
this)(1, 1)) * invdet,
229 ((*this)(2, 0) * (*
this)(0, 1) - (*
this)(0, 0) * (*
this)(2, 1)) * invdet,
230 ((*this)(0, 0) * (*
this)(1, 1) - (*
this)(1, 0) * (*
this)(0, 1)) * invdet,
234 constexpr Scalar frobeniusSquared()
const {
235 return std::inner_product(
236 values_.begin(), values_.end(), values_.begin(), Scalar(0.0));
239 constexpr
double frobenius()
const {
240 return std::sqrt(frobeniusSquared());
245 std::ostream &operator<< (std::ostream &os,
const Matrix3x3T &m) {
246 os <<
"[[" << m[0] <<
", " << m[1] <<
", " << m[2] <<
"], " 247 "[" << m[3] <<
", " << m[4] <<
", " << m[5] <<
"], " 248 "[" << m[6] <<
", " << m[7] <<
", " << m[8] <<
"]]";
253 std::array<Scalar, 9> values_;
261 #if defined(_MSC_VER) && _MSC_VER < 1900 Namespace providing different geometric functions concerning angles.
constexpr Matrix3x3T(std::array< Scalar, 9 > row_major)
static constexpr uint_fast8_t indexof(uint_fast8_t r, uint_fast8_t c)
Map row/column index to linearized index.
constexpr const Scalar & operator[](uint_fast8_t i) const
Linearized row major access.