ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/vct_courbe.cpp
Revision: 85
Committed: Fri May 2 14:24:42 2008 UTC (17 years ago) by souaissa
Original Path: magic/lib/geometrie/geometrie/src/vct_courbe.cpp
File size: 11078 byte(s)
Log Message:

File Contents

# User Rev Content
1 souaissa 66 #include "gestionversion.h"
2    
3     //---------------------------------------------------------------------------
4    
5    
6     #pragma hdrstop
7 souaissa 85 #include<math.h>
8 souaissa 66 #include "vct_courbe.h"
9     #include "mg_courbe.h"
10     #include "mg_arete.h"
11     #include <iomanip.h>
12     //---------------------------------------------------------------------------
13    
14     #pragma package(smart_init)
15    
16    
17    
18     VCT_COURBE::VCT_COURBE(MG_COURBE* elemgeo):VCT_ELEMENT_GEOMETRIQUE(elemgeo)
19     {
20 souaissa 69 int indx_premier_ptctr;
21     OT_VECTEUR_4DD V1,V2,V;
22     TPL_LISTE_ENTITE<double> nurbs_params;
23 souaissa 66 elem_geo->get_param_NURBS(indx_premier_ptctr,nurbs_params);
24     nb_points=1/4.*(nurbs_params.get_nb()-indx_premier_ptctr);
25 souaissa 69 double2 ZERO=0.;
26     OT_VECTEUR_4DD VCT_NUL(0.,0.,0.,0.);
27    
28    
29     int nb_u=nurbs_params.get(3);
30    
31    
32     for(int s=0;s<nb_u-1;s++)
33     {
34     V1[0]=nurbs_params.get(indx_premier_ptctr+ 4 * s);
35     V1[1]=nurbs_params.get(indx_premier_ptctr+ 4 * s + 1);
36     V1[2]=nurbs_params.get(indx_premier_ptctr+ 4 * s + 2);
37     V1[3]=nurbs_params.get(indx_premier_ptctr+ 4 * s + 3);
38 souaissa 79 if (s==0)
39 souaissa 69 lst_points.insert(lst_points.end(),V1);
40    
41     V2[0]=nurbs_params.get(indx_premier_ptctr+ 4 * (s + 1));
42     V2[1]=nurbs_params.get(indx_premier_ptctr+ 4 * (s + 1) + 1);
43     V2[2]=nurbs_params.get(indx_premier_ptctr+ 4 * (s + 1) + 2);
44     V2[3]=nurbs_params.get(indx_premier_ptctr+ 4 * (s + 1) + 3);
45    
46     lst_points.insert(lst_points.end(),V2);
47    
48     V=V2-V1;
49    
50     double2 norm_au_carre=(V[0]*V[0])+(V[1]*V[1])+(V[2]*V[2])+(V[3]*V[3]);
51     double2 norm=norm_au_carre^0.5;
52    
53     if(V==VCT_NUL)
54     lst_vecteurs.insert(lst_vecteurs.end(),VCT_NUL);
55    
56     if(norm!=ZERO){
57     V=1./norm*V;
58     lst_vecteurs.insert(lst_vecteurs.end(),V);
59     }
60    
61    
62     }
63 souaissa 66 }
64    
65    
66     VCT_COURBE::VCT_COURBE(VCT_COURBE& mdd):VCT_ELEMENT_GEOMETRIQUE(mdd.elem_geo)
67     {
68 souaissa 69 lst_vecteurs=mdd.lst_vecteurs;
69     lst_points=mdd.lst_points;
70     nb_points=mdd.nb_points ;
71 souaissa 66 }
72    
73    
74     VCT_COURBE::~VCT_COURBE()
75     {
76     }
77    
78 souaissa 69
79 francois 72 std::vector<OT_VECTEUR_4DD>& VCT_COURBE::get_points_controle(void)
80 souaissa 66 {
81 souaissa 71 return lst_points;
82     }
83    
84     std::vector<OT_VECTEUR_4DD> & VCT_COURBE::get_vecteurs()
85     {
86 souaissa 69 return lst_vecteurs;
87     }
88 souaissa 66
89    
90 souaissa 69 OT_TENSEUR VCT_COURBE:: calcule_tenseur_metrique()
91     {
92     OT_TENSEUR tns(lst_vecteurs);
93     return tns;
94     }
95 souaissa 66
96 souaissa 69 OT_VECTEUR_4DD VCT_COURBE::calcule_barycentre()
97     {
98 souaissa 66
99 souaissa 69 OT_VECTEUR_4DD barycentre(0,0,0,0);
100 souaissa 66
101 souaissa 69 for(int i=0;i<nb_points;i++)
102     {
103 souaissa 71 barycentre+=lst_points[i];
104 souaissa 69 }
105 souaissa 66
106 souaissa 69 barycentre*=1./nb_points;
107     return barycentre;
108     }
109 souaissa 66
110    
111    
112 souaissa 69 int VCT_COURBE::get_nb_points()
113     {
114     return nb_points ;
115     }
116 souaissa 67
117 souaissa 66
118 souaissa 69 OT_TENSEUR VCT_COURBE::calcule_covariance(void)
119     {
120 souaissa 71 OT_TENSEUR COVARIANCE(4);
121 souaissa 85
122 souaissa 69 OT_VECTEUR_4DD barycentre=calcule_barycentre();
123    
124    
125 souaissa 71 OT_TENSEUR PT_CENTRE(nb_points,4),PT_CENTRE_TRANSPOSE;
126 souaissa 69
127 souaissa 71 for( int i=0;i<nb_points;i++)
128     {
129 souaissa 85 OT_VECTEUR_4DD pt=lst_points[i];
130     OT_VECTEUR_4DD ptcent=lst_points[i]-barycentre;
131     PT_CENTRE(i,0)= ptcent[0];
132     PT_CENTRE(i,1)= ptcent[1];
133     PT_CENTRE(i,2)= ptcent[2];
134     PT_CENTRE(i,3)= ptcent[3];
135 souaissa 71 }
136     PT_CENTRE_TRANSPOSE =PT_CENTRE.transpose();
137    
138     COVARIANCE=PT_CENTRE_TRANSPOSE*PT_CENTRE;
139     double2 COEF= 1./nb_points;
140     COVARIANCE=COVARIANCE*COEF;
141    
142 souaissa 85 for(int i=0;i<4;i++)
143     for(int j=0;j<4;j++)
144     {
145     if(fabs(COVARIANCE(i,j).get_x())<=1e-8)
146     COVARIANCE(i,j).set_x(0.);
147    
148     }
149 souaissa 69 return COVARIANCE;
150 souaissa 66 }
151    
152 souaissa 69
153 souaissa 71 void VCT_COURBE::calcule_axes_dinertie(OT_VECTEUR_4DD& D,OT_TENSEUR& V)
154 souaissa 66 {
155 souaissa 69 int n=4;
156     int nrot;
157    
158 souaissa 71 OT_TENSEUR COV=calcule_covariance();
159    
160    
161 souaissa 69 double2 zro=0.0;
162    
163 souaissa 71 if(COV(0,0)==zro&&COV(1,0)==zro&&COV(2,0)==zro&&COV(3,0)==zro)
164 souaissa 69 {
165 souaissa 71 COV(0,0)=1.0;
166     COV(1,0)=zro;
167     COV(2,0)=zro;
168     COV(3,0)=zro;
169 souaissa 69 }
170 souaissa 71 if(COV(0,1)==zro&&COV(1,1)==zro&&COV(2,1)==zro&&COV(3,1)==zro)
171 souaissa 69 {
172 souaissa 71 COV(0,1)=zro;
173     COV(1,1)=1.0;
174     COV(2,1)=zro;
175     COV(3,1)=zro;
176 souaissa 69 }
177 souaissa 71 if(COV(0,2)==zro&&COV(1,2)==zro&&COV(2,2)==zro&&COV(3,2)==zro)
178 souaissa 69 {
179 souaissa 71 COV(0,2)=zro;
180     COV(1,2)=zro;
181     COV(2,2)=1.0;
182     COV(3,2)=zro;
183 souaissa 69 }
184 souaissa 71 if(COV(0,3)==zro&&COV(1,3)==zro&&COV(2,3)==zro&&COV(3,3)==zro)
185 souaissa 69 {
186 souaissa 71 COV(0,3)=zro;
187     COV(1,3)=zro;
188     COV(2,3)=zro;
189     COV(3,3)=1.0;
190 souaissa 69 }
191    
192    
193 souaissa 71 COV.get_orthogonalisation(COV,D,V,n,nrot);
194 souaissa 69
195 souaissa 66 }
196    
197 souaissa 69
198     OT_TENSEUR VCT_COURBE:: calcule_tenseur_inertie_au_barycentre() //repere globale
199 souaissa 66 {
200 souaissa 71 OT_TENSEUR INERTIE(4);
201 souaissa 69 OT_TENSEUR cov=calcule_covariance();
202     double2 nb_pts=nb_points;
203     double2 MOINS_UN=-1.0;
204 souaissa 71 INERTIE=cov*MOINS_UN;
205     INERTIE=INERTIE*nb_pts;
206 souaissa 66
207 souaissa 71 INERTIE(0,0)=(cov(1,1)+cov(2,2)+cov(3,3))*nb_pts;
208     INERTIE(1,1)=(cov(0,0)+cov(2,2)+cov(3,3))*nb_pts;
209     INERTIE(2,2)=(cov(1,1)+cov(0,0)+cov(3,3))*nb_pts;
210     INERTIE(3,3)=(cov(1,1)+cov(2,2)+cov(0,0))*nb_pts;
211 souaissa 85 for(int i=0;i<4;i++)
212     for(int j=0;j<4;j++)
213     {
214     if(fabs(INERTIE(i,j).get_x())<=1e-12) INERTIE(i,j).set_x(0.);
215 souaissa 71
216 souaissa 85 }
217 souaissa 71 return INERTIE;
218 souaissa 69 }
219 souaissa 66
220    
221 souaissa 69 OT_TENSEUR VCT_COURBE:: calcule_tenseur_inertie_au_pt(OT_VECTEUR_4DD& POINT)
222     {
223 souaissa 66
224 souaissa 71 OT_VECTEUR_4DD BARYCENTRE=calcule_barycentre();
225     OT_TENSEUR TENS=calcule_tenseur_inertie_au_barycentre();
226 souaissa 69
227     OT_VECTEUR_4DD ABC=POINT-BARYCENTRE;
228    
229     double2 a=ABC[0] ;
230     double2 b=ABC[1] ;
231     double2 c=ABC[2] ;
232     double2 d=ABC[3] ;
233    
234     TENS(0,0)=TENS(0,0)+b*b+c*c+d*d;
235     TENS(1,1)=TENS(1,1)+a*a+c*c+d*d;
236     TENS(2,2)=TENS(2,2)+a*a+b*b+d*d;
237 souaissa 71 TENS(3,3)=TENS(3,3)+a*a+b*b+c*c;
238 souaissa 69
239     TENS(0,1)=TENS(0,1)-nb_points*a*b;
240     TENS(0,2)=TENS(0,2)-nb_points*a*c;
241     TENS(0,3)=TENS(0,3)-nb_points*a*d;
242    
243     TENS(1,0)=TENS(1,0)-nb_points*b*a;
244     TENS(1,2)=TENS(1,2)-nb_points*b*c;
245     TENS(1,3)=TENS(1,3)-nb_points*b*d;
246    
247     TENS(2,0)=TENS(2,0)-nb_points*c*a;
248     TENS(2,1)=TENS(2,1)-nb_points*c*b;
249     TENS(2,3)=TENS(2,3)-nb_points*c*d;
250    
251     TENS(3,0)=TENS(3,0)-nb_points*d*a;
252     TENS(3,1)=TENS(3,1)-nb_points*d*b;
253     TENS(3,2)=TENS(3,2)-nb_points*d*c;
254    
255     return TENS;
256 souaissa 66 }
257    
258    
259 souaissa 69 OT_TENSEUR VCT_COURBE::calcule_tenseur_inertie_base_locale()
260     {
261 souaissa 71
262 souaissa 69 OT_VECTEUR_4DD v1,v2,v3,v4;
263     OT_TENSEUR INERTIE;
264     OT_TENSEUR I_GLOBALE;
265 souaissa 71 OT_VECTEUR_4DD D;
266     OT_TENSEUR V(4);
267     this->calcule_axes_dinertie(D,V);
268 souaissa 69 INERTIE=this->calcule_tenseur_inertie_au_barycentre();
269 souaissa 66
270 souaissa 69 I_GLOBALE= INERTIE;
271    
272     OT_TENSEUR P(4);
273     OT_TENSEUR I=I_GLOBALE;
274     OT_TENSEUR P_TRSPOSE;
275     OT_TENSEUR I_LOCALE;
276 souaissa 71 P=V;
277 souaissa 69 P_TRSPOSE=P.transpose();
278    
279     I_LOCALE=P_TRSPOSE*I;
280     I_LOCALE=I_LOCALE*P;
281 souaissa 85 for(int i=0;i<4;i++)
282     for(int j=0;j<4;j++)
283     {
284     if(fabs(I_LOCALE(i,j).get_x())<=1e-12) I_LOCALE(i,j).set_x(0.);
285     }
286 souaissa 71 return I_LOCALE;
287    
288 souaissa 69 }
289    
290    
291    
292    
293 souaissa 79 OT_TENSEUR VCT_COURBE::calcule_tenseur_inertie_base_entite(VCT& vct_f)
294 souaissa 66 {
295 souaissa 71 OT_VECTEUR_4DD Dv,Dw,G1,G2,G1G2;
296 souaissa 69 OT_TENSEUR P(4);
297     OT_TENSEUR pt;
298     OT_TENSEUR IV;
299 souaissa 71 OT_TENSEUR Q(4);
300 souaissa 69 OT_TENSEUR qt;
301     OT_TENSEUR R;
302     OT_TENSEUR Rt;
303     OT_TENSEUR IW;
304 souaissa 71 OT_TENSEUR MASSE_CONCENTRE(4);
305     OT_TENSEUR V(4),W(4);
306     this->calcule_axes_dinertie(Dv,V);
307     vct_f.calcule_axes_dinertie(Dw,W);
308 souaissa 66
309 souaissa 71 P=V;
310     Q=W;
311 souaissa 66
312 souaissa 71 IW=vct_f.calcule_tenseur_inertie_base_locale();
313 souaissa 69
314     pt=P.transpose();
315     qt=Q.transpose();
316     R=pt*Q;
317     Rt=qt*P;
318     IV=R*IW;
319     IV=IV*Rt;
320    
321    
322     G1=this->calcule_barycentre();
323     G2=vct_f.calcule_barycentre();
324    
325     G1G2=G2-G1;
326    
327     OT_VECTEUR_4DD G1G2_LOC; //Calcul du vecteur G1G2 dans la base locale;
328     for(int i=0;i<4;i++)
329 souaissa 66 {
330 souaissa 69 for(int j=0;j<4;j++)
331     {
332     G1G2_LOC[i]= G1G2_LOC[i]+pt(i,j)*G1G2[j];
333     }
334 souaissa 66 }
335 souaissa 69
336     MASSE_CONCENTRE(0,0)=nb_points*(G1G2_LOC[1]*G1G2_LOC[1]+G1G2_LOC[2]*G1G2_LOC[2]+G1G2_LOC[3]*G1G2_LOC[3]);
337     MASSE_CONCENTRE(0,1)=-1*nb_points*(G1G2_LOC[0]*G1G2_LOC[1]);
338     MASSE_CONCENTRE(0,2)=-1*nb_points*(G1G2_LOC[0]*G1G2_LOC[2]);
339     MASSE_CONCENTRE(0,3)=-1*nb_points*(G1G2_LOC[0]*G1G2_LOC[3]);
340    
341     MASSE_CONCENTRE(1,0)=-1*nb_points*(G1G2_LOC[1]*G1G2_LOC[0]);
342     MASSE_CONCENTRE(1,1)= nb_points*(G1G2_LOC[0]*G1G2_LOC[0]+G1G2_LOC[2]*G1G2_LOC[2]+G1G2_LOC[3]*G1G2_LOC[3]);
343     MASSE_CONCENTRE(1,2)=-1*nb_points*(G1G2_LOC[1]*G1G2_LOC[2]);
344     MASSE_CONCENTRE(1,3)=-1*nb_points*(G1G2_LOC[1]*G1G2_LOC[3]);
345    
346     MASSE_CONCENTRE(2,0)=-1*nb_points*(G1G2_LOC[2]*G1G2_LOC[0]);
347     MASSE_CONCENTRE(2,1)=-1*nb_points*(G1G2_LOC[2]*G1G2_LOC[1]);
348     MASSE_CONCENTRE(2,2)=nb_points*(G1G2_LOC[0]*G1G2_LOC[0]+G1G2_LOC[1]*G1G2_LOC[1]+G1G2_LOC[3]*G1G2_LOC[3]);
349 souaissa 79 MASSE_CONCENTRE(2,3)=-1*nb_points*(G1G2_LOC[3]*G1G2_LOC[2]);
350 souaissa 69
351     MASSE_CONCENTRE(3,0)=-1*nb_points*(G1G2_LOC[0]*G1G2_LOC[3]);
352     MASSE_CONCENTRE(3,1)=-1*nb_points*(G1G2_LOC[1]*G1G2_LOC[3]);
353     MASSE_CONCENTRE(3,2)=-1*nb_points*(G1G2_LOC[2]*G1G2_LOC[3]);
354     MASSE_CONCENTRE(3,3)=nb_points*(G1G2_LOC[0]*G1G2_LOC[0]+G1G2_LOC[1]*G1G2_LOC[1]+G1G2_LOC[2]*G1G2_LOC[2]);
355    
356     IV=IV+MASSE_CONCENTRE;
357 souaissa 85
358    
359 souaissa 79 return IV;
360 souaissa 85
361 souaissa 66 }
362    
363    
364 souaissa 71 ostream& operator <<(ostream& os, VCT_COURBE& vct_f)
365     {
366 souaissa 66
367 souaissa 71 vct_f.enregistrer(os) ;
368     return os;
369     }
370    
371     //==========================================================================
372     //Visualisation
373     //==========================================================================
374    
375    
376    
377    
378     void VCT_COURBE::enregistrer(std::ostream& ost)
379 souaissa 66 {
380    
381 souaissa 71 ost<<"========================================"<<endl;
382     ost<<"% FACE: "<<endl;
383     ost<<"========================================"<<endl;
384     ost<<"POINTS_DE_CONTROLS: "<<endl;
385     ost<<"========================================"<<endl;
386    
387     for (unsigned int i=0;i< lst_points.size();i++)
388     {
389     OT_VECTEUR_4DD v= lst_points[i]; // Rmq: la precision nèest pas affocher, il faut rajouter l'affichage
390     ost<< v<<endl; // de la precision dans la classe doubleprecision
391     }
392    
393     ost<<endl;
394     ost<<"VECTORISATION: "<<endl;
395     ost<<"========================================"<<endl;
396     for (unsigned int i=0;i< lst_vecteurs.size();i++)
397     {
398     OT_VECTEUR_4DD v= lst_vecteurs[i];
399     ost<< v<<endl;
400     }
401    
402     ost<<endl<<endl;
403     ost<<"BARYCENTRE: "<<endl;
404     ost<<"========================================"<<endl;
405     OT_VECTEUR_4DD BARY= calcule_barycentre();
406     ost<<BARY<<endl;
407     ost<<endl<<endl;
408     ost<<"TENSEUR_METRIQUE: "<<endl;
409     ost<<"========================================"<<endl;
410     OT_TENSEUR TNS_MT= calcule_tenseur_metrique() ;
411     ost<< TNS_MT<<endl;
412     ost<<endl<<endl;
413     ost<<"TENSEUR_DE_COVARIANCE: "<<endl;
414     ost<<"========================================"<<endl;
415     OT_TENSEUR TNS_CV= calcule_covariance();
416     ost<< TNS_CV<<endl;
417     ost<<endl<<endl;
418     ost<<"AXES_D'INERTIE: "<<endl;
419     ost<<"========================================"<<endl;
420     OT_VECTEUR_4DD D;
421     OT_TENSEUR V(4);
422     calcule_axes_dinertie(D,V);
423     ost<< V<<endl;
424     ost<<endl<<endl;
425     ost<<"INERTIE_CALCULÉE_AU_BARYCENTRE: "<<endl;
426     ost<<"========================================"<<endl;
427     OT_TENSEUR I_BARY=calcule_tenseur_inertie_au_barycentre();
428     ost<<I_BARY<<endl;
429    
430     ost<<endl<<endl;
431     ost<<"INERTIE_TRANSPORTÉE_EN_UN_POINT: "<<endl;
432     ost<<"========================================"<<endl;
433     OT_TENSEUR I_TRANSP=calcule_tenseur_inertie_au_pt(BARY);
434     ost<<I_TRANSP<<endl;
435     ost<<endl<<endl;
436    
437     ost<<"INERTIE_CALCULÉ_DANS_LA_BASE_LOCALE: "<<endl;
438     ost<<"========================================"<<endl;
439     OT_TENSEUR I_BASE=calcule_tenseur_inertie_base_locale();
440     ost<<I_BASE<<endl;
441     ost<<endl<<endl;
442    
443    
444     // void calcule_tenseur_inertie_base_entite(OT_VECTEUR_4DD& G1G2, OT_TENSEUR& tens,VCT& vct_f) ;
445    
446    
447    
448    
449     }