ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/step/src/sttoroidal.cpp
Revision: 27
Committed: Thu Jul 5 15:26:40 2007 UTC (17 years, 10 months ago) by foucault
Original Path: magic/lib/step/step/src/sttoroidal.cpp
File size: 9531 byte(s)
Log Message:

File Contents

# User Rev Content
1 foucault 27 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4     // Jean Christophe Cuillière et Vincent FRANCOIS
5     // Département de Génie Mécanique - UQTR
6     //------------------------------------------------------------
7     // Le projet MAGIC est un projet de recherche du département
8     // de génie mécanique de l'Université du Québec à
9     // Trois Rivières
10     // Les librairies ne peuvent être utilisées sans l'accord
11     // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // sttoroidal.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 à 11H24
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25     #include "gestionversion.h"
26    
27     #include "sttoroidal.h"
28     #include "st_gestionnaire.h"
29     #include "constantegeo.h"
30     #include <math.h>
31    
32    
33    
34    
35    
36     ST_TOROIDAL::ST_TOROIDAL(long LigneCourante,std::string idori,long axis2,double grand,double petit):ST_SURFACE(LigneCourante,idori),id_axis2_placement_3d(axis2),grandray(grand),petitray(petit)
37     {
38     }
39    
40     ST_TOROIDAL::ST_TOROIDAL(double *xyz, double *dirz,double grand,double petit):ST_SURFACE(),grandray(grand),petitray(petit)
41     {
42     initialiser(xyz,dirz);
43     }
44    
45    
46     long ST_TOROIDAL::get_id_axis2_placement_3d(void)
47     {
48     return id_axis2_placement_3d;
49     }
50     double ST_TOROIDAL::get_grandray(void)
51     {
52     return grandray;
53     }
54     double ST_TOROIDAL::get_petitray(void)
55     {
56     return petitray;
57     }
58    
59     void ST_TOROIDAL::evaluer(double *uv,double *xyz)
60     {
61     OT_VECTEUR_3D local((grandray+petitray*cos(uv[1]))*cos(uv[0]),(grandray+petitray*cos(uv[1]))*sin(uv[0]),petitray*sin(uv[1]));
62     OT_VECTEUR_3D global=origine+repere*local;
63     xyz[0]=global.get_x();
64     xyz[1]=global.get_y();
65     xyz[2]=global.get_z();
66     }
67     void ST_TOROIDAL::deriver(double *uv,double *xyzdu, double *xyzdv)
68     {
69     OT_VECTEUR_3D localu(-(grandray+petitray*cos(uv[1]))*sin(uv[0]),(grandray+petitray*cos(uv[1]))*cos(uv[0]),0.);
70     OT_VECTEUR_3D localv(-petitray*sin(uv[1])*cos(uv[0]),-petitray*sin(uv[1])*sin(uv[0]),petitray*cos(uv[1]));
71     OT_VECTEUR_3D globalu=repere*localu;
72     OT_VECTEUR_3D globalv=repere*localv;
73     xyzdu[0]=globalu.get_x();
74     xyzdu[1]=globalu.get_y();
75     xyzdu[2]=globalu.get_z();
76     xyzdv[0]=globalv.get_x();
77     xyzdv[1]=globalv.get_y();
78     xyzdv[2]=globalv.get_z();
79     }
80     void ST_TOROIDAL::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz , double *xyzdu , double *xyzdv )
81     {
82     OT_VECTEUR_3D localuu(-(grandray+petitray*cos(uv[1]))*cos(uv[0]),-(grandray+petitray*cos(uv[1]))*sin(uv[0]),0.);
83     OT_VECTEUR_3D localuv(petitray*sin(uv[1])*sin(uv[0]),-petitray*sin(uv[1])*cos(uv[0]),0.);
84     OT_VECTEUR_3D localvv(-petitray*cos(uv[1])*cos(uv[0]),-petitray*cos(uv[1])*sin(uv[0]),-petitray*sin(uv[1]));
85     OT_VECTEUR_3D globaluu=repere*localuu;
86     OT_VECTEUR_3D globaluv=repere*localuv;
87     OT_VECTEUR_3D globalvv=repere*localvv;
88     xyzduu[0]=globaluu.get_x();
89     xyzduu[1]=globaluu.get_y();
90     xyzduu[2]=globaluu.get_z();
91     xyzduv[0]=globaluv.get_x();
92     xyzduv[1]=globaluv.get_y();
93     xyzduv[2]=globaluv.get_z();
94     xyzdvv[0]=globalvv.get_x();
95     xyzdvv[1]=globalvv.get_y();
96     xyzdvv[2]=globalvv.get_z();
97     if ((xyzdu!=NULL) && (xyzdv!=NULL ) ) deriver(uv,xyzdu,xyzdv);
98     if (xyz!=NULL) evaluer(uv,xyz);
99     }
100     void ST_TOROIDAL::inverser(double *uv,double *xyz,double precision)
101     {
102     double sign;
103     double valeur1;
104     double valeur3;
105     double variable;
106     OT_VECTEUR_3D global(xyz[0],xyz[1],xyz[2]);
107     OT_MATRICE_3D transpose_repere;
108     repere.transpose(transpose_repere);
109     OT_VECTEUR_3D vecteur=transpose_repere*(global-origine);
110     valeur1=vecteur.get_z()/petitray;
111     if (valeur1>1) valeur1=1;
112     if (valeur1<-1) valeur1=-1;
113     uv[1]=asin(valeur1);
114     double cosv=cos(uv[1]);
115     double cosv1=(-grandray+sqrt(vecteur.get_x()*vecteur.get_x()+vecteur.get_y()*vecteur.get_y()))/petitray;
116     if ( cosv*cosv1 < -0.000001 ) uv[1]= M_PI-uv[1];
117     valeur3=vecteur.get_x()/(grandray+petitray*cos(uv[1]));
118     if (valeur3>1) valeur3=1;
119     if (valeur3<-1) valeur3=-1;
120     uv[0]=acos(valeur3);
121     sign=vecteur.get_y()/(grandray+petitray*cos(uv[1]));
122     if (sign<-0.000001) uv[0]= 2.*M_PI-uv[0];
123     }
124     int ST_TOROIDAL::est_periodique_u(void)
125     {
126     return 1;
127     }
128     int ST_TOROIDAL::est_periodique_v(void)
129     {
130     return 1;
131     }
132     double ST_TOROIDAL::get_periode_u(void)
133     {
134     return 2.*M_PI;
135     }
136     double ST_TOROIDAL::get_periode_v(void)
137     {
138     return 2.*M_PI;
139     }
140     double ST_TOROIDAL::get_umin(void)
141     {
142     return 0.;
143     }
144     double ST_TOROIDAL::get_umax(void)
145     {
146     return 2.*M_PI;
147     }
148     double ST_TOROIDAL::get_vmin(void)
149     {
150     return 0.;
151     }
152     double ST_TOROIDAL::get_vmax(void)
153     {
154     return 2.*M_PI;
155     }
156     void ST_TOROIDAL::initialiser(ST_GESTIONNAIRE *gest)
157     {
158     ST_AXIS2_PLACEMENT_3D* axe=gest->lst_axis2_placement_3d.getid(id_axis2_placement_3d);
159     ST_DIRECTION* dirz=gest->lst_direction.getid(axe->get_id_direction1());
160     ST_POINT* point=gest->lst_point.getid(axe->get_id_point());
161     double xyz[3];
162     point->evaluer(xyz);
163     double *dirnorm=dirz->get_direction();
164     initialiser(xyz,dirnorm);
165     }
166    
167    
168     void ST_TOROIDAL::initialiser(double *xyz,double *dirz)
169     {
170     origine.change_x(xyz[0]);
171     origine.change_y(xyz[1]);
172     origine.change_z(xyz[2]);
173     OT_VECTEUR_3D vec_z(dirz[0],dirz[1],dirz[2]);
174     vec_z.norme();
175     if (!(OPERATEUR::egal(vec_z.get_x(),0.,0.000001)))
176     {
177     x[0]=vec_z.get_y();
178     x[1]=(-vec_z.get_x());
179     x[2]=0.;
180     }
181     else if (!(OPERATEUR::egal(vec_z.get_y(),0.,0.000001)))
182     {
183     x[0]=0.;
184     x[1]=(-vec_z.get_z());
185     x[2]=vec_z.get_y();
186     }
187     else
188     {
189     x[0]=vec_z.get_z();
190     x[1]=0.;
191     x[2]=0.;
192     }
193     OT_VECTEUR_3D vec_x(x);
194     vec_x.norme();
195     OT_VECTEUR_3D vec_y=vec_z&vec_x;
196     repere.change_vecteur1(vec_x);
197     repere.change_vecteur2(vec_y);
198     repere.change_vecteur3(vec_z);
199     }
200    
201    
202    
203    
204     int ST_TOROIDAL::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
205     {
206     param.ajouter(origine.get_x());
207     param.ajouter(origine.get_y());
208     param.ajouter(origine.get_z());
209     param.ajouter(repere.get_vecteur1().get_x());
210     param.ajouter(repere.get_vecteur1().get_y());
211     param.ajouter(repere.get_vecteur1().get_z());
212     param.ajouter(repere.get_vecteur3().get_x());
213     param.ajouter(repere.get_vecteur3().get_y());
214     param.ajouter(repere.get_vecteur3().get_z());
215     param.ajouter(grandray);
216     param.ajouter(petitray);
217     return MGCo_TORE;
218     }
219    
220    
221     void ST_TOROIDAL::est_util(ST_GESTIONNAIRE* gest)
222     {
223     util=true;
224     gest->lst_axis2_placement_3d.getid(id_axis2_placement_3d)->est_util(gest);
225     }
226    
227    
228    
229    
230    
231     void ST_TOROIDAL:: get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
232     {
233    
234     // The first parameter indicate the code access
235     param.ajouter(2);
236    
237     // The follewing two parameters of the list indicate the orders of the net points
238    
239     param.ajouter(4);
240     param.ajouter(4);
241    
242     // The follewing two parameters indicate the number of rows and colons of the control points
243     // respectively to the two parameters directions
244    
245     param.ajouter(7);
246     param.ajouter(7);
247    
248     // this present the knot vector in the u-direction
249    
250     param.ajouter(0);
251     param.ajouter(0);
252     param.ajouter(0);
253     param.ajouter(0.25);
254     param.ajouter(0.5);
255     param.ajouter(0.5);
256     param.ajouter(0.75);
257     param.ajouter(1);
258     param.ajouter(1);
259     param.ajouter(1);
260    
261     // this present the knot vector in the u-direction
262    
263     param.ajouter(0);
264     param.ajouter(0);
265     param.ajouter(0);
266     param.ajouter(0.25);
267     param.ajouter(0.5);
268     param.ajouter(0.5);
269     param.ajouter(0.75);
270     param.ajouter(1);
271     param.ajouter(1);
272     param.ajouter(1);
273    
274    
275     // the construction of the polygon control of toroid surface is obtained by rotating the
276     // the controle polygon of one circle along the other circle.
277    
278    
279     double xyz[3];
280     double w;
281     double rx,ry,rz;
282     double rp=grandray-petitray;
283     double rg=grandray+petitray;
284    
285     for(int v=0;v<7;v++)
286     {
287    
288     switch (v){
289     case 0: {rx=0;ry=rp;rz=0;w=1; break;}
290     case 1: {rx=-rp;ry=rp;rz=0;w=0.5; break;}
291     case 2: {rx=-rp;ry=-rp;rz=0;w=0.5; break;}
292     case 3: {rx=-rp;ry=0;rz=0;w=1; break;}
293     case 4: {rx=rp;ry=-rp;rz=0;w=0.5; break;}
294     case 5: {rx=0;ry=rp;rz=0;w=0.5; break;}
295     case 6: {rx=0;ry=rp;rz=0;w=1; break;}
296     }
297    
298    
299     //P0j
300    
301     OT_VECTEUR_3D loc(rx,ry,rz);
302     OT_VECTEUR_3D glob=origine+repere*loc;
303    
304     glob=origine+repere*loc;
305    
306     xyz[0]=glob.get_x();
307     xyz[1]=glob.get_y();
308     xyz[2]=glob.get_z();
309    
310     param.ajouter(xyz[0]);
311     param.ajouter(xyz[1]);
312     param.ajouter(xyz[2]);
313     param.ajouter(1*w);
314    
315     //P1j
316    
317     loc.change_z(-petitray);
318    
319     glob=origine+repere*loc;
320    
321     xyz[0]=glob.get_x();
322     xyz[1]=glob.get_y();
323     xyz[2]=glob.get_z();
324    
325     param.ajouter(xyz[0]);
326     param.ajouter(xyz[1]);
327     param.ajouter(xyz[2]);
328     param.ajouter(0.5*w);
329    
330    
331     //P2j
332    
333     loc.change_y(rg);
334    
335     if(v==1||v==2||v==4||v==5) loc.change_x(rg);
336    
337     glob=origine+repere*loc;
338    
339     xyz[0]=glob.get_x();
340     xyz[1]=glob.get_y();
341     xyz[2]=glob.get_z();
342    
343     param.ajouter(xyz[0]);
344     param.ajouter(xyz[1]);
345     param.ajouter(xyz[2]);
346     param.ajouter(0.5*w);
347    
348     //P3j
349    
350     loc.change_z(0);
351    
352     glob=origine+repere*loc;
353    
354     xyz[0]=glob.get_x();
355     xyz[1]=glob.get_y();
356     xyz[2]=glob.get_z();
357    
358     param.ajouter(xyz[0]);
359     param.ajouter(xyz[1]);
360     param.ajouter(xyz[2]);
361     param.ajouter(1*w);
362    
363     //P4j
364    
365     loc.change_z(petitray);
366    
367     glob=origine+repere*loc;
368    
369     xyz[0]=glob.get_x();
370     xyz[1]=glob.get_y();
371     xyz[2]=glob.get_z();
372    
373     param.ajouter(xyz[0]);
374     param.ajouter(xyz[1]);
375     param.ajouter(xyz[2]);
376     param.ajouter(0.5*w);
377    
378     //P5j
379    
380     loc.change_y(rp);
381     if(v==1||v==2||v==4||v==5) loc.change_x(rp);
382    
383     glob=origine+repere*loc;
384    
385     xyz[0]=glob.get_x();
386     xyz[1]=glob.get_y();
387     xyz[2]=glob.get_z();
388    
389     param.ajouter(xyz[0]);
390     param.ajouter(xyz[1]);
391     param.ajouter(xyz[2]);
392     param.ajouter(0.5*w);
393     //P5j
394    
395     loc.change_z(0);
396    
397     glob=origine+repere*loc;
398    
399     xyz[0]=glob.get_x();
400     xyz[1]=glob.get_y();
401     xyz[2]=glob.get_z();
402    
403     param.ajouter(xyz[0]);
404     param.ajouter(xyz[1]);
405     param.ajouter(xyz[2]);
406     param.ajouter(1*w);
407    
408     }
409    
410     indx_premier_ptctr=25;
411     }
412