2 // class : Les matrices
4 // Copyright (C) 2009-2014 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, or (at your option) any later version.
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 "HexVertex.hxx"
27 #include "HexVector.hxx"
33 class HexaExport Matrix
37 int defTranslation (Vector* depl);
38 int defTranslation (double* depl);
39 int defScale (Vertex* center, double scale);
40 int defScale (double* center, double scale);
41 int defRotation (Vertex* center, Vector* axe, double degres);
42 int defRotation (Vertex* center, double* axe, double degres);
43 int defSymmetryPoint (Vertex* center);
44 int defSymmetryLine (Vertex* center, Vector* dir);
45 int defSymmetryPlane (Vertex* center, Vector* normale);
47 void define (double* orig, double* iprim, double* jprim, double* kprim);
49 void perform (Vertex* noeud);
50 void perform (double* point);
51 void perform (double* point, double* result);
53 void getCoeff (double& a11, double& a12, double& a13, double& a14,
54 double& a21, double& a22, double& a23, double& a24,
55 double& a31, double& a32, double& a33, double& a34);
59 double mat11, mat12, mat13, mat14;
60 double mat21, mat22, mat23, mat24;
61 double mat31, mat32, mat33, mat34;
63 // ------------------------------------------- Inlining
64 // ========================================================= Constructeur
65 inline Matrix::Matrix ()
69 // ========================================================= erase
70 inline void Matrix::erase ()
72 mat12 = mat13 = mat14 = 0.0;
73 mat21 = mat23 = mat24 = 0.0;
74 mat31 = mat32 = mat34 = 0.0;
75 mat11 = mat22 = mat33 = 1.0;
77 // ========================================================= perform
78 inline void Matrix::perform (Vertex* noeud)
81 px = mat11*noeud->getX()+mat12*noeud->getY()+mat13*noeud->getZ()+mat14;
82 py = mat21*noeud->getX()+mat22*noeud->getY()+mat23*noeud->getZ()+mat24;
83 pz = mat31*noeud->getX()+mat32*noeud->getY()+mat33*noeud->getZ()+mat34;
85 noeud->setCoord (px, py, pz);
87 // ========================================================= defTranslation
88 inline int Matrix::defTranslation (Vector* boulevard)
91 mat11 = mat22 = mat33 = 1.0;
93 mat14 = boulevard->getDx ();
94 mat24 = boulevard->getDy ();
95 mat34 = boulevard->getDz ();
99 // ========================================================= defTranslation (2)
100 inline int Matrix::defTranslation (double* decal)
103 mat11 = mat22 = mat33 = 1.0;
105 mat14 = decal [dir_x];
106 mat24 = decal [dir_y];
107 mat34 = decal [dir_z];
110 // ========================================================= defScale
111 inline int Matrix::defScale (double* center, double scale)
114 mat11 = mat22 = mat33 = scale;
116 mat14 = (1-scale) * center[dir_x];
117 mat24 = (1-scale) * center[dir_y];
118 mat34 = (1-scale) * center[dir_z];
122 // ========================================================= defScale
123 inline int Matrix::defScale (Vertex* center, double scale)
132 int ier = defScale (center->getPoint (coord ), scale);
135 // ========================================================= defRotation
136 inline int Matrix::defRotation (Vertex* center, double* axe, double degres)
139 if (BadElement (center))
142 double norme = calc_norme (axe);
146 double ux = axe [dir_x] / norme;
147 double uy = axe [dir_y] / norme;
148 double uz = axe [dir_z] / norme;
150 double cx = center->getX ();
151 double cy = center->getY ();
152 double cz = center->getZ ();
154 double cost = cos (degres*M_PI/180);
155 double sint = sin (degres*M_PI/180);
157 mat11 = ux*ux * (1-cost) + cost;
158 mat12 = ux*uy * (1-cost) - uz*sint;
159 mat13 = ux*uz * (1-cost) + uy*sint;
161 mat21 = ux*uy * (1-cost) + uz*sint;
162 mat22 = uy*uy * (1-cost) + cost;
163 mat23 = uy*uz * (1-cost) - ux*sint;
165 mat31 = ux*uz * (1-cost) - uy*sint;
166 mat32 = uy*uz * (1-cost) + ux*sint;
167 mat33 = uz*uz * (1-cost) + cost;
169 mat14 = cx - mat11*cx - mat12*cy - mat13*cz;
170 mat24 = cy - mat21*cx - mat22*cy - mat23*cz;
171 mat34 = cz - mat31*cx - mat32*cy - mat33*cz;
175 // ========================================================= defRotation
176 inline int Matrix::defRotation (Vertex* center, Vector* dir, double degres)
178 if (BadElement (dir))
183 int ier = defRotation (center, axe, degres);
186 // ========================================================= defSymmetryPoint
187 inline int Matrix::defSymmetryPoint (Vertex* center)
191 mat11 = mat22 = mat33 = -1;
193 mat14 = 2 * center->getX();
194 mat24 = 2 * center->getY();
195 mat34 = 2 * center->getZ();
199 // ========================================================= defSymmetryLine
204 // (1) et (2) => lambda = ((x-xc)*xd + (y-yc)*yd + (z-zc)*zd) / norme(d)
207 // <=> MO + OM' = 2 (MO + OC + CH)
208 // <=> OM' = MO + 2.OC + 2.CH
209 // <=> OM' = -OM + 2.OC + 2.lambda.d (2) et (3)
211 // x' = -x + 2*xc + 2*xd*((x-xc)*xd + (y-yc)*yd + (z-zc)*zd)
212 // y' = -y + 2*yc + 2*yd*((x-xc)*xd + (y-yc)*yd + (z-zc)*zd)
213 // z' = -z + 2*zc + 2*zd*((x-xc)*xd + (y-yc)*yd + (z-zc)*zd)
215 inline int Matrix::defSymmetryLine (Vertex* center, Vector* dir)
219 double normed = dir->getNorm ();
223 double xc = center->getX();
224 double yc = center->getY();
225 double zc = center->getZ();
227 double xd = dir->getDx() / normed;
228 double yd = dir->getDy() / normed;
229 double zd = dir->getDz() / normed;
234 mat14 = 2*(xc - xd*(xc*xd + yc*yd + zc*zd));
239 mat24 = 2*(yc - yd*(xc*xd + yc*yd + zc*zd));
244 mat34 = 2*(zc - zd*(xc*xd + yc*yd + zc*zd));
248 // ========================================================= defSymmetryPlane
253 // (1) et (2) => lambda = ((x-xc)*xn + (y-yc)*yn + (z-zc)*zn) / norme(n)
256 // <=> MO + OM' = 2.lambda.n
257 // <=> OM' = OM + 2.lambda.n
259 // x' = x + 2*lambda*xn
260 // y' = y + 2*lambda*yn
261 // z' = z + 2*lambda*zn
263 // x' = x + 2*xn*((x-xc)*xn + (y-yc)*yn + (z-zc)*zn)
264 // y' = y + 2*yn*((x-xc)*xn + (y-yc)*yn + (z-zc)*zn)
265 // z' = z + 2*zn*((x-xc)*xn + (y-yc)*yn + (z-zc)*zn)
267 inline int Matrix::defSymmetryPlane (Vertex* center, Vector* normale)
271 double normed = normale->getNorm ();
275 double xc = center->getX();
276 double yc = center->getY();
277 double zc = center->getZ();
279 double xn = normale->getDx() / normed;
280 double yn = normale->getDy() / normed;
281 double zn = normale->getDz() / normed;
283 mat11 = -2*xn*xn + 1;
286 mat14 = 2*xn*(xc*xn + yc*yn + zc*zn);
289 mat22 = -2*yn*yn + 1;
291 mat24 = 2*yn*(xc*xn + yc*yn + zc*zn);
295 mat33 = -2*zn*zn + 1;
296 mat34 = 2*zn*(xc*xn + yc*yn + zc*zn);
300 // ========================================================= define
301 inline void Matrix::define (double* omega, double* iprim, double* jprim,
304 mat11 = iprim [dir_x];
305 mat21 = iprim [dir_y];
306 mat31 = iprim [dir_z];
308 mat12 = jprim [dir_x];
309 mat22 = jprim [dir_y];
310 mat32 = jprim [dir_z];
312 mat13 = kprim [dir_x];
313 mat23 = kprim [dir_y];
314 mat33 = kprim [dir_z];
316 mat14 = omega [dir_x];
317 mat24 = omega [dir_y];
318 mat34 = omega [dir_z];
320 // ========================================================= getCoeff
321 inline void Matrix::getCoeff(double& a11, double& a12, double& a13, double& a14,
322 double& a21, double& a22, double& a23, double& a24,
323 double& a31, double& a32, double& a33, double& a34)
340 // ========================================================= perform
341 inline void Matrix::perform (double* point)
343 double px = point [dir_x];
344 double py = point [dir_y];
345 double pz = point [dir_z];
347 point [dir_x] = mat11*px + mat12*py + mat13*pz + mat14;
348 point [dir_y] = mat21*px + mat22*py + mat23*pz + mat24;
349 point [dir_z] = mat31*px + mat32*py + mat33*pz + mat34;
351 // ========================================================= perform
352 inline void Matrix::perform (double* point, double* result)
354 double px = point [dir_x];
355 double py = point [dir_y];
356 double pz = point [dir_z];
358 result [dir_x] = mat11*px + mat12*py + mat13*pz + mat14;
359 result [dir_y] = mat21*px + mat22*py + mat23*pz + mat24;
360 result [dir_z] = mat31*px + mat32*py + mat33*pz + mat34;