Menu

[r116]: / trunk / include / small / dgemat3-function.hpp  Maximize  Restore  History

Download this file

45 lines (41 with data), 1.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//=============================================================================
/*! calculate determinant */
inline double det(const dgemat3& A)
{
return
+A(0,0)*A(1,1)*A(2,2) -A(0,0)*A(1,2)*A(2,1)
+A(0,1)*A(1,2)*A(2,0) -A(0,1)*A(1,0)*A(2,2)
+A(0,2)*A(1,0)*A(2,1) -A(0,2)*A(1,1)*A(2,0);
}
//=============================================================================
/*! calculate inverse */
inline dgemat3 inv(const dgemat3& A)
{
const double Adet( det(A) );
dgemat3 Ainv;
Ainv(0,0) =(A(1,1)*A(2,2)-A(1,2)*A(2,1))/Adet;
Ainv(0,1) =(A(0,2)*A(2,1)-A(0,1)*A(2,2))/Adet;
Ainv(0,2) =(A(0,1)*A(1,2)-A(0,2)*A(1,1))/Adet;
Ainv(1,0) =(A(1,2)*A(2,0)-A(1,0)*A(2,2))/Adet;
Ainv(1,1) =(A(0,0)*A(2,2)-A(0,2)*A(2,0))/Adet;
Ainv(1,2) =(A(0,2)*A(1,0)-A(0,0)*A(1,2))/Adet;
Ainv(2,0) =(A(1,0)*A(2,1)-A(1,1)*A(2,0))/Adet;
Ainv(2,1) =(A(0,1)*A(2,0)-A(0,0)*A(2,1))/Adet;
Ainv(2,2) =(A(0,0)*A(1,1)-A(0,1)*A(1,0))/Adet;
return Ainv;
}
//=============================================================================
/*! */
inline dgemat3 rotate(const dgemat3& m, const dquater& q)
{
dgemat3 R(q2m(q));
return R*m*t(R);
}
//=============================================================================
/*! */
inline dquater m2q(const dgemat3& m)
{
dcovec3 v( m(2,1)-m(1,2), m(0,2)-m(2,0), m(1,0)-m(0,1) );
double t( acos(0.5*(m(0,0)+m(1,1)+m(2,2)-1.)) );
return vt2q(v,t);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.