g4tools  5.4.0
Public Member Functions | Static Protected Member Functions | List of all members
tools::mat3< T > Class Template Reference
Inheritance diagram for tools::mat3< T >:
Inheritance graph
[legend]
Collaboration diagram for tools::mat3< T >:
Collaboration graph
[legend]

Public Member Functions

 mat3 ()
 
 mat3 (const mat< T, 3 > &a_from)
 
virtual ~mat3 ()
 
 mat3 (const mat3 &a_from)
 
mat3operator= (const mat3 &a_from)
 
 mat3 (const T &a_00, const T &a_01, const T &a_02, const T &a_10, const T &a_11, const T &a_12, const T &a_20, const T &a_21, const T &a_22)
 
void set_matrix (const mat3< T > &a_m)
 
void set_matrix (const T &a_00, const T &a_01, const T &a_02, const T &a_10, const T &a_11, const T &a_12, const T &a_20, const T &a_21, const T &a_22)
 
void set_scale (const T &a_s)
 
void set_scale (const T &a_1, const T &a_2, const T &a_3)
 
void set_rotate (const T &a_x, const T &a_y, const T &a_z, const T &a_angle, T(*a_sin)(T), T(*a_cos)(T))
 
bool get_rotate (T &a_x, T &a_y, T &a_z, T &a_angle, T(*a_acos)(T), T(*a_sin)(T), T(*a_sqrt)(T))
 
void mul_3 (T &a_x, T &a_y, T &a_z) const
 
void mul_rotate (const T &a_x, const T &a_y, const T &a_z, const T &a_angle, T(*a_sin)(T), T(*a_cos)(T))
 
void left_mul_rotate (const T &a_x, const T &a_y, const T &a_z, const T &a_angle, T(*a_sin)(T), T(*a_cos)(T))
 
void v00 (const T &a_value)
 
void v10 (const T &a_value)
 
void v20 (const T &a_value)
 
void v01 (const T &a_value)
 
void v11 (const T &a_value)
 
void v21 (const T &a_value)
 
void v02 (const T &a_value)
 
void v12 (const T &a_value)
 
void v22 (const T &a_value)
 
const T & v00 () const
 
const T & v10 () const
 
const T & v20 () const
 
const T & v01 () const
 
const T & v11 () const
 
const T & v21 () const
 
const T & v02 () const
 
const T & v12 () const
 
const T & v22 () const
 
- Public Member Functions inherited from tools::mat< T, 3 >
 mat ()
 
 mat (const mat &a_from)
 
 mat (const T a_v[])
 
virtual ~mat ()
 
matoperator= (const mat &a_from)
 
unsigned int dimension () const
 

Static Protected Member Functions

static void _set_scale (const T &a_1, const T &a_2, const T &a_3, T v[])
 
static void _set_rotate (const T &a_x, const T &a_y, const T &a_z, const T &a_angle, T v[], T(*a_sin)(T), T(*a_cos)(T))
 

Additional Inherited Members

- Protected Attributes inherited from tools::mat< T, 3 >
m_vec [D *D]
 

Detailed Description

template<class T>
class tools::mat3< T >

Definition at line 14 of file mat3.

Constructor & Destructor Documentation

◆ mat3() [1/4]

template<class T >
tools::mat3< T >::mat3 ( )
inline

Definition at line 21 of file mat3.

21 :parent() {}

◆ mat3() [2/4]

template<class T >
tools::mat3< T >::mat3 ( const mat< T, 3 > &  a_from)
inline

Definition at line 23 of file mat3.

23 :parent(a_from){}

◆ ~mat3()

template<class T >
virtual tools::mat3< T >::~mat3 ( )
inlinevirtual

Definition at line 24 of file mat3.

24 {}

◆ mat3() [3/4]

template<class T >
tools::mat3< T >::mat3 ( const mat3< T > &  a_from)
inline

Definition at line 26 of file mat3.

26 :parent(a_from){}

◆ mat3() [4/4]

template<class T >
tools::mat3< T >::mat3 ( const T &  a_00,
const T &  a_01,
const T &  a_02,
const T &  a_10,
const T &  a_11,
const T &  a_12,
const T &  a_20,
const T &  a_21,
const T &  a_22 
)
inline

Definition at line 32 of file mat3.

35  {
36  set_matrix(a_00,a_01,a_02,
37  a_10,a_11,a_12,
38  a_20,a_21,a_22);
39  }

Member Function Documentation

◆ _set_rotate()

template<class T >
static void tools::mat3< T >::_set_rotate ( const T &  a_x,
const T &  a_y,
const T &  a_z,
const T &  a_angle,
v[],
T(*)(T)  a_sin,
T(*)(T)  a_cos 
)
inlinestaticprotected

