// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_mat3 #define tools_mat3 #include "mat" //#include namespace tools { template class mat3 : public mat { typedef mat parent; typedef mat pr; public: #ifdef TOOLS_MEM mat3(bool a_inc = true):parent(a_inc) {} #else mat3():parent() {} #endif mat3(const mat& a_from):parent(a_from){} virtual ~mat3() {} public: mat3(const mat3& a_from):parent(a_from){} mat3& operator=(const mat3& a_from){ parent::operator=(a_from); return *this; } public: mat3(const T& a_00,const T& a_01,const T& a_02, //first row const T& a_10,const T& a_11,const T& a_12, //second row const T& a_20,const T& a_21,const T& a_22) //third row { set_matrix(a_00,a_01,a_02, a_10,a_11,a_12, a_20,a_21,a_22); } public: void set_matrix(const mat3& a_m){parent::set_matrix(a_m);} void set_matrix(const T& a_00,const T& a_01,const T& a_02, //1 row const T& a_10,const T& a_11,const T& a_12, //2 row const T& a_20,const T& a_21,const T& a_22) { //3 row //a_ //pr::m_vec[R + C * 3]; pr::m_vec[0] = a_00;pr::m_vec[3] = a_01;pr::m_vec[6] = a_02; pr::m_vec[1] = a_10;pr::m_vec[4] = a_11;pr::m_vec[7] = a_12; pr::m_vec[2] = a_20;pr::m_vec[5] = a_21;pr::m_vec[8] = a_22; } void set_scale(const T& a_s) {_set_scale(a_s,a_s,a_s,pr::m_vec);} void set_scale(const T& a_1,const T& a_2,const T& a_3) {_set_scale(a_1,a_2,a_3,pr::m_vec);} 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)) { _set_rotate(a_x,a_y,a_z,a_angle,pr::m_vec,a_sin,a_cos); } 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)) { //warning : acos and not cos. // used in tests/check_pauli. Same code as matTs/get_rotate. // we assume that we have a rotation matrix. // get (a_angle,a_n(x,y,z)) such that matrix is exp(a_angle*a_n*Rs) (passive(=coord) rotation) and then : // exp(a_angle*n*Rs) = cos_angle*I3+(1-cos_angle)*n*n+sin_theta*n*Rs // trace = 3*cos_angle+(1-cos_angle)*n2 T cos_angle = T(0.5)*(pr::m_vec[0]+pr::m_vec[4]+pr::m_vec[8]-T(1)); if((cos_angle dummy;} }; //////////////////////////////////////////////// /// common matrices : ////////////////////////// //////////////////////////////////////////////// template inline const mat3& mat3_zero() { static const mat3 s_v(false); //inc mem count = false return s_v; } //for sf, mf : //template //inline const T* get_data(const mat3& a_v) {return a_v.data();} } #include namespace tools { template inline std::ostream& operator<<(std::ostream& a_out,const mat3& a_mtx){ const T* v = a_mtx.data(); a_out << v[0] << "," << v[3] << "," << v[6] << std::endl << v[1] << "," << v[4] << "," << v[7] << std::endl << v[2] << "," << v[5] << "," << v[8] << std::endl; return a_out; } } #endif