2 // class : Les matrices
4 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 #include "Hex_defines.hxx"
27 #include "HexVertex.hxx"
28 #include "HexVector.hxx"
34 class HEXABLOCKENGINE_EXPORT Matrix
38 int defTranslation (Vector* depl);
39 int defTranslation (double* depl);
40 int defScale (Vertex* center, double scale);
41 int defScale (double* center, double scale);
42 int defRotation (Vertex* center, Vector* axe, double degres);
43 int defRotation (Vertex* center, double* axe, double degres);
44 int defSymmetryPoint (Vertex* center);
45 int defSymmetryLine (Vertex* center, Vector* dir);
46 int defSymmetryPlane (Vertex* center, Vector* normale);
48 void define (double* orig, double* iprim, double* jprim, double* kprim);
50 void perform (Vertex* noeud);
51 void perform (double* point);
52 void perform (double* point, double* result);
54 void getCoeff (double& a11, double& a12, double& a13, double& a14,
55 double& a21, double& a22, double& a23, double& a24,
56 double& a31, double& a32, double& a33, double& a34);
60 double mat11, mat12, mat13, mat14;
61 double mat21, mat22, mat23, mat24;
62 double mat31, mat32, mat33, mat34;
64 // ------------------------------------------- Inlining
65 // ========================================================= Constructeur
66 inline Matrix::Matrix ()
70 // ========================================================= erase
71 inline void Matrix::erase ()
73 mat12 = mat13 = mat14 = 0.0;
74 mat21 = mat23 = mat24 = 0.0;
75 mat31 = mat32 = mat34 = 0.0;
76 mat11 = mat22 = mat33 = 1.0;
78 // ========================================================= perform
79 inline void Matrix::perform (Vertex* noeud)
82 px = mat11*noeud->getX()+mat12*noeud->getY()+mat13*noeud->getZ()+mat14;
83 py = mat21*noeud->getX()+mat22*noeud->getY()+mat23*noeud->getZ()+mat24;
84 pz = mat31*noeud->getX()+mat32*noeud->getY()+mat33*noeud->getZ()+mat34;
86 noeud->setCoord (px, py, pz);
88 // ========================================================= defTranslation
89 inline int Matrix::defTranslation (Vector* boulevard)
92 mat11 = mat22 = mat33 = 1.0;
94 mat14 = boulevard->getDx ();
95 mat24 = boulevard->getDy ();
96 mat34 = boulevard->getDz ();
100 // ========================================================= defTranslation (2)
101 inline int Matrix::defTranslation (double* decal)
104 mat11 = mat22 = mat33 = 1.0;
106 mat14 = decal [dir_x];
107 mat24 = decal [dir_y];
108 mat34 = decal [dir_z];
111 // ========================================================= defScale
112 inline int Matrix::defScale (double* center, double scale)
115 mat11 = mat22 = mat33 = scale;
117 mat14 = (1-scale) * center[dir_x];
118 mat24 = (1-scale) * center[dir_y];
119 mat34 = (1-scale) * center[dir_z];
123 // ========================================================= defScale
124 inline int Matrix::defScale (Vertex* center, double scale)
133 int ier = defScale (center->getPoint (coord ), scale);
136 // ========================================================= defRotation
137 inline int Matrix::defRotation (Vertex* center, double* axe, double degres)
140 if (BadElement (center))
143 double norme = calc_norme (axe);
147 double ux = axe [dir_x] / norme;
148 double uy = axe [dir_y] / norme;
149 double uz = axe [dir_z] / norme;
151 double cx = center->getX ();
152 double cy = center->getY ();
153 double cz = center->getZ ();
155 double cost = cos (degres*M_PI/180);
156 double sint = sin (degres*M_PI/180);
158 mat11 = ux*ux * (1-cost) + cost;
159 mat12 = ux*uy * (1-cost) - uz*sint;
160 mat13 = ux*uz * (1-cost) + uy*sint;
162 mat21 = ux*uy * (1-cost) + uz*sint;
163 mat22 = uy*uy * (1-cost) + cost;
164 mat23 = uy*uz * (1-cost) - ux*sint;
166 mat31 = ux*uz * (1-cost) - uy*sint;
167 mat32 = uy*uz * (1-cost) + ux*sint;
168 mat33 = uz*uz * (1-cost) + cost;
170 mat14 = cx - mat11*cx - mat12*cy - mat13*cz;
171 mat24 = cy - mat21*cx - mat22*cy - mat23*cz;
172 mat34 = cz - mat31*cx - mat32*cy - mat33*cz;
176 // ========================================================= defRotation
177 inline int Matrix::defRotation (Vertex* center, Vector* dir, double degres)
179 if (BadElement (dir))
184 int ier = defRotation (center, axe, degres);
187 // ========================================================= defSymmetryPoint
188 inline int Matrix::defSymmetryPoint (Vertex* center)
192 mat11 = mat22 = mat33 = -1;
194 mat14 = 2 * center->getX();
195 mat24 = 2 * center->getY();
196 mat34 = 2 * center->getZ();
200 // ========================================================= defSymmetryLine
205 // (1) et (2) => lambda = ((x-xc)*xd + (y-yc)*yd + (z-zc)*zd) / norme(d)
208 // <=> MO + OM' = 2 (MO + OC + CH)
209 // <=> OM' = MO + 2.OC + 2.CH
210 // <=> OM' = -OM + 2.OC + 2.lambda.d (2) et (3)
212 // x' = -x + 2*xc + 2*xd*((x-xc)*xd + (y-yc)*yd + (z-zc)*zd)
213 // y' = -y + 2*yc + 2*yd*((x-xc)*xd + (y-yc)*yd + (z-zc)*zd)
214 // z' = -z + 2*zc + 2*zd*((x-xc)*xd + (y-yc)*yd + (z-zc)*zd)
216 inline int Matrix::defSymmetryLine (Vertex* center, Vector* dir)
220 double normed = dir->getNorm ();
224 double xc = center->getX();
225 double yc = center->getY();
226 double zc = center->getZ();
228 double xd = dir->getDx() / normed;
229 double yd = dir->getDy() / normed;
230 double zd = dir->getDz() / normed;
235 mat14 = 2*(xc - xd*(xc*xd + yc*yd + zc*zd));
240 mat24 = 2*(yc - yd*(xc*xd + yc*yd + zc*zd));
245 mat34 = 2*(zc - zd*(xc*xd + yc*yd + zc*zd));
249 // ========================================================= defSymmetryPlane
254 // (1) et (2) => lambda = ((x-xc)*xn + (y-yc)*yn + (z-zc)*zn) / norme(n)
257 // <=> MO + OM' = 2.lambda.n
258 // <=> OM' = OM + 2.lambda.n
260 // x' = x + 2*lambda*xn
261 // y' = y + 2*lambda*yn
262 // z' = z + 2*lambda*zn
264 // x' = x + 2*xn*((x-xc)*xn + (y-yc)*yn + (z-zc)*zn)
265 // y' = y + 2*yn*((x-xc)*xn + (y-yc)*yn + (z-zc)*zn)
266 // z' = z + 2*zn*((x-xc)*xn + (y-yc)*yn + (z-zc)*zn)
268 inline int Matrix::defSymmetryPlane (Vertex* center, Vector* normale)
272 double normed = normale->getNorm ();
276 double xc = center->getX();
277 double yc = center->getY();
278 double zc = center->getZ();
280 double xn = normale->getDx() / normed;
281 double yn = normale->getDy() / normed;
282 double zn = normale->getDz() / normed;
284 mat11 = -2*xn*xn + 1;
287 mat14 = 2*xn*(xc*xn + yc*yn + zc*zn);
290 mat22 = -2*yn*yn + 1;
292 mat24 = 2*yn*(xc*xn + yc*yn + zc*zn);
296 mat33 = -2*zn*zn + 1;
297 mat34 = 2*zn*(xc*xn + yc*yn + zc*zn);
301 // ========================================================= define
302 inline void Matrix::define (double* omega, double* iprim, double* jprim,
305 mat11 = iprim [dir_x];
306 mat21 = iprim [dir_y];
307 mat31 = iprim [dir_z];
309 mat12 = jprim [dir_x];
310 mat22 = jprim [dir_y];
311 mat32 = jprim [dir_z];
313 mat13 = kprim [dir_x];
314 mat23 = kprim [dir_y];
315 mat33 = kprim [dir_z];
317 mat14 = omega [dir_x];
318 mat24 = omega [dir_y];
319 mat34 = omega [dir_z];
321 // ========================================================= getCoeff
322 inline void Matrix::getCoeff(double& a11, double& a12, double& a13, double& a14,
323 double& a21, double& a22, double& a23, double& a24,
324 double& a31, double& a32, double& a33, double& a34)
341 // ========================================================= perform
342 inline void Matrix::perform (double* point)
344 double px = point [dir_x];
345 double py = point [dir_y];
346 double pz = point [dir_z];
348 point [dir_x] = mat11*px + mat12*py + mat13*pz + mat14;
349 point [dir_y] = mat21*px + mat22*py + mat23*pz + mat24;
350 point [dir_z] = mat31*px + mat32*py + mat33*pz + mat34;
352 // ========================================================= perform
353 inline void Matrix::perform (double* point, double* result)
355 double px = point [dir_x];
356 double py = point [dir_y];
357 double pz = point [dir_z];
359 result [dir_x] = mat11*px + mat12*py + mat13*pz + mat14;
360 result [dir_y] = mat21*px + mat22*py + mat23*pz + mat24;
361 result [dir_z] = mat31*px + mat32*py + mat33*pz + mat34;