2 // class : Les matrices
4 // Copyright (C) 2009-2012 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 "HexVertex.hxx"
27 #include "HexVector.hxx"
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* depl, double degres);
42 int defSymmetryPoint (Vertex* center);
43 int defSymmetryLine (Vertex* center, Vector* dir);
44 int defSymmetryPlane (Vertex* center, Vector* normale);
46 int perform (Vertex* noeud);
48 void getCoeff (double& a11, double& a12, double& a13, double& a14,
49 double& a21, double& a22, double& a23, double& a24,
50 double& a31, double& a32, double& a33, double& a34);
54 double mat11, mat12, mat13, mat14;
55 double mat21, mat22, mat23, mat24;
56 double mat31, mat32, mat33, mat34;
58 // ------------------------------------------- Inlining
59 // ========================================================= Constructeur
60 inline Matrix::Matrix ()
64 // ========================================================= erase
65 inline void Matrix::erase ()
67 mat12 = mat13 = mat14 = 0.0;
68 mat21 = mat23 = mat24 = 0.0;
69 mat31 = mat32 = mat34 = 0.0;
70 mat11 = mat22 = mat33 = 1.0;
72 // ========================================================= perform
73 inline int Matrix::perform (Vertex* noeud)
76 px = mat11*noeud->getX()+mat12*noeud->getY()+mat13*noeud->getZ()+mat14;
77 py = mat21*noeud->getX()+mat22*noeud->getY()+mat23*noeud->getZ()+mat24;
78 pz = mat31*noeud->getX()+mat32*noeud->getY()+mat33*noeud->getZ()+mat34;
80 noeud->setCoord (px, py, pz);
83 // ========================================================= defTranslation
84 inline int Matrix::defTranslation (Vector* boulevard)
87 mat11 = mat22 = mat33 = 1.0;
89 mat14 = boulevard->getDx ();
90 mat24 = boulevard->getDy ();
91 mat34 = boulevard->getDz ();
95 // ========================================================= defTranslation (2)
96 inline int Matrix::defTranslation (double* decal)
99 mat11 = mat22 = mat33 = 1.0;
101 mat14 = decal [dir_x];
102 mat24 = decal [dir_y];
103 mat34 = decal [dir_z];
106 // ========================================================= defScale
107 inline int Matrix::defScale (double* center, double scale)
110 mat11 = mat22 = mat33 = scale;
112 mat14 = (1-scale) * center[dir_x];
113 mat24 = (1-scale) * center[dir_y];
114 mat34 = (1-scale) * center[dir_z];
118 // ========================================================= defScale
119 inline int Matrix::defScale (Vertex* center, double scale)
128 int ier = defScale (center->getPoint (coord ), scale);
131 // ========================================================= defRotation
132 inline int Matrix::defRotation (Vertex* center, Vector* dir, double degres)
136 double normed = dir->getNorm ();
140 double ux = dir->getDx () / normed;
141 double uy = dir->getDy () / normed;
142 double uz = dir->getDz () / normed;
144 double cx = center->getX ();
145 double cy = center->getY ();
146 double cz = center->getZ ();
148 double cost = cos (degres*M_PI/180);
149 double sint = sin (degres*M_PI/180);
151 mat11 = ux*ux * (1-cost) + cost;
152 mat12 = ux*uy * (1-cost) - uz*sint;
153 mat13 = ux*uz * (1-cost) + uy*sint;
155 mat21 = ux*uy * (1-cost) + uz*sint;
156 mat22 = uy*uy * (1-cost) + cost;
157 mat23 = uy*uz * (1-cost) - ux*sint;
159 mat31 = ux*uz * (1-cost) - uy*sint;
160 mat32 = uy*uz * (1-cost) + ux*sint;
161 mat33 = uz*uz * (1-cost) + cost;
163 mat14 = cx - mat11*cx - mat12*cy - mat13*cz;
164 mat24 = cy - mat21*cx - mat22*cy - mat23*cz;
165 mat34 = cz - mat31*cx - mat32*cy - mat33*cz;
169 // ========================================================= defSymmetryPoint
170 inline int Matrix::defSymmetryPoint (Vertex* center)
174 mat11 = mat22 = mat33 = -1;
176 mat14 = 2 * center->getX();
177 mat24 = 2 * center->getY();
178 mat34 = 2 * center->getZ();
182 // ========================================================= defSymmetryLine
187 // (1) et (2) => lambda = ((x-xc)*xd + (y-yc)*yd + (z-zc)*zd) / norme(d)
190 // <=> MO + OM' = 2 (MO + OC + CH)
191 // <=> OM' = MO + 2.OC + 2.CH
192 // <=> OM' = -OM + 2.OC + 2.lambda.d (2) et (3)
194 // x' = -x + 2*xc + 2*xd*((x-xc)*xd + (y-yc)*yd + (z-zc)*zd)
195 // y' = -y + 2*yc + 2*yd*((x-xc)*xd + (y-yc)*yd + (z-zc)*zd)
196 // z' = -z + 2*zc + 2*zd*((x-xc)*xd + (y-yc)*yd + (z-zc)*zd)
198 inline int Matrix::defSymmetryLine (Vertex* center, Vector* dir)
202 double normed = dir->getNorm ();
206 double xc = center->getX();
207 double yc = center->getY();
208 double zc = center->getZ();
210 double xd = dir->getDx() / normed;
211 double yd = dir->getDy() / normed;
212 double zd = dir->getDz() / normed;
217 mat14 = 2*(xc - xd*(xc*xd + yc*yd + zc*zd));
222 mat24 = 2*(yc - yd*(xc*xd + yc*yd + zc*zd));
227 mat34 = 2*(zc - zd*(xc*xd + yc*yd + zc*zd));
231 // ========================================================= defSymmetryPlane
236 // (1) et (2) => lambda = ((x-xc)*xn + (y-yc)*yn + (z-zc)*zn) / norme(n)
239 // <=> MO + OM' = 2.lambda.n
240 // <=> OM' = OM + 2.lambda.n
242 // x' = x + 2*lambda*xn
243 // y' = y + 2*lambda*yn
244 // z' = z + 2*lambda*zn
246 // x' = x + 2*xn*((x-xc)*xn + (y-yc)*yn + (z-zc)*zn)
247 // y' = y + 2*yn*((x-xc)*xn + (y-yc)*yn + (z-zc)*zn)
248 // z' = z + 2*zn*((x-xc)*xn + (y-yc)*yn + (z-zc)*zn)
250 inline int Matrix::defSymmetryPlane (Vertex* center, Vector* normale)
254 double normed = normale->getNorm ();
258 double xc = center->getX();
259 double yc = center->getY();
260 double zc = center->getZ();
262 double xn = normale->getDx() / normed;
263 double yn = normale->getDy() / normed;
264 double zn = normale->getDz() / normed;
266 mat11 = -2*xn*xn + 1;
269 mat14 = 2*xn*(xc*xn + yc*yn + zc*zn);
272 mat22 = -2*yn*yn + 1;
274 mat24 = 2*yn*(xc*xn + yc*yn + zc*zn);
278 mat33 = -2*zn*zn + 1;
279 mat34 = 2*zn*(xc*xn + yc*yn + zc*zn);
283 // ========================================================= getCoeff
284 inline void Matrix::getCoeff(double& a11, double& a12, double& a13, double& a14,
285 double& a21, double& a22, double& a23, double& a24,
286 double& a31, double& a32, double& a33, double& a34)