1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef __TRANSLATIONROTATIONMATRIX_HXX__
20 #define __TRANSLATIONROTATIONMATRIX_HXX__
24 namespace INTERP_KERNEL
26 class TranslationRotationMatrix
31 TranslationRotationMatrix()
34 for(i=0;i<TRANSL_SIZE;i++)
35 _translation_coeffs[i]=0.;
36 for(i=0;i<ROT_SIZE;i++)
37 _rotation_coeffs[i]=i%4?0.:1.;
40 void multiply(const TranslationRotationMatrix& A)
42 TranslationRotationMatrix result;
43 //setting output matrix to zero
44 for (int i=0; i<3; i++)
45 result._rotation_coeffs[i*4]=0.0;
47 for (int i=0; i<3;i++)
48 for (int j=0; j<3; j++)
49 for (int k=0; k<3; k++)
50 result._rotation_coeffs[j+i*3]+=A._rotation_coeffs[3*i+k]*_rotation_coeffs[j+k*3];
52 for (int i=0;i<9; i++)
53 _rotation_coeffs[i]=result._rotation_coeffs[i];
56 void rotate_vector(double* P)
58 double temp[3]={0.0, 0.0, 0.0};
60 for (int i=0; i<3;i++)
61 for (int j=0; j<3; j++)
62 temp[i] +=_rotation_coeffs[3*i+j]*P[j];
64 P[0]=temp[0];P[1]=temp[1];P[2]=temp[2];
67 void transform_vector(double*P)
69 P[0]+=_translation_coeffs[0];
70 P[1]+=_translation_coeffs[1];
71 P[2]+=_translation_coeffs[2];
75 void translate(const double* P)
77 _translation_coeffs[0]=P[0];
78 _translation_coeffs[1]=P[1];
79 _translation_coeffs[2]=P[2];
82 void rotate_x (double* P)
84 _rotation_coeffs[0]=1.0;
85 double r_sqr = P[1]*P[1]+P[2]*P[2];
87 {_rotation_coeffs[4]=1.0; _rotation_coeffs[8]=1.0; return;}
88 double r = sqrt(r_sqr);
92 _rotation_coeffs[4]=cos;
93 _rotation_coeffs[5]=sin;
94 _rotation_coeffs[7]=-sin;
95 _rotation_coeffs[8]=cos;
101 void rotate_z (double* P)
103 _rotation_coeffs[8]=1.0;
104 double r_sqr = P[0]*P[0]+P[1]*P[1];
106 {_rotation_coeffs[4]=1.0; _rotation_coeffs[0]=1.0; return;}
107 double r = sqrt(r_sqr);
111 _rotation_coeffs[0]=cos;
112 _rotation_coeffs[1]=sin;
113 _rotation_coeffs[3]=-sin;
114 _rotation_coeffs[4]=cos;
121 static const double EPS;
122 static const unsigned ROT_SIZE=9;
123 static const unsigned TRANSL_SIZE=3;
124 double _rotation_coeffs[ROT_SIZE];
125 double _translation_coeffs[TRANSL_SIZE];
127 const double TranslationRotationMatrix::EPS=1e-12;