Definition at line 167 of file mat3.

167  {
168  //WARNING : it models the rotation of an object (active rotation) = exp(-a_angle*n(a_x,a_y,a_z)*Rs).
169  //WARNING : (a_x,a_y,a_z) must be a normalized vector.
170  T si = a_sin(a_angle);
171  T co = a_cos(a_angle);
172  T x = a_x;
173  T y = a_y;
174  T z = a_z;
175  T x2 = x*x;
176  T y2 = y*y;
177  T z2 = z*z;
178  T xy = x*y;
179  T xz = x*z;
180  T yz = y*z;
181  v[0] = x2+(1-x2)*co;v[3] = xy*(1-co)-z*si;v[6] = xz*(1-co)+y*si;
182  v[1] = xy*(1-co)+z*si;v[4] = y2+(1-y2)*co;v[7] = yz*(1-co)-x*si;
183  v[2] = xz*(1-co)-y*si;v[5] = yz*(1-co)+x*si;v[8] = z2+(1-z2)*co;
184 
185  // If :
186  // n =(x,y,z)
187  // n2 = x2+y2+z2 = 1
188  // n.E = x*E1+y*E2+z*E3
189  // with :
190  // E1 E2 E3
191  // 0 0 0 0 0 -1 0 1 0
192  // 0 0 1 0 0 0 -1 0 0
193  // 0 -1 0 1 0 0 0 0 0
194  //
195  // R(r,c) = cos(theta)*Id(r,c)+(1-cos(theta))*nr*nc-sin(theta)*(n.E)(r,c)
196  //
197  // R = exp(-theta*(n.E))
198 
199  }

◆ _set_scale()

template<class T >
static void tools::mat3< T >::_set_scale ( const T &  a_1,
const T &  a_2,
const T &  a_3,
v[] 
)
inlinestaticprotected

Definition at line 161 of file mat3.

161  {
162  v[0] = a_1;v[3] = 0;v[6] = 0;
163  v[1] = 0;v[4] = a_2;v[7] = 0;
164  v[2] = 0;v[5] = 0;v[8] = a_3;
165  }

◆ get_rotate()

template<class T >
bool tools::mat3< T >::get_rotate ( T &  a_x,
T &  a_y,
T &  a_z,
T &  a_angle,
T(*)(T)  a_acos,
T(*)(T)  a_sin,
T(*)(T)  a_sqrt 
)
inline

Definition at line 58 of file mat3.

58  { //warning : acos and not cos.
59  // used in tests/check_pauli. Same code as matTs/get_rotate.
60  // we assume that we have a rotation matrix.
61  // get (a_angle,a_n(x,y,z)) such that matrix is exp(a_angle*a_n*Rs) (passive(=coord) rotation) and then :
62  // exp(a_angle*n*Rs) = cos_angle*I3+(1-cos_angle)*n*n+sin_theta*n*Rs
63  // trace = 3*cos_angle+(1-cos_angle)*n2
64  T cos_angle = T(0.5)*(pr::m_vec[0]+pr::m_vec[4]+pr::m_vec[8]-T(1));
65  if((cos_angle<T(-1))||(T(1)<cos_angle)) { //matrix is not a rotation :
66  a_angle = T(0);
67  a_x = 0;
68  a_y = 0;
69  a_z = 0;
70  return false;
71  }
72  if(cos_angle==T(1)) {
73  a_angle = T(0);
74  a_x = 0;
75  a_y = 0;
76  a_z = 1;
77  return true; //vector is undefined but we return true anyway.
78  }
79  T one_minus_cos_angle = T(1)-cos_angle;
80  T x2 = (pr::m_vec[0]-cos_angle)/one_minus_cos_angle;
81  //T y2 = (pr::m_vec[4]-cos_angle)/one_minus_cos_angle;
82  //T z2 = (pr::m_vec[8]-cos_angle)/one_minus_cos_angle;
83  /*
84  if((x2<T(0))||(y2<T(0))||(z2<T(0))||(x2+y2+z2)!=T(1)) { //not a rotation :
85  a_angle = T(0);
86  a_x = 0;
87  a_y = 0;
88  a_z = 0;
89  return false;
90  }
91  */
92  a_angle = a_acos(cos_angle); //in ]0,pi].
93  T sin_angle = a_sin(a_angle); //in [0,1].
94  if(sin_angle==T(0)) { //angle is pi. //sym part can determine vector, but up to a sign :
95  // sym part is : cos_angle*I+(1-cos_angle)*n*n
96  // cos_angle = -1
97  T xy = T(0.5)*(pr::m_vec[3]+pr::m_vec[1])/one_minus_cos_angle;
98  T xz = T(0.5)*(pr::m_vec[6]+pr::m_vec[2])/one_minus_cos_angle;
99  //T yz = T(0.5)*(pr::m_vec[7]+pr::m_vec[5])/one_minus_cos_angle;
100  a_x = a_sqrt(x2); //up to a sign.
101  a_y = xy/a_x;
102  a_z = xz/a_x;
103  return true; //vector is defined up to a sign.
104  }
105  // antisym part is : sin(theta)*n.Rs
106  a_z = T(0.5)*(pr::m_vec[3]-pr::m_vec[1])/sin_angle;
107  a_y = T(-0.5)*(pr::m_vec[6]-pr::m_vec[2])/sin_angle; //warning : -1.
108  a_x = T(0.5)*(pr::m_vec[7]-pr::m_vec[5])/sin_angle;
109  return true;
110  }

