1 |
francois |
283 |
//------------------------------------------------------------ |
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 |
|
|
// sat_ellipse.cpp |
16 |
|
|
// |
17 |
|
|
//------------------------------------------------------------ |
18 |
|
|
//------------------------------------------------------------ |
19 |
|
|
// COPYRIGHT 2000 |
20 |
|
|
// Version du 02/03/2006 � 11H24 |
21 |
|
|
//------------------------------------------------------------ |
22 |
|
|
//------------------------------------------------------------ |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "gestionversion.h" |
26 |
|
|
#include "sat_ellipse.h" |
27 |
|
|
#include "tpl_fonction.h" |
28 |
|
|
#include "ot_mathematique.h" |
29 |
|
|
#include "constantegeo.h" |
30 |
|
|
|
31 |
|
|
#include <math.h> |
32 |
|
|
|
33 |
|
|
SAT_ELLIPSE::SAT_ELLIPSE(unsigned long num):SAT_COURBE(num) |
34 |
|
|
{ |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
SAT_ELLIPSE::SAT_ELLIPSE():SAT_COURBE() |
38 |
|
|
{ |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
SAT_ELLIPSE::~SAT_ELLIPSE() |
42 |
|
|
{ |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
void SAT_ELLIPSE::evaluer(double t,double *xyz) |
48 |
|
|
{ |
49 |
|
|
xyz[0]=center[0]+major[0]*a*cos(t)+minor[0]*a*ratio*sin(t); |
50 |
|
|
xyz[1]=center[1]+major[1]*a*cos(t)+minor[1]*a*ratio*sin(t); |
51 |
|
|
xyz[2]=center[2]+major[2]*a*cos(t)+minor[2]*a*ratio*sin(t); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
void SAT_ELLIPSE::deriver(double t,double *xyz) |
55 |
|
|
{ |
56 |
|
|
xyz[0]= -major[0]*a*sin(t)+minor[0]*a*ratio*cos(t); |
57 |
|
|
xyz[1]= -major[1]*a*sin(t)+minor[1]*a*ratio*cos(t); |
58 |
|
|
xyz[2]= -major[2]*a*sin(t)+minor[2]*a*ratio*cos(t); |
59 |
|
|
|
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
void SAT_ELLIPSE::deriver_seconde(double t,double *ddxyz,double* dxyz ,double* xyz ) |
63 |
|
|
{ |
64 |
|
|
ddxyz[0]= -major[0]*a*cos(t)-minor[0]*a*ratio*sin(t); |
65 |
|
|
ddxyz[1]= -major[1]*a*cos(t)-minor[1]*a*ratio*sin(t); |
66 |
|
|
ddxyz[2]= -major[2]*a*cos(t)-minor[2]*a*ratio*sin(t); |
67 |
|
|
if (dxyz!=NULL) deriver(t,dxyz); |
68 |
|
|
if (xyz!=NULL) evaluer(t,xyz); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
void SAT_ELLIPSE::inverser(double& t,double *xyz,double precision) |
72 |
|
|
{ |
73 |
|
|
double vecsol[3],veccoef1[3],veccoef2[3]; |
74 |
|
|
vecsol[0]=xyz[0]-center[0]; |
75 |
|
|
vecsol[1]=xyz[1]-center[1]; |
76 |
|
|
vecsol[2]=xyz[2]-center[2]; |
77 |
|
|
veccoef1[0]=major[0]*a; |
78 |
|
|
veccoef1[1]=major[1]*a; |
79 |
|
|
veccoef1[2]=major[2]*a; |
80 |
|
|
veccoef2[0]=minor[0]*a*ratio; |
81 |
|
|
veccoef2[1]=minor[1]*a*ratio; |
82 |
|
|
veccoef2[2]=minor[2]*a*ratio; |
83 |
|
|
|
84 |
|
|
int num1,num2; |
85 |
|
|
double det= veccoef1[0]*veccoef2[1]-veccoef1[1]*veccoef2[0]; |
86 |
|
|
if (OPERATEUR::egal(det,0.0,0.0001)) |
87 |
|
|
{ |
88 |
|
|
det= veccoef1[0]*veccoef2[2]-veccoef1[2]*veccoef2[0]; |
89 |
|
|
if (OPERATEUR::egal(det,0.0,0.0001)) |
90 |
|
|
{ |
91 |
|
|
det= veccoef1[1]*veccoef2[2]-veccoef1[2]*veccoef2[1]; |
92 |
|
|
num1=1; |
93 |
|
|
num2=2; |
94 |
|
|
} |
95 |
|
|
else |
96 |
|
|
{ |
97 |
|
|
num1=0; |
98 |
|
|
num2=2; |
99 |
|
|
} |
100 |
|
|
} |
101 |
|
|
else |
102 |
|
|
{ |
103 |
|
|
num1=0; |
104 |
|
|
num2=1; |
105 |
|
|
} |
106 |
|
|
double co= (vecsol[num1]*veccoef2[num2]-vecsol[num2]*veccoef2[num1])/det; |
107 |
|
|
double si= (vecsol[num2]*veccoef1[num1]-vecsol[num1]*veccoef1[num2])/det; |
108 |
|
|
if (co>1.) co=1.; |
109 |
|
|
if (co<(-1.)) co=(-1.); |
110 |
|
|
t=acos(co); |
111 |
|
|
if (si<-0.0001) t= -t; |
112 |
|
|
if (t<-0.0001) t=t+2*M_PI; |
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
double SAT_ELLIPSE::get_tmin() |
119 |
|
|
{ |
120 |
|
|
return 0.; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
double SAT_ELLIPSE::get_tmax() |
124 |
|
|
{ |
125 |
|
|
return 2.*M_PI; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
int SAT_ELLIPSE::est_periodique(void) |
129 |
|
|
{ |
130 |
|
|
return 1; |
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
double SAT_ELLIPSE::get_periode(void) |
134 |
|
|
{ |
135 |
|
|
return 2.*M_PI; |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
|
139 |
|
|
void SAT_ELLIPSE::calcul_parametre(void) |
140 |
|
|
{ |
141 |
|
|
a=sqrt(major[0]*major[0]+major[1]*major[1]+major[2]*major[2]); |
142 |
|
|
OT_VECTEUR_3D u(major); |
143 |
|
|
OT_VECTEUR_3D w(normal); |
144 |
|
|
OT_VECTEUR_3D v=w&u; |
145 |
|
|
u.norme(); |
146 |
|
|
w.norme(); |
147 |
|
|
v.norme(); |
148 |
|
|
major[0]=u.get_x(); |
149 |
|
|
major[1]=u.get_y(); |
150 |
|
|
major[2]=u.get_z(); |
151 |
|
|
minor[0]=v.get_x(); |
152 |
|
|
minor[1]=v.get_y(); |
153 |
|
|
minor[2]=v.get_z(); |
154 |
|
|
normal[0]=w.get_x(); |
155 |
|
|
normal[1]=w.get_y(); |
156 |
|
|
normal[2]=w.get_z(); |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
double equation_longueur(SAT_ELLIPSE& ellipse,double t) |
172 |
|
|
{ |
173 |
|
|
return sqrt(ellipse.a*ellipse.a*sin(t)*sin(t)+ellipse.a*ellipse.a*ellipse.ratio*ellipse.ratio*cos(t)*cos(t)); |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
double SAT_ELLIPSE::get_longueur(double t1,double t2,double precis) |
180 |
|
|
{ |
181 |
|
|
if (ratio!=1.) |
182 |
|
|
{ |
183 |
|
|
TPL_FONCTION1<double,SAT_ELLIPSE,double> longueur_ellipse(*this,equation_longueur); |
184 |
|
|
return longueur_ellipse.integrer_gauss_2(t1,t2); |
185 |
|
|
} |
186 |
|
|
else |
187 |
|
|
{ |
188 |
|
|
return a*(t2-t1); |
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
|
192 |
|
|
} |
193 |
|
|
|
194 |
|
|
|
195 |
|
|
int SAT_ELLIPSE::get_type_geometrique(TPL_LISTE_ENTITE<double> ¶m) |
196 |
|
|
{ |
197 |
|
|
param.ajouter(center[0]); |
198 |
|
|
param.ajouter(center[1]); |
199 |
|
|
param.ajouter(center[2]); |
200 |
|
|
param.ajouter(major[0]); |
201 |
|
|
param.ajouter(major[1]); |
202 |
|
|
param.ajouter(major[2]); |
203 |
|
|
param.ajouter(normal[0]); |
204 |
|
|
param.ajouter(normal[1]); |
205 |
|
|
param.ajouter(normal[2]); |
206 |
|
|
param.ajouter(a); |
207 |
|
|
param.ajouter(a*ratio); |
208 |
|
|
return MGCo_ELLIPSE; |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
void SAT_ELLIPSE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> ¶m) |
215 |
|
|
{ |
216 |
|
|
double xyz[3]; |
217 |
|
|
|
218 |
|
|
// The first parameter indicate the code access |
219 |
|
|
param.ajouter(1); |
220 |
|
|
|
221 |
|
|
// The follewing two parameters of the list indicate the orders of the net points |
222 |
|
|
|
223 |
|
|
param.ajouter(3); |
224 |
|
|
param.ajouter(0); |
225 |
|
|
|
226 |
|
|
// The follewing two parameters indicate the number of rows and colons of the control points |
227 |
|
|
// respectively to the two parameters directions |
228 |
|
|
|
229 |
|
|
param.ajouter(7); |
230 |
|
|
param.ajouter(0); |
231 |
|
|
|
232 |
|
|
// this present the knot vector in the u-direction |
233 |
|
|
|
234 |
|
|
param.ajouter(0); |
235 |
|
|
param.ajouter(0); |
236 |
|
|
param.ajouter(0); |
237 |
|
|
param.ajouter(0.25); |
238 |
|
|
param.ajouter(0.5); |
239 |
|
|
param.ajouter(0.5); |
240 |
|
|
param.ajouter(0.75); |
241 |
|
|
param.ajouter(1); |
242 |
|
|
param.ajouter(1); |
243 |
|
|
param.ajouter(1); |
244 |
|
|
|
245 |
|
|
|
246 |
|
|
//the first control point |
247 |
|
|
|
248 |
|
|
double ax= a; |
249 |
|
|
double ay= 0; |
250 |
|
|
|
251 |
|
|
xyz[0]=center[0]+major[0]*ax+minor[0]*ay; |
252 |
|
|
xyz[1]=center[1]+major[1]*ax+minor[1]*ay; |
253 |
|
|
xyz[2]=center[2]+major[2]*ax+minor[2]*ay; |
254 |
|
|
|
255 |
|
|
param.ajouter(xyz[0]); |
256 |
|
|
param.ajouter(xyz[1]); |
257 |
|
|
param.ajouter(xyz[2]); |
258 |
|
|
param.ajouter(1); |
259 |
|
|
|
260 |
|
|
// the second control point have such local cordinate (rayon,rayon) |
261 |
|
|
|
262 |
|
|
ay=a*ratio; |
263 |
|
|
|
264 |
|
|
xyz[0]=center[0]+major[0]*ax+minor[0]*ay; |
265 |
|
|
xyz[1]=center[1]+major[1]*ax+minor[1]*ay; |
266 |
|
|
xyz[2]=center[2]+major[2]*ax+minor[2]*ay; |
267 |
|
|
|
268 |
|
|
|
269 |
|
|
|
270 |
|
|
param.ajouter(xyz[0]); |
271 |
|
|
param.ajouter(xyz[1]); |
272 |
|
|
param.ajouter(xyz[2]); |
273 |
|
|
param.ajouter(0.5); |
274 |
|
|
|
275 |
|
|
//the third control point have such local cordinate (-rayon,rayon) |
276 |
|
|
|
277 |
|
|
|
278 |
|
|
ax=-a; |
279 |
|
|
|
280 |
|
|
xyz[0]=center[0]+major[0]*ax+minor[0]*ay; |
281 |
|
|
xyz[1]=center[1]+major[1]*ax+minor[1]*ay; |
282 |
|
|
xyz[2]=center[2]+major[2]*ax+minor[2]*ay; |
283 |
|
|
|
284 |
|
|
|
285 |
|
|
param.ajouter(xyz[0]); |
286 |
|
|
param.ajouter(xyz[1]); |
287 |
|
|
param.ajouter(xyz[2]); |
288 |
|
|
param.ajouter(0.5); |
289 |
|
|
|
290 |
|
|
//The forth point have the local cordinate at(-rayon,rayon) |
291 |
|
|
|
292 |
|
|
ay=0; |
293 |
|
|
|
294 |
|
|
xyz[0]=center[0]+major[0]*ax+minor[0]*ay; |
295 |
|
|
xyz[1]=center[1]+major[1]*ax+minor[1]*ay; |
296 |
|
|
xyz[2]=center[2]+major[2]*ax+minor[2]*ay; |
297 |
|
|
|
298 |
|
|
|
299 |
|
|
param.ajouter(xyz[0]); |
300 |
|
|
param.ajouter(xyz[1]); |
301 |
|
|
param.ajouter(xyz[2]); |
302 |
|
|
param.ajouter(1); |
303 |
|
|
|
304 |
|
|
|
305 |
|
|
//the fifth control point have the corfinate in the local cordinate (-rayon,-rayon) |
306 |
|
|
|
307 |
|
|
ay=-a*ratio; |
308 |
|
|
|
309 |
|
|
xyz[0]=center[0]+major[0]*ax+minor[0]*ay; |
310 |
|
|
xyz[1]=center[1]+major[1]*ax+minor[1]*ay; |
311 |
|
|
xyz[2]=center[2]+major[2]*ax+minor[2]*ay; |
312 |
|
|
|
313 |
|
|
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
param.ajouter(xyz[0]); |
317 |
|
|
param.ajouter(xyz[1]); |
318 |
|
|
param.ajouter(xyz[2]); |
319 |
|
|
param.ajouter(0.5); |
320 |
|
|
|
321 |
|
|
//The sixth control point have the cordiante in the local coordinate (rayon,-rayon) |
322 |
|
|
|
323 |
|
|
ax=a; |
324 |
|
|
|
325 |
|
|
xyz[0]=center[0]+major[0]*ax+minor[0]*ay; |
326 |
|
|
xyz[1]=center[1]+major[1]*ax+minor[1]*ay; |
327 |
|
|
xyz[2]=center[2]+major[2]*ax+minor[2]*ay; |
328 |
|
|
|
329 |
|
|
|
330 |
|
|
param.ajouter(xyz[0]); |
331 |
|
|
param.ajouter(xyz[1]); |
332 |
|
|
param.ajouter(xyz[2]); |
333 |
|
|
param.ajouter(0.5); |
334 |
|
|
|
335 |
|
|
//The last control point have the same local cordinate with rhe first control point (rayon, 0) |
336 |
|
|
|
337 |
|
|
ay=0; |
338 |
|
|
|
339 |
|
|
xyz[0]=center[0]+major[0]*ax+minor[0]*ay; |
340 |
|
|
xyz[1]=center[1]+major[1]*ax+minor[1]*ay; |
341 |
|
|
xyz[2]=center[2]+major[2]*ax+minor[2]*ay; |
342 |
|
|
|
343 |
|
|
|
344 |
|
|
param.ajouter(xyz[0]); |
345 |
|
|
param.ajouter(xyz[1]); |
346 |
|
|
param.ajouter(xyz[2]); |
347 |
|
|
param.ajouter(1); |
348 |
|
|
|
349 |
|
|
indx_premier_ptctr=15; |
350 |
|
|
|
351 |
|
|
} |