ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/step/src/stspherical.cpp
Revision: 5
Committed: Tue Jun 12 20:26:34 2007 UTC (17 years, 11 months ago)
Original Path: magic/lib/step/step/src/stspherical.cpp
File size: 11065 byte(s)
Log Message:

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
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     // stspherical.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 "stspherical.h"
28     #include "st_gestionnaire.h"
29     #include "constantegeo.h"
30    
31     #include <math.h>
32    
33    
34    
35    
36     ST_SPHERICAL::ST_SPHERICAL(long LigneCourante,std::string idori,long axis2,double ray):ST_SURFACE(LigneCourante,idori),id_axis2_placement_3d(axis2),rayon(ray)
37     {
38     }
39    
40     ST_SPHERICAL::ST_SPHERICAL(double *xyz,double *dirz,double *dirx,double ray):ST_SURFACE(),rayon(ray)
41     {
42     initialiser(xyz,dirz,dirx);
43     }
44    
45    
46     long ST_SPHERICAL::get_id_axis2_placement_3d(void)
47     {
48     return id_axis2_placement_3d;
49     }
50    
51     double ST_SPHERICAL::get_rayon(void)
52     {
53     return rayon;
54     }
55     void ST_SPHERICAL::evaluer(double *uv,double *xyz)
56     {
57     OT_VECTEUR_3D local(rayon*cos(uv[1])*cos(uv[0]),rayon*cos(uv[1])*sin(uv[0]),rayon*sin(uv[1]));
58     OT_VECTEUR_3D global=origine+repere*local;
59     xyz[0]=global.get_x();
60     xyz[1]=global.get_y();
61     xyz[2]=global.get_z();
62     }
63     void ST_SPHERICAL::deriver(double *uv,double *xyzdu, double *xyzdv)
64     {
65     OT_VECTEUR_3D localu(-rayon*sin(uv[0])*cos(uv[1]),rayon*cos(uv[0])*cos(uv[1]),0.);
66     OT_VECTEUR_3D localv(-rayon*sin(uv[1])*cos(uv[0]),-rayon*sin(uv[1])*sin(uv[0]),rayon*cos(uv[1]));
67     OT_VECTEUR_3D globalu=repere*localu;
68     OT_VECTEUR_3D globalv=repere*localv;
69     xyzdu[0]=globalu.get_x();
70     xyzdu[1]=globalu.get_y();
71     xyzdu[2]=globalu.get_z();
72     xyzdv[0]=globalv.get_x();
73     xyzdv[1]=globalv.get_y();
74     xyzdv[2]=globalv.get_z();
75     }
76     void ST_SPHERICAL::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz , double *xyzdu , double *xyzdv )
77     {
78     OT_VECTEUR_3D localuu(-rayon*cos(uv[1])*cos(uv[0]),-rayon*cos(uv[1])*sin(uv[0]),0.);
79     OT_VECTEUR_3D localuv(rayon*sin(uv[0])*sin(uv[1]),-rayon*cos(uv[0])*sin(uv[1]),0.);
80     OT_VECTEUR_3D localvv(-rayon*cos(uv[1])*cos(uv[0]),-rayon*cos(uv[1])*sin(uv[0]),-rayon*sin(uv[1]));
81     OT_VECTEUR_3D globaluu=repere*localuu;
82     OT_VECTEUR_3D globaluv=repere*localuv;
83     OT_VECTEUR_3D globalvv=repere*localvv;
84     xyzduu[0]=globaluu.get_x();
85     xyzduu[1]=globaluu.get_y();
86     xyzduu[2]=globaluu.get_z();
87     xyzduv[0]=globaluv.get_x();
88     xyzduv[1]=globaluv.get_y();
89     xyzduv[2]=globaluv.get_z();
90     xyzdvv[0]=globalvv.get_x();
91     xyzdvv[1]=globalvv.get_y();
92     xyzdvv[2]=globalvv.get_z();
93     if ((xyzdu!=NULL) && (xyzdv!=NULL ) ) deriver(uv,xyzdu,xyzdv);
94     if (xyz!=NULL) evaluer(uv,xyz);
95     }
96     void ST_SPHERICAL::inverser(double *uv,double *xyz,double precision)
97     {
98     double sign;
99     OT_VECTEUR_3D global(xyz[0],xyz[1],xyz[2]);
100     OT_MATRICE_3D transpose_repere;
101     repere.transpose(transpose_repere);
102     OT_VECTEUR_3D vecteur=transpose_repere*(global-origine);
103     double valeur1;
104     valeur1=vecteur.get_z()/rayon;
105     if (valeur1>1) valeur1=1;
106     if (valeur1<-1) valeur1=-1;
107     uv[1]=asin(valeur1);
108     double valeur2;
109     valeur2=vecteur.get_x()/(rayon*cos(uv[1]));
110     if (valeur2>1) valeur2=1;
111     if (valeur2<-1) valeur2=-1;
112     uv[0]=acos(valeur2);
113     sign=vecteur.get_y()/(rayon*cos(uv[1]));
114     if (sign<-0.000001) uv[0]= 2.*M_PI-uv[0];
115     }
116     int ST_SPHERICAL::est_periodique_u(void)
117     {
118     return 1;
119     }
120     int ST_SPHERICAL::est_periodique_v(void)
121     {
122     return 0;
123     }
124     double ST_SPHERICAL::get_periode_u(void)
125     {
126     return 2.*M_PI;
127     }
128     double ST_SPHERICAL::get_periode_v(void)
129     {
130     return 0;
131     }
132     double ST_SPHERICAL::get_umin(void)
133     {
134     return 0.;
135     }
136     double ST_SPHERICAL::get_umax(void)
137     {
138     return 2.*M_PI;
139     }
140     double ST_SPHERICAL::get_vmin(void)
141     {
142     return -M_PI/2.;
143     }
144     double ST_SPHERICAL::get_vmax(void)
145     {
146     return M_PI/2.;
147     }
148    
149     void ST_SPHERICAL::initialiser(ST_GESTIONNAIRE *gest)
150     {
151     ST_AXIS2_PLACEMENT_3D* axe=gest->lst_axis2_placement_3d.getid(id_axis2_placement_3d);
152     ST_DIRECTION* dirz=gest->lst_direction.getid(axe->get_id_direction1());
153     ST_DIRECTION* dirx=gest->lst_direction.getid(axe->get_id_direction2());
154     ST_POINT* point=gest->lst_point.getid(axe->get_id_point());
155     double xyz[3];
156     point->evaluer(xyz);
157     double *directz=dirz->get_direction();
158     double *directx=dirx->get_direction();
159     initialiser(xyz,directz,directx);
160     }
161    
162    
163     void ST_SPHERICAL::initialiser(double *xyz,double *dirz, double *dirx)
164     {
165     origine.change_x(xyz[0]);
166     origine.change_y(xyz[1]);
167     origine.change_z(xyz[2]);
168     double axez[3]={0.,0.,1.};
169     double axex[3]={1.,0.,0.};
170     if (dirz==NULL)
171     {
172     dirz=axez;
173     dirx=axex;
174     }
175     OT_VECTEUR_3D z(dirz[0],dirz[1],dirz[2]);
176     z.norme();
177     OT_VECTEUR_3D x(dirx[0],dirx[1],dirx[2]);
178     x.norme();
179     OT_VECTEUR_3D y=z&x;
180     repere.change_vecteur1(x);
181     repere.change_vecteur2(y);
182     repere.change_vecteur3(z);
183     }
184    
185    
186     int ST_SPHERICAL::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
187     {
188     param.ajouter(origine.get_x());
189     param.ajouter(origine.get_y());
190     param.ajouter(origine.get_z());
191     param.ajouter(rayon);
192     return MGCo_SPHERE;
193     }
194    
195    
196     void ST_SPHERICAL::est_util(ST_GESTIONNAIRE* gest)
197     {
198     util=true;
199     gest->lst_axis2_placement_3d.getid(id_axis2_placement_3d)->est_util(gest);
200     }
201    
202    
203    
204     void ST_SPHERICAL:: get_param_NURBS(TPL_LISTE_ENTITE<double> &param)
205     {
206    
207     // The first parameter indicate the code access
208     param.ajouter(2);
209    
210     // The follewing two parameters of the list indicate the orders of the net points
211    
212     param.ajouter(4);
213     param.ajouter(4);
214    
215     // The follewing two parameters indicate the number of rows and colons of the control points
216     // respectively to the two parameters directions
217    
218     param.ajouter(4);
219     param.ajouter(7);
220    
221     // this present the knot vector in the u-direction
222    
223     param.ajouter(0);
224     param.ajouter(0);
225     param.ajouter(0);
226     param.ajouter(0.25);
227     param.ajouter(0.5);
228     param.ajouter(0.5);
229     param.ajouter(0.75);
230     param.ajouter(1);
231     param.ajouter(1);
232     param.ajouter(1);
233    
234     // the following is the V_knots of the semicircle in the direction V
235    
236    
237     param.ajouter(0);
238     param.ajouter(0);
239     param.ajouter(0);
240     param.ajouter(0.5);
241     param.ajouter(1);
242     param.ajouter(1);
243     param.ajouter(1);
244    
245     // the weight of the controle point are given in this vecteur wi={1,0.5,0.5,1}
246     // Notice that the controle point at the north and south poles of the sphere
247     // are repeated sventh times P0,0=....=P6,0 and P0,3=....=P0,3
248    
249     double xyz[3];
250     double w;
251     double rx=0.;
252     double ry=0.;
253     double rz=rayon;
254     //==========================================
255     //POLE 1
256     //==========================================
257     OT_VECTEUR_3D loc(0,0,rz);
258     OT_VECTEUR_3D glob=origine+repere*loc;
259    
260     double pole1_x=glob.get_x();
261     double pole1_y=glob.get_y();
262     double pole1_z=glob.get_z();
263     //==========================================
264     //POLE 2
265     //==========================================
266     loc.change_z(-rz);
267     glob=origine+repere*loc;
268    
269     double pole2_x=glob.get_x();
270     double pole2_y=glob.get_y();
271     double pole2_z=glob.get_z();
272     //==========================================
273    
274     for(int v=0;v<7;v++)
275     {
276    
277     switch (v){
278     case 0: {rx=rayon;ry=0;w=1; break;}
279     case 1: {rx=rayon;ry=rayon;w=0.5; break;}
280     case 2: {rx=-rayon;ry=rayon;w=0.5; break;}
281     case 3: {rx=-rayon;ry=0;w=1; break;}
282     case 4: {rx=-rayon;ry=-rayon;w=0.5; break;}
283     case 5: {rx=rayon;ry=-rayon;w=0.5; break;}
284     case 6: {rx=rayon;ry=0;w=1; break;}
285     }
286     //P0j
287     param.ajouter(pole1_x);
288     param.ajouter(pole1_y);
289     param.ajouter(pole1_z);
290     param.ajouter(1*w);
291    
292     //P1j
293    
294     loc.change_x(rx);
295     loc.change_y(ry);
296    
297     glob=origine+repere*loc;
298    
299     xyz[0]=glob.get_x();
300     xyz[1]=glob.get_y();
301     xyz[2]=glob.get_z();
302    
303     param.ajouter(xyz[0]);
304     param.ajouter(xyz[1]);
305     param.ajouter(xyz[2]);
306     param.ajouter(0.5*w);
307    
308     //P2j
309    
310     loc.change_z(-rz);
311    
312     glob=origine+repere*loc;
313    
314     xyz[0]=glob.get_x();
315     xyz[1]=glob.get_y();
316     xyz[2]=glob.get_z();
317    
318     param.ajouter(xyz[0]);
319     param.ajouter(xyz[1]);
320     param.ajouter(xyz[2]);
321     param.ajouter(0.5*w);
322    
323    
324     //P3j
325    
326     param.ajouter(pole2_x);
327     param.ajouter(pole2_y);
328     param.ajouter(pole2_z);
329     param.ajouter(1*w);
330    
331    
332     }
333    
334    
335    
336    
337    
338    
339    
340     /*
341     for(int j=0;j<2;j++)
342     {
343    
344     double rz;
345    
346     if (j==0) rz=rayon;
347     if (j==1) rz=-rayon;
348     //=======================================================
349     // point de controle au premier pole : P00
350     //=======================================================
351     OT_VECTEUR_3D loc(0,0,rz);
352     OT_VECTEUR_3D 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);
362     //=======================================================
363     //=======================================================
364     loc.change_x(rayon);
365    
366     glob=origine+repere*loc;
367    
368     xyz[0]=glob.get_x();
369     xyz[1]=glob.get_y();
370     xyz[2]=glob.get_z();
371    
372     param.ajouter(xyz[0]);
373     param.ajouter(xyz[1]);
374     param.ajouter(xyz[2]);
375     param.ajouter(0.5);
376    
377     // The second control point have such local cordinate (rayon,rayon)
378    
379     loc.change_y(rayon);
380     glob=origine+repere*loc;
381    
382     xyz[0]=glob.get_x();
383     xyz[1]=glob.get_y();
384     xyz[2]=glob.get_z();
385    
386     param.ajouter(xyz[0]);
387     param.ajouter(xyz[1]);
388     param.ajouter(xyz[2]);
389     param.ajouter(0.25);
390    
391     //the third control point have such local cordinate (-rayon,rayon)
392    
393     loc.change_x(-rayon);
394     glob=origine+repere*loc;
395    
396    
397     xyz[0]=glob.get_x();
398     xyz[1]=glob.get_y();
399     xyz[2]=glob.get_z();
400    
401     param.ajouter(xyz[0]);
402     param.ajouter(xyz[1]);
403     param.ajouter(xyz[2]);
404     param.ajouter(0.25);
405    
406     //The forth point have the local cordinate at(-rayon,rayon)
407    
408     loc.change_y(0);
409    
410     glob=origine+repere*loc;
411    
412     param.ajouter(xyz[0]);
413     param.ajouter(xyz[1]);
414     param.ajouter(xyz[2]);
415     param.ajouter(0.5);
416    
417    
418     //the fifth control point have the corfinate in the local cordinate (-rayon,-rayon)
419    
420    
421     loc.change_y(-rayon);
422    
423     glob=origine+repere*loc;
424    
425    
426     xyz[0]=glob.get_x();
427     xyz[1]=glob.get_y();
428     xyz[2]=glob.get_z();
429    
430     param.ajouter(xyz[0]);
431     param.ajouter(xyz[1]);
432     param.ajouter(xyz[2]);
433     param.ajouter(0.25);
434    
435     //The sixth control point have the cordiante in the local coordinate (rayon,-rayon)
436    
437     loc.change_x(rayon);
438    
439     glob=origine+repere*loc;
440    
441    
442     xyz[0]=glob.get_x();
443     xyz[1]=glob.get_y();
444     xyz[2]=glob.get_z();
445    
446     param.ajouter(xyz[0]);
447     param.ajouter(xyz[1]);
448     param.ajouter(xyz[2]);
449     param.ajouter(0.25);
450    
451     //The last control point have the same local cordinate with rhe first control point (rayon, 0)
452    
453     loc.change_y(0);
454    
455     glob=origine+repere*loc;
456    
457     param.ajouter(xyz[0]);
458     param.ajouter(xyz[1]);
459     param.ajouter(xyz[2]);
460     param.ajouter(0.5);
461     } */
462    
463    
464    
465    
466    
467    
468    
469     }