Menu

[r120]: / trunk / include / small / dgemat2-function.hpp  Maximize  Restore  History

Download this file

47 lines (42 with data), 1.6 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
45
46
//=============================================================================
/*! calculate determinant */
inline double det(const dgemat2& A)
{
return A(0,0)*A(1,1)-A(0,1)*A(1,0);
}
//=============================================================================
/*! calculate inverse */
inline dgemat2 inv(const dgemat2& A)
{
const double Adet( det(A) );
dgemat2 Ainv;
Ainv(0,0)= A(1,1)/Adet; Ainv(0,1)=-A(0,1)/Adet;
Ainv(1,0)=-A(1,0)/Adet; Ainv(1,1)= A(0,0)/Adet;
return Ainv;
}
//=============================================================================
/*! return rotated tensor */
inline dgemat2 rotate(const dgemat2& m, const double& theta)
{
//dgemat2 R(t2m(theta)); return R*m*t(R);//too slow
double c(cos(theta)), s(sin(theta));
double cc(c*c), cs(c*s), ss(s*s);
dgemat2 mat;
mat(0,0) =m(0,0)*cc -(m(0,1)+m(1,0))*cs +m(1,1)*ss;
mat(0,1) =m(0,1)*cc +(m(0,0)-m(1,1))*cs -m(1,0)*ss;
mat(1,0) =m(1,0)*cc +(m(0,0)-m(1,1))*cs -m(0,1)*ss;
mat(1,1) =m(1,1)*cc +(m(0,1)+m(1,0))*cs +m(0,0)*ss;
return mat;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
/*! convert theta to 2x2 rotational matrix */
inline dgemat2 t2m(const double& theta)
{
dgemat2 R;
R(0,0)=cos(theta); R(0,1)=-sin(theta);
R(1,0)=sin(theta); R(1,1)=cos(theta);
return R;
}
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.