◆ left_mul_rotate()

template<class T >
void tools::mat3< T >::left_mul_rotate ( const T &  a_x,
const T &  a_y,
const T &  a_z,
const T &  a_angle,
T(*)(T)  a_sin,
T(*)(T)  a_cos 
)
inline

Definition at line 130 of file mat3.

130  {
131  T _m[9];
132  _set_rotate(a_x,a_y,a_z,a_angle,_m,a_sin,a_cos);
133  parent::_left_mul_mtx(_m);
134  }

◆ mul_3()

template<class T >
void tools::mat3< T >::mul_3 ( T &  a_x,
T &  a_y,
T &  a_z 
) const
inline

Definition at line 113 of file mat3.

113  {
114  // a_[x,y,z] = this * a_[x,y,z]
115  //pr::m_vec[R + C * 3];
116  T x = pr::m_vec[0]*a_x+pr::m_vec[3]*a_y+pr::m_vec[6]*a_z;
117  T y = pr::m_vec[1]*a_x+pr::m_vec[4]*a_y+pr::m_vec[7]*a_z;
118  T z = pr::m_vec[2]*a_x+pr::m_vec[5]*a_y+pr::m_vec[8]*a_z;
119  a_x = x;
120  a_y = y;
121  a_z = z;
122  }

◆ mul_rotate()

template<class T >
void tools::mat3< T >::mul_rotate ( const T &  a_x,
const T &  a_y,
const T &  a_z,
const T &  a_angle,
T(*)(T)  a_sin,
T(*)(T)  a_cos 
)
inline

Definition at line 124 of file mat3.

124  {
125  T rot[9];
126  _set_rotate(a_x,a_y,a_z,a_angle,rot,a_sin,a_cos);
127  parent::_mul_mtx(rot);
128  }

◆ operator=()

template<class T >
mat3& tools::mat3< T >::operator= ( const mat3< T > &  a_from)
inline

Definition at line 27 of file mat3.

27  {
28  parent::operator=(a_from);
29  return *this;
30  }

◆ set_matrix() [1/2]

template<class T >
void tools::mat3< T >::set_matrix ( const mat3< T > &  a_m)
inline

Definition at line 41 of file mat3.

41 {parent::set_matrix(a_m);}

◆ set_matrix() [2/2]

template<class T >
void tools::mat3< T >::set_matrix ( const T &  a_00,
const T &  a_01,
const T &  a_02,
const T &  a_10,
const T &  a_11,
const T &  a_12,
const T &  a_20,
const T &  a_21,
const T &  a_22 
)
inline

Definition at line 42 of file mat3.

44  { //3 row
45  //a_<R><C>
46  //pr::m_vec[R + C * 3];
47  pr::m_vec[0] = a_00;pr::m_vec[3] = a_01;pr::m_vec[6] = a_02;
48  pr::m_vec[1] = a_10;pr::m_vec[4] = a_11;pr::m_vec[7] = a_12;
49  pr::m_vec[2] = a_20;pr::m_vec[5] = a_21;pr::m_vec[8] = a_22;
50  }

◆ set_rotate()

template<class T >
void tools::mat3< T >::set_rotate ( const T &  a_x,
const T &  a_y,
const T &  a_z,
const T &  a_angle,
T(*)(T)  a_sin,
T(*)(T)  a_cos 
)
inline

Definition at line 54 of file mat3.

54  {
55  _set_rotate(a_x,a_y,a_z,a_angle,pr::m_vec,a_sin,a_cos);
56  }

◆ set_scale() [1/2]

template<class T >
void tools::mat3< T >::set_scale ( const T &  a_1,
const T &  a_2,
const T &  a_3 
)
inline

Definition at line 53 of file mat3.

53 {_set_scale(a_1,a_2,a_3,pr::m_vec);}

◆ set_scale() [2/2]

template<class T >
void tools::mat3< T >::set_scale ( const T &  a_s)
inline

