2#include "tools/Matrix3x3d.h"
4Matrix3x3d::Matrix3x3d()
9Matrix3x3d::Matrix3x3d(
double m00,
double m01,
double m02,
10 double m10,
double m11,
double m12,
11 double m20,
double m21,
double m22)
26 for (
int i = 0; i < 9; i++)
32void Matrix3x3d::set(
double m00,
double m01,
double m02,
33 double m10,
double m11,
double m12,
34 double m20,
double m21,
double m22)
49 for (
int i = 0; i < 9; i++)
55void Matrix3x3d::setZero()
57 for (
int i = 0; i < 9; i++)
63void Matrix3x3d::setIdentity()
76void Matrix3x3d::setDiagonal(
double d)
83double Matrix3x3d::get(
int row,
int col)
85 return _m[(3 * row + col)];
88void Matrix3x3d::set(
int row,
int col,
double value)
90 _m[(3 * row + col)] = value;
93void Matrix3x3d::getColumn(
int col,
Vector3d &v)
100void Matrix3x3d::setColumn(
int col,
Vector3d v)
107void Matrix3x3d::scale(
double s)
109 for (
int i = 0; i < 9; i++)
117 for (
int i = 0; i < 9; i++)
125 for (
int i = 0; i < 9; i++)
131void Matrix3x3d::transpose()
146 result._m[0] = _m[0];
147 result._m[1] = _m[3];
148 result._m[2] = _m[6];
149 result._m[3] = _m[1];
150 result._m[4] = _m[4];
151 result._m[5] = _m[7];
152 result._m[6] = _m[2];
153 result._m[7] = _m[5];
154 result._m[8] = _m[8];
159 for (
int i = 0; i < 9; i++)
161 result._m[i] = a._m[i] + b._m[i];
167 result.set(a._m[0] * b._m[0] + a._m[1] * b._m[3] + a._m[2] * b._m[6],
168 a._m[0] * b._m[1] + a._m[1] * b._m[4] + a._m[2] * b._m[7],
169 a._m[0] * b._m[2] + a._m[1] * b._m[5] + a._m[2] * b._m[8],
170 a._m[3] * b._m[0] + a._m[4] * b._m[3] + a._m[5] * b._m[6],
171 a._m[3] * b._m[1] + a._m[4] * b._m[4] + a._m[5] * b._m[7],
172 a._m[3] * b._m[2] + a._m[4] * b._m[5] + a._m[5] * b._m[8],
173 a._m[6] * b._m[0] + a._m[7] * b._m[3] + a._m[8] * b._m[6],
174 a._m[6] * b._m[1] + a._m[7] * b._m[4] + a._m[8] * b._m[7],
175 a._m[6] * b._m[2] + a._m[7] * b._m[5] + a._m[8] * b._m[8]);
180 result.set( a._m[0] * v.x + a._m[1] * v.y + a._m[2] * v.z,
181 a._m[3] * v.x + a._m[4] * v.y + a._m[5] * v.z,
182 a._m[6] * v.x + a._m[7] * v.y + a._m[8] * v.z);
185double Matrix3x3d::determinant()
187 return get(0, 0) * (get(1, 1) * get(2, 2) - get(2, 1) * get(1, 2))
188 - get(0, 1) * (get(1, 0) * get(2, 2) - get(1, 2) * get(2, 0))
189 + get(0, 2) * (get(1, 0) * get(2, 1) - get(1, 1) * get(2, 0));
194 double d = determinant();
199 double invdet = 1.0 / d;
200 result.set( (_m[4] * _m[8] - _m[7] * _m[5]) * invdet,
201 -(_m[1] * _m[8] - _m[2] * _m[7]) * invdet,
202 (_m[1] * _m[5] - _m[2] * _m[4]) * invdet,
203 -(_m[3] * _m[8] - _m[5] * _m[6]) * invdet,
204 (_m[0] * _m[8] - _m[2] * _m[6]) * invdet,
205 -(_m[0] * _m[5] - _m[3] * _m[2]) * invdet,
206 (_m[3] * _m[7] - _m[6] * _m[4]) * invdet,
207 -(_m[0] * _m[7] - _m[6] * _m[1]) * invdet,
208 (_m[0] * _m[4] - _m[3] * _m[1]) * invdet);