Definition at line 52 of file mat3.

52 {_set_scale(a_s,a_s,a_s,pr::m_vec);}

◆ v00() [1/2]

template<class T >
const T& tools::mat3< T >::v00 ( ) const
inline

Definition at line 148 of file mat3.

148 {return pr::m_vec[0+0*3];}

◆ v00() [2/2]

template<class T >
void tools::mat3< T >::v00 ( const T &  a_value)
inline

Definition at line 136 of file mat3.

136 {pr::m_vec[0+0*3] = a_value;}

◆ v01() [1/2]

template<class T >
const T& tools::mat3< T >::v01 ( ) const
inline

Definition at line 152 of file mat3.

152 {return pr::m_vec[0+1*3];}

◆ v01() [2/2]

template<class T >
void tools::mat3< T >::v01 ( const T &  a_value)
inline

Definition at line 140 of file mat3.

140 {pr::m_vec[0+1*3] = a_value;}

◆ v02() [1/2]

template<class T >
const T& tools::mat3< T >::v02 ( ) const
inline

Definition at line 156 of file mat3.

156 {return pr::m_vec[0+2*3];}

◆ v02() [2/2]

template<class T >
void tools::mat3< T >::v02 ( const T &  a_value)
inline

Definition at line 144 of file mat3.

144 {pr::m_vec[0+2*3] = a_value;}

◆ v10() [1/2]

template<class T >
const T& tools::mat3< T >::v10 ( ) const
inline

Definition at line 149 of file mat3.

149 {return pr::m_vec[1+0*3];}

◆ v10() [2/2]

template<class T >
void tools::mat3< T >::v10 ( const T &  a_value)
inline

Definition at line 137 of file mat3.

137 {pr::m_vec[1+0*3] = a_value;}

◆ v11() [1/2]

template<class T >
const T& tools::mat3< T >::v11 ( ) const
inline

Definition at line 153 of file mat3.

153 {return pr::m_vec[1+1*3];}

◆ v11() [2/2]

template<class T >
void tools::mat3< T >::v11 ( const T &  a_value)
inline

Definition at line 141 of file mat3.

141 {pr::m_vec[1+1*3] = a_value;}

◆ v12() [1/2]

template<class T >
const T& tools::mat3< T >::v12 ( ) const
inline

Definition at line 157 of file mat3.

157 {return pr::m_vec[1+2*3];}

◆ v12() [2/2]

template<class T >
void tools::mat3< T >::v12 ( const T &  a_value)
inline

Definition at line 145 of file mat3.

145 {pr::m_vec[1+2*3] = a_value;}

◆ v20() [1/2]

template<class T >
const T& tools::mat3< T >::v20 ( ) const
inline

Definition at line 150 of file mat3.

150 {return pr::m_vec[2+0*3];}

◆ v20() [2/2]

template<class T >
void tools::mat3< T >::v20 ( const T &  a_value)
inline

Definition at line 138 of file mat3.

138 {pr::m_vec[2+0*3] = a_value;}

◆ v21() [1/2]

template<class T >
const T& tools::mat3< T >::v21 ( ) const
inline

Definition at line 154 of file mat3.

154 {return pr::m_vec[2+1*3];}

◆ v21() [2/2]

template<class T >
void tools::mat3< T >::v21 ( const T &  a_value)
inline

Definition at line 142 of file mat3.

142 {pr::m_vec[2+1*3] = a_value;}

◆ v22() [1/2]

template<class T >
const T& tools::mat3< T >::v22 ( ) const
inline

Definition at line 158 of file mat3.

158 {return pr::m_vec[2+2*3];}

◆ v22() [2/2]

template<class T >
void tools::mat3< T >::v22 ( const T &  a_value)
inline

Definition at line 146 of file mat3.

146 {pr::m_vec[2+2*3] = a_value;}

The documentation for this class was generated from the following file:
tools::mat< T, 3 >::m_vec
T m_vec[D *D]
Definition: mat:85
tools::mat3::_set_rotate
static void _set_rotate(const T &a_x, const T &a_y, const T &a_z, const T &a_angle, T v[], T(*a_sin)(T), T(*a_cos)(T))
Definition: mat3:167
tools::set_matrix
void set_matrix(MATRIX &a_matrix, const std::string &a_fmt)
Definition: sprintf:100
tools::mat3::_set_scale
static void _set_scale(const T &a_1, const T &a_2, const T &a_3, T v[])
Definition: mat3:161
tools::mat3::set_matrix
void set_matrix(const mat3< T > &a_m)
Definition: mat3:41
tools::mat< T, 3 >::operator=
mat & operator=(const mat &a_from)
Definition: mat:64