Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1992-08-06 |
2 | // Created by: Laurent BUCHARD | |
3 | // Copyright (c) 1992-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | //---------------------------------------------------------------------- |
22 | //-- Purposse: Geometric Intersection between two Natural Quadric | |
23 | //-- If the intersection is not a conic, | |
24 | //-- analytical methods must be called. | |
25 | //---------------------------------------------------------------------- | |
26 | #ifndef DEB | |
27 | #define No_Standard_RangeError | |
28 | #define No_Standard_OutOfRange | |
29 | #endif | |
30 | ||
31 | #include <IntAna_QuadQuadGeo.ixx> | |
32 | ||
33 | #include <IntAna_IntConicQuad.hxx> | |
34 | #include <StdFail_NotDone.hxx> | |
35 | #include <Standard_DomainError.hxx> | |
36 | #include <Standard_OutOfRange.hxx> | |
37 | #include <math_DirectPolynomialRoots.hxx> | |
38 | ||
39 | #include <gp.hxx> | |
40 | #include <gp_Pln.hxx> | |
41 | #include <gp_Vec.hxx> | |
42 | #include <ElSLib.hxx> | |
43 | #include <ElCLib.hxx> | |
44 | ||
45 | #include <gp_Dir.hxx> | |
46 | #include <gp_XYZ.hxx> | |
47 | #include <gp_Pnt2d.hxx> | |
48 | #include <gp_Vec2d.hxx> | |
49 | #include <gp_Dir2d.hxx> | |
50 | ||
51 | ||
52 | static | |
53 | gp_Ax2 DirToAx2(const gp_Pnt& P,const gp_Dir& D); | |
77088633 | 54 | static |
55 | void RefineDir(gp_Dir& aDir); | |
7fd59977 | 56 | |
57 | //======================================================================= | |
58 | //class : | |
59 | //purpose : O p e r a t i o n s D i v e r s e s s u r d e s A x 1 | |
60 | //======================================================================= | |
61 | class AxeOperator { | |
62 | public: | |
63 | AxeOperator(const gp_Ax1& A1,const gp_Ax1& A2); | |
64 | ||
65 | void Distance(Standard_Real& dist, | |
66 | Standard_Real& Param1, | |
67 | Standard_Real& Param2); | |
68 | ||
69 | gp_Pnt PtIntersect() { | |
70 | return ptintersect; | |
71 | } | |
72 | Standard_Boolean Coplanar(void) { | |
73 | return thecoplanar; | |
74 | } | |
75 | Standard_Boolean Same(void) { | |
76 | return theparallel && (thedistance<myEPSILON_DISTANCE); | |
77 | } | |
78 | Standard_Real Distance(void) { | |
79 | return thedistance ; | |
80 | } | |
81 | Standard_Boolean Intersect(void) { | |
82 | return (thecoplanar && (!theparallel)); | |
83 | } | |
84 | Standard_Boolean Parallel(void) { | |
85 | return theparallel; | |
86 | } | |
87 | Standard_Boolean Normal(void) { | |
88 | return thenormal; | |
89 | } | |
90 | ||
91 | protected: | |
92 | Standard_Real Det33(const Standard_Real a11, | |
93 | const Standard_Real a12, | |
94 | const Standard_Real a13, | |
95 | const Standard_Real a21, | |
96 | const Standard_Real a22, | |
97 | const Standard_Real a23, | |
98 | const Standard_Real a31, | |
99 | const Standard_Real a32, | |
100 | const Standard_Real a33) { | |
101 | Standard_Real theReturn = | |
102 | a11*(a22*a33-a32*a23) - a21*(a12*a33-a32*a13) + a31*(a12*a23-a22*a13) ; | |
103 | return theReturn ; | |
104 | } | |
105 | ||
106 | private: | |
107 | gp_Pnt ptintersect; | |
108 | gp_Ax1 Axe1; | |
109 | gp_Ax1 Axe2; | |
110 | Standard_Real thedistance; | |
111 | Standard_Boolean theparallel; | |
112 | Standard_Boolean thecoplanar; | |
113 | Standard_Boolean thenormal; | |
114 | // | |
115 | Standard_Real myEPSILON_DISTANCE; | |
116 | Standard_Real myEPSILON_AXES_PARA; | |
117 | }; | |
118 | ||
119 | //======================================================================= | |
120 | //function : AxeOperator::AxeOperator | |
121 | //purpose : | |
122 | //======================================================================= | |
123 | AxeOperator::AxeOperator(const gp_Ax1& A1,const gp_Ax1& A2) | |
124 | { | |
125 | myEPSILON_DISTANCE=0.00000000000001; | |
126 | myEPSILON_AXES_PARA=0.000000000001; | |
127 | Axe1=A1; | |
128 | Axe2=A2; | |
129 | //--------------------------------------------------------------------- | |
130 | gp_Dir V1=Axe1.Direction(); | |
131 | gp_Dir V2=Axe2.Direction(); | |
132 | gp_Pnt P1=Axe1.Location(); | |
133 | gp_Pnt P2=Axe2.Location(); | |
77088633 | 134 | // |
135 | RefineDir(V1); | |
136 | RefineDir(V2); | |
7fd59977 | 137 | thecoplanar= Standard_False; |
138 | thenormal = Standard_False; | |
139 | ||
140 | //--- check if the two axis are parallel | |
141 | theparallel=V1.IsParallel(V2, myEPSILON_AXES_PARA); | |
142 | //--- Distance between the two axis | |
143 | gp_XYZ perp(A1.Direction().XYZ().Crossed(A2.Direction().XYZ())); | |
144 | if (theparallel) { | |
145 | gp_Lin L1(A1); | |
146 | thedistance = L1.Distance(A2.Location()); | |
147 | } | |
148 | else { | |
149 | thedistance = Abs(gp_Vec(perp.Normalized()).Dot(gp_Vec(Axe1.Location(), | |
150 | Axe2.Location()))); | |
151 | } | |
152 | //--- check if Axis are Coplanar | |
153 | Standard_Real D33; | |
154 | if(thedistance<myEPSILON_DISTANCE) { | |
155 | D33=Det33(V1.X(),V1.Y(),V1.Z() | |
156 | ,V2.X(),V2.Y(),V2.Z() | |
157 | ,P1.X()-P2.X(),P1.Y()-P2.Y(),P1.Z()-P2.Z()); | |
158 | if(Abs(D33)<=myEPSILON_DISTANCE) { | |
159 | thecoplanar=Standard_True; | |
160 | } | |
161 | } | |
162 | else { | |
163 | thecoplanar=Standard_True; | |
164 | thenormal=(V1.Dot(V2)==0.0)? Standard_True : Standard_False; | |
165 | } | |
166 | //--- check if the two axis are concurrent | |
167 | if(thecoplanar && (!theparallel)) { | |
168 | Standard_Real smx=P2.X() - P1.X(); | |
169 | Standard_Real smy=P2.Y() - P1.Y(); | |
170 | Standard_Real smz=P2.Z() - P1.Z(); | |
171 | Standard_Real Det1,Det2,Det3,A; | |
172 | Det1=V1.Y() * V2.X() - V1.X() * V2.Y(); | |
173 | Det2=V1.Z() * V2.Y() - V1.Y() * V2.Z(); | |
174 | Det3=V1.Z() * V2.X() - V1.X() * V2.Z(); | |
175 | ||
176 | if((Det1!=0.0) && ((Abs(Det1) >= Abs(Det2))&&(Abs(Det1) >= Abs(Det3)))) { | |
177 | A=(smy * V2.X() - smx * V2.Y())/Det1; | |
178 | } | |
179 | else if((Det2!=0.0) | |
180 | && ((Abs(Det2) >= Abs(Det1)) | |
181 | &&(Abs(Det2) >= Abs(Det3)))) { | |
182 | A=(smz * V2.Y() - smy * V2.Z())/Det2; | |
183 | } | |
184 | else { | |
185 | A=(smz * V2.X() - smx * V2.Z())/Det3; | |
186 | } | |
187 | ptintersect.SetCoord( P1.X() + A * V1.X() | |
188 | ,P1.Y() + A * V1.Y() | |
189 | ,P1.Z() + A * V1.Z()); | |
190 | } | |
191 | else { | |
192 | ptintersect.SetCoord(0,0,0); //-- Pour eviter des FPE | |
193 | } | |
194 | } | |
195 | //======================================================================= | |
196 | //function : Distance | |
197 | //purpose : | |
198 | //======================================================================= | |
199 | void AxeOperator::Distance(Standard_Real& dist,Standard_Real& Param1,Standard_Real& Param2) | |
200 | { | |
201 | gp_Vec O1O2(Axe1.Location(),Axe2.Location()); //----------------------------- | |
202 | gp_Dir U1 = Axe1.Direction(); //-- juste pour voir. | |
203 | gp_Dir U2 = Axe2.Direction(); | |
204 | ||
205 | gp_Dir N = U1.Crossed(U2); | |
206 | Standard_Real D = Det33(U1.X(),U2.X(),N.X(), | |
207 | U1.Y(),U2.Y(),N.Y(), | |
208 | U1.Z(),U2.Z(),N.Z()); | |
209 | if(D) { | |
210 | dist = Det33(U1.X(),U2.X(),O1O2.X(), | |
211 | U1.Y(),U2.Y(),O1O2.Y(), | |
212 | U1.Z(),U2.Z(),O1O2.Z()) / D; | |
213 | Param1 = Det33(O1O2.X(),U2.X(),N.X(), | |
214 | O1O2.Y(),U2.Y(),N.Y(), | |
215 | O1O2.Z(),U2.Z(),N.Z()) / (-D); | |
216 | //------------------------------------------------------------ | |
217 | //-- On resout P1 * Dir1 + P2 * Dir2 + d * N = O1O2 | |
218 | //-- soit : Segment perpendiculaire : O1+P1 D1 | |
219 | //-- O2-P2 D2 | |
220 | Param2 = Det33(U1.X(),O1O2.X(),N.X(), | |
221 | U1.Y(),O1O2.Y(),N.Y(), | |
222 | U1.Z(),O1O2.Z(),N.Z()) / (D); | |
223 | } | |
224 | } | |
225 | //======================================================================= | |
226 | //function : DirToAx2 | |
227 | //purpose : returns a gp_Ax2 where D is the main direction | |
228 | //======================================================================= | |
229 | gp_Ax2 DirToAx2(const gp_Pnt& P,const gp_Dir& D) | |
230 | { | |
231 | Standard_Real x=D.X(); Standard_Real ax=Abs(x); | |
232 | Standard_Real y=D.Y(); Standard_Real ay=Abs(y); | |
233 | Standard_Real z=D.Z(); Standard_Real az=Abs(z); | |
234 | if( (ax==0.0) || ((ax<ay) && (ax<az)) ) { | |
235 | return(gp_Ax2(P,D,gp_Dir(gp_Vec(0.0,-z,y)))); | |
236 | } | |
237 | else if( (ay==0.0) || ((ay<ax) && (ay<az)) ) { | |
238 | return(gp_Ax2(P,D,gp_Dir(gp_Vec(-z,0.0,x)))); | |
239 | } | |
240 | else { | |
241 | return(gp_Ax2(P,D,gp_Dir(gp_Vec(-y,x,0.0)))); | |
242 | } | |
243 | } | |
244 | //======================================================================= | |
245 | //function : IntAna_QuadQuadGeo | |
246 | //purpose : Empty constructor | |
247 | //======================================================================= | |
248 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo(void) | |
249 | : done(Standard_False), | |
250 | nbint(0), | |
251 | typeres(IntAna_Empty), | |
252 | pt1(0,0,0), | |
253 | pt2(0,0,0), | |
254 | param1(0), | |
255 | param2(0), | |
256 | param1bis(0), | |
257 | param2bis(0), | |
258 | myCommonGen(Standard_False), | |
259 | myPChar(0,0,0) | |
260 | { | |
261 | InitTolerances(); | |
262 | } | |
263 | //======================================================================= | |
264 | //function : InitTolerances | |
265 | //purpose : | |
266 | //======================================================================= | |
267 | void IntAna_QuadQuadGeo::InitTolerances() | |
268 | { | |
269 | myEPSILON_DISTANCE = 0.00000000000001; | |
270 | myEPSILON_ANGLE_CONE = 0.000000000001; | |
271 | myEPSILON_MINI_CIRCLE_RADIUS = 0.000000001; | |
272 | myEPSILON_CYLINDER_DELTA_RADIUS = 0.0000000000001; | |
273 | myEPSILON_CYLINDER_DELTA_DISTANCE= 0.0000001; | |
274 | myEPSILON_AXES_PARA = 0.000000000001; | |
275 | } | |
276 | //======================================================================= | |
277 | //function : IntAna_QuadQuadGeo | |
278 | //purpose : Pln Pln | |
279 | //======================================================================= | |
280 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo(const gp_Pln& P1, | |
281 | const gp_Pln& P2, | |
282 | const Standard_Real TolAng, | |
283 | const Standard_Real Tol) | |
284 | : done(Standard_False), | |
285 | nbint(0), | |
286 | typeres(IntAna_Empty), | |
287 | pt1(0,0,0), | |
288 | pt2(0,0,0), | |
289 | param1(0), | |
290 | param2(0), | |
291 | param1bis(0), | |
292 | param2bis(0), | |
293 | myCommonGen(Standard_False), | |
294 | myPChar(0,0,0) | |
295 | { | |
296 | InitTolerances(); | |
297 | Perform(P1,P2,TolAng,Tol); | |
298 | } | |
299 | //======================================================================= | |
300 | //function : Perform | |
301 | //purpose : | |
302 | //======================================================================= | |
303 | void IntAna_QuadQuadGeo::Perform (const gp_Pln& P1, | |
304 | const gp_Pln& P2, | |
305 | const Standard_Real TolAng, | |
306 | const Standard_Real Tol) | |
307 | { | |
308 | done=Standard_False; | |
309 | // | |
310 | param2bis=0.0; | |
311 | ||
312 | Standard_Real A1 = 0., B1 = 0., C1 = 0., D1 = 0., A2 = 0., B2 = 0., C2 = 0., D2 = 0.; | |
313 | P1.Coefficients(A1,B1,C1,D1); | |
314 | P2.Coefficients(A2,B2,C2,D2); | |
315 | ||
316 | gp_Vec vd(gp_Vec(A1,B1,C1).Crossed(gp_Vec(A2,B2,C2))); | |
317 | Standard_Real dist1= A2*P1.Location().X() + B2*P1.Location().Y() + C2*P1.Location().Z() + D2; | |
318 | Standard_Real dist2= A1*P2.Location().X() + B1*P2.Location().Y() + C1*P2.Location().Z() + D1; | |
319 | ||
320 | if(vd.Magnitude() <=TolAng) { | |
321 | // normalles are collinear - planes are same or parallel | |
322 | typeres = (Abs(dist1) <= Tol && Abs(dist2) <= Tol) ? IntAna_Same : IntAna_Empty; | |
323 | } | |
324 | else { | |
325 | Standard_Real denom=A1*A2 + B1*B2 + C1*C2; | |
326 | ||
327 | Standard_Real denom2 = denom*denom; | |
328 | Standard_Real ddenom = 1. - denom2; | |
4355f260 | 329 | //denom = ( Abs(ddenom) <= 1.e-9 ) ? 1.e-9 : ddenom; |
330 | denom = ( Abs(ddenom) <= 1.e-16 ) ? 1.e-16 : ddenom; | |
7fd59977 | 331 | |
332 | Standard_Real par1 = dist1/denom; | |
333 | Standard_Real par2 = -dist2/denom; | |
334 | ||
335 | gp_Vec inter1(gp_Vec(A1,B1,C1).Crossed(vd)); | |
336 | gp_Vec inter2(gp_Vec(A2,B2,C2).Crossed(vd)); | |
337 | ||
338 | Standard_Real X1=P1.Location().X() + par1*inter1.X(); | |
339 | Standard_Real Y1=P1.Location().Y() + par1*inter1.Y(); | |
340 | Standard_Real Z1=P1.Location().Z() + par1*inter1.Z(); | |
341 | Standard_Real X2=P2.Location().X() + par2*inter2.X(); | |
342 | Standard_Real Y2=P2.Location().Y() + par2*inter2.Y(); | |
343 | Standard_Real Z2=P2.Location().Z() + par2*inter2.Z(); | |
344 | ||
345 | pt1=gp_Pnt((X1+X2)*0.5, (Y1+Y2)*0.5, (Z1+Z2)*0.5); | |
346 | dir1 = gp_Dir(vd); | |
347 | typeres = IntAna_Line; | |
348 | nbint = 1; | |
349 | ||
350 | } | |
351 | done=Standard_True; | |
352 | } | |
353 | //======================================================================= | |
354 | //function : IntAna_QuadQuadGeo | |
355 | //purpose : Pln Cylinder | |
356 | //======================================================================= | |
357 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo( const gp_Pln& P | |
358 | ,const gp_Cylinder& Cl | |
359 | ,const Standard_Real Tolang | |
04cbc9d3 | 360 | ,const Standard_Real Tol |
361 | ,const Standard_Real H) | |
7fd59977 | 362 | : done(Standard_False), |
363 | nbint(0), | |
364 | typeres(IntAna_Empty), | |
365 | pt1(0,0,0), | |
366 | pt2(0,0,0), | |
367 | param1(0), | |
368 | param2(0), | |
369 | param1bis(0), | |
370 | param2bis(0), | |
371 | myCommonGen(Standard_False), | |
372 | myPChar(0,0,0) | |
373 | { | |
374 | InitTolerances(); | |
04cbc9d3 | 375 | Perform(P,Cl,Tolang,Tol,H); |
7fd59977 | 376 | } |
377 | //======================================================================= | |
378 | //function : Perform | |
379 | //purpose : | |
380 | //======================================================================= | |
381 | void IntAna_QuadQuadGeo::Perform( const gp_Pln& P | |
04cbc9d3 | 382 | ,const gp_Cylinder& Cl |
383 | ,const Standard_Real Tolang | |
384 | ,const Standard_Real Tol | |
385 | ,const Standard_Real H) | |
7fd59977 | 386 | { |
387 | done = Standard_False; | |
388 | Standard_Real dist,radius; | |
389 | Standard_Real A,B,C,D; | |
390 | Standard_Real X,Y,Z; | |
391 | Standard_Real sint,cost,h; | |
392 | gp_XYZ axex,axey,omega; | |
393 | ||
394 | ||
395 | param2bis=0.0; | |
396 | radius = Cl.Radius(); | |
397 | ||
398 | gp_Lin axec(Cl.Axis()); | |
399 | gp_XYZ normp(P.Axis().Direction().XYZ()); | |
400 | ||
401 | P.Coefficients(A,B,C,D); | |
402 | axec.Location().Coord(X,Y,Z); | |
403 | dist = A*X + B*Y + C*Z + D; // la distance axe/plan est evaluee a l origine de l axe. | |
404 | ||
405 | Standard_Real tolang = Tolang; | |
406 | Standard_Boolean newparams = Standard_False; | |
407 | ||
408 | gp_Vec ldv( axec.Direction() ); | |
409 | gp_Vec npv( normp ); | |
410 | Standard_Real dA = Abs( ldv.Angle( npv ) ); | |
c6541a0c | 411 | if( dA > (M_PI/4.) ) |
7fd59977 | 412 | { |
c6541a0c | 413 | Standard_Real dang = Abs( ldv.Angle( npv ) ) - M_PI/2.; |
7fd59977 | 414 | Standard_Real dangle = Abs( dang ); |
415 | if( dangle > Tolang ) | |
416 | { | |
417 | Standard_Real sinda = Abs( Sin( dangle ) ); | |
418 | Standard_Real dif = Abs( sinda - Tol ); | |
419 | if( dif < Tol ) | |
420 | { | |
421 | tolang = sinda * 2.; | |
422 | newparams = Standard_True; | |
423 | } | |
424 | } | |
425 | } | |
426 | ||
427 | nbint = 0; | |
04cbc9d3 | 428 | IntAna_IntConicQuad inter(axec,P,tolang,Tol,H); |
7fd59977 | 429 | |
430 | if (inter.IsParallel()) { | |
431 | // Le resultat de l intersection Plan-Cylindre est de type droite. | |
432 | // il y a 1 ou 2 droites | |
433 | ||
434 | typeres = IntAna_Line; | |
435 | omega.SetCoord(X-dist*A,Y-dist*B,Z-dist*C); | |
436 | ||
437 | if (Abs(Abs(dist)-radius) < Tol) | |
438 | { | |
439 | nbint = 1; | |
440 | pt1.SetXYZ(omega); | |
441 | ||
442 | if( newparams ) | |
443 | { | |
444 | gp_XYZ omegaXYZ(X,Y,Z); | |
445 | gp_XYZ omegaXYZtrnsl( omegaXYZ + 100.*axec.Direction().XYZ() ); | |
446 | Standard_Real Xt,Yt,Zt,distt; | |
447 | omegaXYZtrnsl.Coord(Xt,Yt,Zt); | |
448 | distt = A*Xt + B*Yt + C*Zt + D; | |
449 | gp_XYZ omega1( omegaXYZtrnsl.X()-distt*A, omegaXYZtrnsl.Y()-distt*B, omegaXYZtrnsl.Z()-distt*C ); | |
450 | gp_Pnt ppt1; | |
451 | ppt1.SetXYZ( omega1 ); | |
452 | gp_Vec vv1(pt1,ppt1); | |
453 | gp_Dir dd1( vv1 ); | |
454 | dir1 = dd1; | |
455 | } | |
456 | else | |
457 | dir1 = axec.Direction(); | |
458 | } | |
459 | else if (Abs(dist) < radius) | |
460 | { | |
461 | nbint = 2; | |
462 | h = Sqrt(radius*radius - dist*dist); | |
463 | axey = axec.Direction().XYZ().Crossed(normp); // axey est normalise | |
464 | ||
465 | pt1.SetXYZ(omega - h*axey); | |
466 | pt2.SetXYZ(omega + h*axey); | |
467 | ||
468 | if( newparams ) | |
469 | { | |
470 | gp_XYZ omegaXYZ(X,Y,Z); | |
471 | gp_XYZ omegaXYZtrnsl( omegaXYZ + 100.*axec.Direction().XYZ() ); | |
472 | Standard_Real Xt,Yt,Zt,distt,ht; | |
473 | omegaXYZtrnsl.Coord(Xt,Yt,Zt); | |
474 | distt = A*Xt + B*Yt + C*Zt + D; | |
475 | // ht = Sqrt(radius*radius - distt*distt); | |
476 | Standard_Real anSqrtArg = radius*radius - distt*distt; | |
477 | ht = (anSqrtArg > 0.) ? Sqrt(anSqrtArg) : 0.; | |
478 | ||
479 | gp_XYZ omega1( omegaXYZtrnsl.X()-distt*A, omegaXYZtrnsl.Y()-distt*B, omegaXYZtrnsl.Z()-distt*C ); | |
480 | gp_Pnt ppt1,ppt2; | |
481 | ppt1.SetXYZ( omega1 - ht*axey); | |
482 | ppt2.SetXYZ( omega1 + ht*axey); | |
483 | gp_Vec vv1(pt1,ppt1); | |
484 | gp_Vec vv2(pt2,ppt2); | |
485 | gp_Dir dd1( vv1 ); | |
486 | gp_Dir dd2( vv2 ); | |
487 | dir1 = dd1; | |
488 | dir2 = dd2; | |
489 | } | |
490 | else | |
491 | { | |
492 | dir1 = axec.Direction(); | |
493 | dir2 = axec.Direction(); | |
494 | } | |
495 | } | |
496 | // else nbint = 0 | |
497 | ||
498 | // debug JAG : le nbint = 0 doit etre remplace par typeres = IntAna_Empty | |
499 | // et ne pas etre seulement supprime... | |
500 | ||
501 | else { | |
502 | typeres = IntAna_Empty; | |
503 | } | |
504 | } | |
505 | else { // Il y a un point d intersection. C est le centre du cercle | |
506 | // ou de l ellipse solution. | |
507 | ||
508 | nbint = 1; | |
509 | axey = normp.Crossed(axec.Direction().XYZ()); | |
510 | sint = axey.Modulus(); | |
511 | ||
512 | pt1 = inter.Point(1); | |
513 | ||
514 | if (sint < Tol/radius) { | |
515 | ||
516 | // on construit un cercle avec comme axes X et Y ceux du cylindre | |
517 | typeres = IntAna_Circle; | |
518 | ||
519 | dir1 = axec.Direction(); // axe Z | |
520 | dir2 = Cl.Position().XDirection(); | |
521 | param1 = radius; | |
522 | } | |
523 | else { | |
524 | ||
525 | // on construit un ellipse | |
526 | typeres = IntAna_Ellipse; | |
527 | cost = Abs(axec.Direction().XYZ().Dot(normp)); | |
528 | axex = axey.Crossed(normp); | |
529 | ||
530 | dir1.SetXYZ(normp); //Modif ds ce bloc | |
531 | dir2.SetXYZ(axex); | |
532 | ||
533 | param1 = radius/cost; | |
534 | param1bis = radius; | |
535 | } | |
536 | } | |
788cbaf4 | 537 | |
7fd59977 | 538 | done = Standard_True; |
539 | } | |
540 | //======================================================================= | |
541 | //function : IntAna_QuadQuadGeo | |
542 | //purpose : Pln Cone | |
543 | //======================================================================= | |
544 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo(const gp_Pln& P, | |
545 | const gp_Cone& Co, | |
546 | const Standard_Real Tolang, | |
547 | const Standard_Real Tol) | |
548 | : done(Standard_False), | |
549 | nbint(0), | |
550 | typeres(IntAna_Empty), | |
551 | pt1(0,0,0), | |
552 | pt2(0,0,0), | |
553 | param1(0), | |
554 | param2(0), | |
555 | param1bis(0), | |
556 | param2bis(0), | |
557 | myCommonGen(Standard_False), | |
558 | myPChar(0,0,0) | |
559 | { | |
560 | InitTolerances(); | |
561 | Perform(P,Co,Tolang,Tol); | |
562 | } | |
563 | //======================================================================= | |
564 | //function : Perform | |
565 | //purpose : | |
566 | //======================================================================= | |
567 | void IntAna_QuadQuadGeo::Perform(const gp_Pln& P, | |
568 | const gp_Cone& Co, | |
569 | const Standard_Real Tolang, | |
570 | const Standard_Real Tol) | |
571 | { | |
572 | ||
573 | done = Standard_False; | |
574 | nbint = 0; | |
575 | ||
576 | Standard_Real A,B,C,D; | |
577 | Standard_Real X,Y,Z; | |
578 | Standard_Real dist,sint,cost,sina,cosa,angl,costa; | |
579 | Standard_Real dh; | |
580 | gp_XYZ axex,axey; | |
581 | ||
582 | gp_Lin axec(Co.Axis()); | |
583 | P.Coefficients(A,B,C,D); | |
584 | gp_Pnt apex(Co.Apex()); | |
585 | ||
586 | apex.Coord(X,Y,Z); | |
587 | dist = A*X + B*Y + C*Z + D; // distance signee sommet du cone/ Plan | |
588 | ||
589 | gp_XYZ normp = P.Axis().Direction().XYZ(); | |
590 | if(P.Direct()==Standard_False) { //-- lbr le 14 jan 97 | |
591 | normp.Reverse(); | |
592 | } | |
593 | ||
594 | axey = normp.Crossed(Co.Axis().Direction().XYZ()); | |
595 | axex = axey.Crossed(normp); | |
596 | ||
597 | ||
598 | angl = Co.SemiAngle(); | |
599 | ||
600 | cosa = Cos(angl); | |
601 | sina = Abs(Sin(angl)); | |
602 | ||
603 | ||
604 | // Angle entre la normale au plan et l axe du cone, ramene entre 0. et PI/2. | |
605 | ||
606 | sint = axey.Modulus(); | |
607 | cost = Abs(Co.Axis().Direction().XYZ().Dot(normp)); | |
608 | ||
609 | // Le calcul de costa permet de determiner si le plan contient | |
610 | // un generatrice du cone : on calcul Sin((PI/2. - t) - angl) | |
611 | ||
612 | costa = cost*cosa - sint*sina; // sin((PI/2 -t)-angl)=cos(t+angl) | |
613 | // avec t ramene entre 0 et pi/2. | |
614 | ||
615 | if (Abs(dist) < Tol) { | |
616 | // on considere que le plan contient le sommet du cone. | |
617 | // les solutions possibles sont donc : 1 point, 1 droite, 2 droites | |
618 | // selon l inclinaison du plan. | |
619 | ||
620 | if (Abs(costa) < Tolang) { // plan parallele a la generatrice | |
621 | typeres = IntAna_Line; | |
622 | nbint = 1; | |
623 | gp_XYZ ptonaxe(apex.XYZ() + 10.*(Co.Axis().Direction().XYZ())); | |
624 | // point sur l axe du cone cote z positif | |
625 | ||
626 | dist = A*ptonaxe.X() + B*ptonaxe.Y() + C*ptonaxe.Z() + D; | |
627 | ptonaxe = ptonaxe - dist*normp; | |
628 | pt1 = apex; | |
629 | dir1.SetXYZ(ptonaxe - pt1.XYZ()); | |
630 | } | |
631 | else if (cost < sina) { // plan "interieur" au cone | |
632 | typeres = IntAna_Line; | |
633 | nbint = 2; | |
634 | pt1 = apex; | |
635 | pt2 = apex; | |
636 | dh = Sqrt(sina*sina-cost*cost)/cosa; | |
637 | dir1.SetXYZ(axex + dh*axey); | |
638 | dir2.SetXYZ(axex - dh*axey); | |
639 | } | |
640 | else { // plan "exterieur" au cone | |
641 | typeres = IntAna_Point; | |
642 | nbint = 1; | |
643 | pt1 = apex; | |
644 | } | |
645 | } | |
646 | else { | |
647 | // Solutions possibles : cercle, ellipse, parabole, hyperbole selon | |
648 | // l inclinaison du plan. | |
649 | Standard_Real deltacenter, distance; | |
650 | ||
651 | if (cost < Tolang) { | |
652 | // Le plan contient la direction de l axe du cone. La solution est | |
653 | // l hyperbole | |
654 | typeres = IntAna_Hyperbola; | |
655 | nbint = 2; | |
656 | pt1.SetXYZ(apex.XYZ()-dist*normp); | |
657 | pt2 = pt1; | |
658 | dir1=normp; | |
659 | dir2.SetXYZ(axex); | |
660 | param1 = param2 = Abs(dist/Tan(angl)); | |
661 | param1bis = param2bis = Abs(dist); | |
662 | } | |
663 | else { | |
664 | ||
665 | IntAna_IntConicQuad inter(axec,P,Tolang); // on a necessairement 1 point. | |
666 | ||
667 | gp_Pnt center(inter.Point(1)); | |
668 | ||
669 | // En fonction de la position de l intersection par rapport au sommet | |
670 | // du cone, on change l axe x en -x et y en -y. Le parametre du sommet | |
671 | // sur axec est negatif (voir definition du cone) | |
672 | ||
673 | distance = apex.Distance(center); | |
674 | ||
675 | if (inter.ParamOnConic(1) + Co.RefRadius()/Tan(angl) < 0.) { | |
676 | axex.Reverse(); | |
677 | axey.Reverse(); | |
678 | } | |
679 | ||
680 | if (Abs(costa) < Tolang) { // plan parallele a une generatrice | |
681 | typeres = IntAna_Parabola; | |
682 | nbint = 1; | |
683 | deltacenter = distance/2./cosa; | |
684 | axex.Normalize(); | |
685 | pt1.SetXYZ(center.XYZ()-deltacenter*axex); | |
686 | dir1 = normp; | |
687 | dir2.SetXYZ(axex); | |
688 | param1 = deltacenter*sina*sina; | |
689 | } | |
690 | else if (sint < Tolang) { // plan perpendiculaire a l axe | |
691 | typeres = IntAna_Circle; | |
692 | nbint = 1; | |
693 | pt1 = center; | |
694 | dir1 = Co.Position().Direction(); | |
695 | dir2 = Co.Position().XDirection(); | |
696 | param1 = apex.Distance(center)*Abs(Tan(angl)); | |
697 | } | |
698 | else if (cost < sina ) { | |
699 | typeres = IntAna_Hyperbola; | |
700 | nbint = 2; | |
701 | axex.Normalize(); | |
702 | ||
703 | deltacenter = sint*sina*sina*distance/(sina*sina - cost*cost); | |
704 | pt1.SetXYZ(center.XYZ() - deltacenter*axex); | |
705 | pt2 = pt1; | |
706 | dir1 = normp; | |
707 | dir2.SetXYZ(axex); | |
708 | param1 = param2 = cost*sina*cosa*distance /(sina*sina-cost*cost); | |
709 | param1bis = param2bis = cost*sina*distance / Sqrt(sina*sina-cost*cost); | |
710 | ||
711 | } | |
712 | else { // on a alors cost > sina | |
713 | typeres = IntAna_Ellipse; | |
714 | nbint = 1; | |
715 | Standard_Real radius = cost*sina*cosa*distance/(cost*cost-sina*sina); | |
716 | deltacenter = sint*sina*sina*distance/(cost*cost-sina*sina); | |
717 | axex.Normalize(); | |
718 | pt1.SetXYZ(center.XYZ() + deltacenter*axex); | |
719 | dir1 = normp; | |
720 | dir2.SetXYZ(axex); | |
721 | param1 = radius; | |
722 | param1bis = cost*sina*distance/ Sqrt(cost*cost - sina*sina); | |
723 | } | |
724 | } | |
725 | } | |
726 | ||
727 | //-- On a du mal a gerer plus loin (Value ProjLib, Params ... ) | |
728 | //-- des hyperboles trop bizarres | |
729 | //-- On retourne False -> Traitement par biparametree | |
730 | static Standard_Real EllipseLimit = 1.0E+9; //OCC513(apo) 1000000 | |
731 | static Standard_Real HyperbolaLimit = 2.0E+6; //OCC537(apo) 50000 | |
732 | if(typeres==IntAna_Ellipse && nbint>=1) { | |
733 | if(Abs(param1) > EllipseLimit || Abs(param1bis) > EllipseLimit) { | |
734 | done=Standard_False; | |
735 | return; | |
736 | } | |
737 | } | |
738 | if(typeres==IntAna_Hyperbola && nbint>=2) { | |
739 | if(Abs(param2) > HyperbolaLimit || Abs(param2bis) > HyperbolaLimit) { | |
740 | done = Standard_False; | |
741 | return; | |
742 | } | |
743 | } | |
744 | if(typeres==IntAna_Hyperbola && nbint>=1) { | |
745 | if(Abs(param1) > HyperbolaLimit || Abs(param1bis) > HyperbolaLimit) { | |
746 | done=Standard_False; | |
747 | return; | |
748 | } | |
749 | } | |
750 | ||
751 | done = Standard_True; | |
752 | } | |
753 | ||
754 | //======================================================================= | |
755 | //function : IntAna_QuadQuadGeo | |
756 | //purpose : Pln Sphere | |
757 | //======================================================================= | |
758 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo(const gp_Pln& P, | |
759 | const gp_Sphere& S) | |
760 | : done(Standard_False), | |
761 | nbint(0), | |
762 | typeres(IntAna_Empty), | |
763 | pt1(0,0,0), | |
764 | pt2(0,0,0), | |
765 | param1(0), | |
766 | param2(0), | |
767 | param1bis(0), | |
768 | param2bis(0), | |
769 | myCommonGen(Standard_False), | |
770 | myPChar(0,0,0) | |
771 | { | |
772 | InitTolerances(); | |
773 | Perform(P,S); | |
774 | } | |
775 | //======================================================================= | |
776 | //function : Perform | |
777 | //purpose : | |
778 | //======================================================================= | |
779 | void IntAna_QuadQuadGeo::Perform( const gp_Pln& P | |
780 | ,const gp_Sphere& S) | |
781 | { | |
782 | ||
783 | done = Standard_False; | |
784 | Standard_Real A,B,C,D,dist, radius; | |
785 | Standard_Real X,Y,Z; | |
786 | ||
787 | nbint = 0; | |
788 | // debug JAG : on met typeres = IntAna_Empty par defaut... | |
789 | typeres = IntAna_Empty; | |
790 | ||
791 | P.Coefficients(A,B,C,D); | |
792 | S.Location().Coord(X,Y,Z); | |
793 | radius = S.Radius(); | |
794 | ||
795 | dist = A * X + B * Y + C * Z + D; | |
796 | ||
797 | if (Abs( Abs(dist) - radius) < Epsilon(radius)) { | |
798 | // on a une seule solution : le point projection du centre de la sphere | |
799 | // sur le plan | |
800 | nbint = 1; | |
801 | typeres = IntAna_Point; | |
802 | pt1.SetCoord(X - dist*A, Y - dist*B, Z - dist*C); | |
803 | } | |
804 | else if (Abs(dist) < radius) { | |
805 | // on a un cercle solution | |
806 | nbint = 1; | |
807 | typeres = IntAna_Circle; | |
808 | pt1.SetCoord(X - dist*A, Y - dist*B, Z - dist*C); | |
809 | dir1 = P.Axis().Direction(); | |
810 | if(P.Direct()==Standard_False) dir1.Reverse(); | |
811 | dir2 = P.Position().XDirection(); | |
812 | param1 = Sqrt(radius*radius - dist*dist); | |
813 | } | |
814 | param2bis=0.0; //-- pour eviter param2bis not used .... | |
815 | done = Standard_True; | |
816 | } | |
817 | ||
818 | //======================================================================= | |
819 | //function : IntAna_QuadQuadGeo | |
820 | //purpose : Cylinder - Cylinder | |
821 | //======================================================================= | |
822 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo(const gp_Cylinder& Cyl1, | |
823 | const gp_Cylinder& Cyl2, | |
824 | const Standard_Real Tol) | |
825 | : done(Standard_False), | |
826 | nbint(0), | |
827 | typeres(IntAna_Empty), | |
828 | pt1(0,0,0), | |
829 | pt2(0,0,0), | |
830 | param1(0), | |
831 | param2(0), | |
832 | param1bis(0), | |
833 | param2bis(0), | |
834 | myCommonGen(Standard_False), | |
835 | myPChar(0,0,0) | |
836 | { | |
837 | InitTolerances(); | |
838 | Perform(Cyl1,Cyl2,Tol); | |
839 | } | |
840 | //======================================================================= | |
841 | //function : Perform | |
842 | //purpose : | |
843 | //======================================================================= | |
844 | void IntAna_QuadQuadGeo::Perform(const gp_Cylinder& Cyl1, | |
845 | const gp_Cylinder& Cyl2, | |
846 | const Standard_Real Tol) | |
847 | { | |
848 | done=Standard_True; | |
849 | //---------------------------- Parallel axes ------------------------- | |
850 | AxeOperator A1A2(Cyl1.Axis(),Cyl2.Axis()); | |
851 | Standard_Real R1=Cyl1.Radius(); | |
852 | Standard_Real R2=Cyl2.Radius(); | |
853 | Standard_Real RmR, RmR_Relative; | |
854 | RmR=(R1>R2)? (R1-R2) : (R2-R1); | |
855 | { | |
856 | Standard_Real Rmax, Rmin; | |
857 | Rmax=(R1>R2)? R1 : R2; | |
858 | Rmin=(R1>R2)? R2 : R1; | |
859 | RmR_Relative=RmR/Rmax; | |
860 | } | |
861 | ||
862 | Standard_Real DistA1A2=A1A2.Distance(); | |
863 | ||
864 | if(A1A2.Parallel()) { | |
865 | if(DistA1A2<=Tol) { | |
866 | if(RmR<=Tol) { | |
867 | typeres=IntAna_Same; | |
868 | } | |
869 | else { | |
870 | typeres=IntAna_Empty; | |
871 | } | |
872 | } | |
873 | else { //-- DistA1A2 > Tol | |
874 | gp_Pnt P1=Cyl1.Location(); | |
875 | gp_Pnt P2t=Cyl2.Location(); | |
876 | gp_Pnt P2; | |
877 | //-- P2t is projected on the plane (P1,DirCylX,DirCylY) | |
878 | gp_Dir DirCyl = Cyl1.Position().Direction(); | |
879 | Standard_Real ProjP2OnDirCyl1=gp_Vec(DirCyl).Dot(gp_Vec(P1,P2t)); | |
880 | ||
881 | P2.SetCoord( P2t.X() - ProjP2OnDirCyl1*DirCyl.X() | |
882 | ,P2t.Y() - ProjP2OnDirCyl1*DirCyl.Y() | |
883 | ,P2t.Z() - ProjP2OnDirCyl1*DirCyl.Z()); | |
884 | //-- | |
885 | Standard_Real R1pR2=R1+R2; | |
886 | if(DistA1A2>(R1pR2+Tol)) { | |
887 | typeres=IntAna_Empty; | |
888 | nbint=0; | |
889 | } | |
890 | else if(DistA1A2>(R1pR2)) { | |
891 | //-- 1 Tangent line -------------------------------------OK | |
892 | typeres=IntAna_Line; | |
893 | ||
894 | nbint=1; | |
895 | dir1=DirCyl; | |
896 | Standard_Real R1_R1pR2=R1/R1pR2; | |
897 | pt1.SetCoord( P1.X() + R1_R1pR2 * (P2.X()-P1.X()) | |
898 | ,P1.Y() + R1_R1pR2 * (P2.Y()-P1.Y()) | |
899 | ,P1.Z() + R1_R1pR2 * (P2.Z()-P1.Z())); | |
900 | ||
901 | } | |
902 | else if(DistA1A2>RmR) { | |
903 | //-- 2 lines ---------------------------------------------OK | |
904 | typeres=IntAna_Line; | |
905 | nbint=2; | |
906 | dir1=DirCyl; | |
907 | gp_Vec P1P2(P1,P2); | |
908 | gp_Dir DirA1A2=gp_Dir(P1P2); | |
909 | gp_Dir Ortho_dir1_P1P2 = dir1.Crossed(DirA1A2); | |
910 | dir2=dir1; | |
911 | Standard_Real Alpha=0.5*(R1*R1-R2*R2+DistA1A2*DistA1A2)/(DistA1A2); | |
912 | ||
913 | // Standard_Real Beta = Sqrt(R1*R1-Alpha*Alpha); | |
914 | Standard_Real anSqrtArg = R1*R1-Alpha*Alpha; | |
915 | Standard_Real Beta = (anSqrtArg > 0.) ? Sqrt(anSqrtArg) : 0.; | |
916 | ||
917 | if((Beta+Beta)<Tol) { | |
918 | nbint=1; | |
919 | pt1.SetCoord( P1.X() + Alpha*DirA1A2.X() | |
920 | ,P1.Y() + Alpha*DirA1A2.Y() | |
921 | ,P1.Z() + Alpha*DirA1A2.Z()); | |
922 | } | |
923 | else { | |
924 | pt1.SetCoord( P1.X() + Alpha*DirA1A2.X() + Beta*Ortho_dir1_P1P2.X() | |
925 | ,P1.Y() + Alpha*DirA1A2.Y() + Beta*Ortho_dir1_P1P2.Y() | |
926 | ,P1.Z() + Alpha*DirA1A2.Z() + Beta*Ortho_dir1_P1P2.Z() ); | |
927 | ||
928 | pt2.SetCoord( P1.X() + Alpha*DirA1A2.X() - Beta*Ortho_dir1_P1P2.X() | |
929 | ,P1.Y() + Alpha*DirA1A2.Y() - Beta*Ortho_dir1_P1P2.Y() | |
930 | ,P1.Z() + Alpha*DirA1A2.Z() - Beta*Ortho_dir1_P1P2.Z()); | |
931 | } | |
932 | } | |
933 | else if(DistA1A2>(RmR-Tol)) { | |
934 | //-- 1 Tangent ------------------------------------------OK | |
935 | typeres=IntAna_Line; | |
936 | nbint=1; | |
937 | dir1=DirCyl; | |
938 | Standard_Real R1_RmR=R1/RmR; | |
939 | ||
940 | if(R1 < R2) R1_RmR = -R1_RmR; | |
941 | ||
942 | pt1.SetCoord( P1.X() + R1_RmR * (P2.X()-P1.X()) | |
943 | ,P1.Y() + R1_RmR * (P2.Y()-P1.Y()) | |
944 | ,P1.Z() + R1_RmR * (P2.Z()-P1.Z())); | |
945 | } | |
946 | else { | |
947 | nbint=0; | |
948 | typeres=IntAna_Empty; | |
949 | } | |
950 | } | |
951 | } | |
952 | else { //-- No Parallel Axis ---------------------------------OK | |
953 | if((RmR_Relative<=myEPSILON_CYLINDER_DELTA_RADIUS) | |
954 | && (DistA1A2 <= myEPSILON_CYLINDER_DELTA_DISTANCE)) { | |
955 | //-- PI/2 between the two axis and Intersection | |
956 | //-- and identical radius | |
957 | typeres=IntAna_Ellipse; | |
958 | nbint=2; | |
959 | gp_Dir DirCyl1=Cyl1.Position().Direction(); | |
960 | gp_Dir DirCyl2=Cyl2.Position().Direction(); | |
961 | pt1=pt2=A1A2.PtIntersect(); | |
962 | ||
963 | Standard_Real A=DirCyl1.Angle(DirCyl2); | |
964 | Standard_Real B; | |
c6541a0c | 965 | B=Abs(Sin(0.5*(M_PI-A))); |
7fd59977 | 966 | A=Abs(Sin(0.5*A)); |
967 | ||
968 | if(A==0.0 || B==0.0) { | |
969 | typeres=IntAna_Same; | |
970 | return; | |
971 | } | |
972 | ||
973 | ||
974 | gp_Vec dircyl1(DirCyl1);gp_Vec dircyl2(DirCyl2); | |
975 | dir1 = gp_Dir(dircyl1.Added(dircyl2)); | |
976 | dir2 = gp_Dir(dircyl1.Subtracted(dircyl2)); | |
977 | ||
978 | param2 = Cyl1.Radius() / A; | |
979 | param1 = Cyl1.Radius() / B; | |
980 | param2bis= param1bis = Cyl1.Radius(); | |
981 | if(param1 < param1bis) { | |
982 | A=param1; param1=param1bis; param1bis=A; | |
983 | } | |
984 | if(param2 < param2bis) { | |
985 | A=param2; param2=param2bis; param2bis=A; | |
986 | } | |
987 | } | |
988 | else { | |
989 | if(Abs(DistA1A2-Cyl1.Radius()-Cyl2.Radius())<Tol) { | |
990 | typeres = IntAna_Point; | |
991 | Standard_Real d,p1,p2; | |
992 | ||
993 | gp_Dir D1 = Cyl1.Axis().Direction(); | |
994 | gp_Dir D2 = Cyl2.Axis().Direction(); | |
995 | A1A2.Distance(d,p1,p2); | |
996 | gp_Pnt P = Cyl1.Axis().Location(); | |
997 | gp_Pnt P1(P.X() - p1*D1.X(), | |
998 | P.Y() - p1*D1.Y(), | |
999 | P.Z() - p1*D1.Z()); | |
1000 | P = Cyl2.Axis().Location(); | |
1001 | gp_Pnt P2(P.X() - p2*D2.X(), | |
1002 | P.Y() - p2*D2.Y(), | |
1003 | P.Z() - p2*D2.Z()); | |
1004 | gp_Vec P1P2(P1,P2); | |
1005 | D1=gp_Dir(P1P2); | |
1006 | p1=Cyl1.Radius(); | |
1007 | pt1.SetCoord(P1.X() + p1*D1.X(), | |
1008 | P1.Y() + p1*D1.Y(), | |
1009 | P1.Z() + p1*D1.Z()); | |
1010 | nbint = 1; | |
1011 | } | |
1012 | else { | |
1013 | typeres=IntAna_NoGeometricSolution; | |
1014 | } | |
1015 | } | |
1016 | } | |
1017 | } | |
1018 | //======================================================================= | |
1019 | //function : IntAna_QuadQuadGeo | |
1020 | //purpose : Cylinder - Cone | |
1021 | //======================================================================= | |
1022 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo(const gp_Cylinder& Cyl, | |
1023 | const gp_Cone& Con, | |
1024 | const Standard_Real Tol) | |
1025 | : done(Standard_False), | |
1026 | nbint(0), | |
1027 | typeres(IntAna_Empty), | |
1028 | pt1(0,0,0), | |
1029 | pt2(0,0,0), | |
1030 | param1(0), | |
1031 | param2(0), | |
1032 | param1bis(0), | |
1033 | param2bis(0), | |
1034 | myCommonGen(Standard_False), | |
1035 | myPChar(0,0,0) | |
1036 | { | |
1037 | InitTolerances(); | |
1038 | Perform(Cyl,Con,Tol); | |
1039 | } | |
1040 | //======================================================================= | |
1041 | //function : Perform | |
1042 | //purpose : | |
1043 | //======================================================================= | |
1044 | void IntAna_QuadQuadGeo::Perform(const gp_Cylinder& Cyl, | |
1045 | const gp_Cone& Con, | |
1046 | const Standard_Real ) | |
1047 | { | |
1048 | done=Standard_True; | |
1049 | AxeOperator A1A2(Cyl.Axis(),Con.Axis()); | |
1050 | if(A1A2.Same()) { | |
1051 | gp_Pnt Pt=Con.Apex(); | |
1052 | Standard_Real dist=Cyl.Radius()/(Tan(Con.SemiAngle())); | |
1053 | gp_Dir dir=Cyl.Position().Direction(); | |
1054 | pt1.SetCoord( Pt.X() + dist*dir.X() | |
1055 | ,Pt.Y() + dist*dir.Y() | |
1056 | ,Pt.Z() + dist*dir.Z()); | |
1057 | pt2.SetCoord( Pt.X() - dist*dir.X() | |
1058 | ,Pt.Y() - dist*dir.Y() | |
1059 | ,Pt.Z() - dist*dir.Z()); | |
1060 | dir1=dir2=dir; | |
1061 | param1=param2=Cyl.Radius(); | |
1062 | nbint=2; | |
1063 | typeres=IntAna_Circle; | |
1064 | ||
1065 | } | |
1066 | else { | |
1067 | typeres=IntAna_NoGeometricSolution; | |
1068 | } | |
1069 | } | |
1070 | //======================================================================= | |
1071 | //function : | |
1072 | //purpose : Cylinder - Sphere | |
1073 | //======================================================================= | |
1074 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo(const gp_Cylinder& Cyl, | |
1075 | const gp_Sphere& Sph, | |
1076 | const Standard_Real Tol) | |
1077 | : done(Standard_False), | |
1078 | nbint(0), | |
1079 | typeres(IntAna_Empty), | |
1080 | pt1(0,0,0), | |
1081 | pt2(0,0,0), | |
1082 | param1(0), | |
1083 | param2(0), | |
1084 | param1bis(0), | |
1085 | param2bis(0), | |
1086 | myCommonGen(Standard_False), | |
1087 | myPChar(0,0,0) | |
1088 | { | |
1089 | InitTolerances(); | |
1090 | Perform(Cyl,Sph,Tol); | |
1091 | } | |
1092 | //======================================================================= | |
1093 | //function : Perform | |
1094 | //purpose : | |
1095 | //======================================================================= | |
1096 | void IntAna_QuadQuadGeo::Perform( const gp_Cylinder& Cyl | |
1097 | ,const gp_Sphere& Sph | |
1098 | ,const Standard_Real) | |
1099 | { | |
1100 | done=Standard_True; | |
1101 | gp_Pnt Pt=Sph.Location(); | |
1102 | AxeOperator A1A2(Cyl.Axis(),Sph.Position().Axis()); | |
1103 | if((A1A2.Intersect() && Pt.Distance(A1A2.PtIntersect())==0.0 ) | |
1104 | || (A1A2.Same())) { | |
1105 | if(Sph.Radius() < Cyl.Radius()) { | |
1106 | typeres = IntAna_Empty; | |
1107 | } | |
1108 | else { | |
1109 | Standard_Real dist=Sqrt( Sph.Radius() * Sph.Radius() - Cyl.Radius() * Cyl.Radius() ); | |
1110 | gp_Dir dir=Cyl.Position().Direction(); | |
1111 | dir1 = dir2 = dir; | |
1112 | typeres=IntAna_Circle; | |
1113 | pt1.SetCoord( Pt.X() + dist*dir.X() | |
1114 | ,Pt.Y() + dist*dir.Y() | |
1115 | ,Pt.Z() + dist*dir.Z()); | |
1116 | nbint=1; | |
1117 | param1 = Cyl.Radius(); | |
1118 | if(dist>RealEpsilon()) { | |
1119 | pt2.SetCoord( Pt.X() - dist*dir.X() | |
1120 | ,Pt.Y() - dist*dir.Y() | |
1121 | ,Pt.Z() - dist*dir.Z()); | |
1122 | param2=Cyl.Radius(); | |
1123 | nbint=2; | |
1124 | } | |
1125 | } | |
1126 | } | |
1127 | else { | |
1128 | typeres=IntAna_NoGeometricSolution; | |
1129 | } | |
1130 | } | |
1131 | ||
1132 | //======================================================================= | |
1133 | //function : IntAna_QuadQuadGeo | |
1134 | //purpose : Cone - Cone | |
1135 | //======================================================================= | |
1136 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo(const gp_Cone& Con1, | |
1137 | const gp_Cone& Con2, | |
1138 | const Standard_Real Tol) | |
1139 | : done(Standard_False), | |
1140 | nbint(0), | |
1141 | typeres(IntAna_Empty), | |
1142 | pt1(0,0,0), | |
1143 | pt2(0,0,0), | |
1144 | param1(0), | |
1145 | param2(0), | |
1146 | param1bis(0), | |
1147 | param2bis(0), | |
1148 | myCommonGen(Standard_False), | |
1149 | myPChar(0,0,0) | |
1150 | { | |
1151 | InitTolerances(); | |
1152 | Perform(Con1,Con2,Tol); | |
1153 | } | |
1154 | // | |
1155 | //======================================================================= | |
1156 | //function : Perform | |
1157 | //purpose : | |
1158 | //======================================================================= | |
1159 | void IntAna_QuadQuadGeo::Perform(const gp_Cone& Con1, | |
1160 | const gp_Cone& Con2, | |
1161 | const Standard_Real Tol) | |
1162 | { | |
1163 | done=Standard_True; | |
1164 | // | |
1165 | Standard_Real tg1, tg2, aDA1A2, aTol2; | |
1166 | gp_Pnt aPApex1, aPApex2; | |
4bd102b8 | 1167 | |
1168 | Standard_Real TOL_APEX_CONF = 1.e-10; | |
1169 | ||
7fd59977 | 1170 | // |
1171 | tg1=Tan(Con1.SemiAngle()); | |
1172 | tg2=Tan(Con2.SemiAngle()); | |
1173 | ||
1174 | if((tg1 * tg2) < 0.) { | |
1175 | tg2 = -tg2; | |
1176 | } | |
1177 | // | |
7fd59977 | 1178 | aTol2=Tol*Tol; |
1179 | aPApex1=Con1.Apex(); | |
1180 | aPApex2=Con2.Apex(); | |
1181 | aDA1A2=aPApex1.SquareDistance(aPApex2); | |
7fd59977 | 1182 | // |
1183 | AxeOperator A1A2(Con1.Axis(),Con2.Axis()); | |
1184 | // | |
1185 | // 1 | |
1186 | if(A1A2.Same()) { | |
1187 | //-- two circles | |
1188 | Standard_Real x; | |
1189 | gp_Pnt P=Con1.Apex(); | |
1190 | gp_Dir D=Con1.Position().Direction(); | |
1191 | Standard_Real d=gp_Vec(D).Dot(gp_Vec(P,Con2.Apex())); | |
1192 | ||
1193 | if(Abs(tg1-tg2)>myEPSILON_ANGLE_CONE) { | |
4bd102b8 | 1194 | if (fabs(d) < TOL_APEX_CONF) { |
1195 | typeres = IntAna_Point; | |
1196 | nbint = 1; | |
1197 | pt1 = P; | |
1198 | return; | |
1199 | } | |
7fd59977 | 1200 | x=(d*tg2)/(tg1+tg2); |
1201 | pt1.SetCoord( P.X() + x*D.X() | |
1202 | ,P.Y() + x*D.Y() | |
1203 | ,P.Z() + x*D.Z()); | |
1204 | param1=Abs(x*tg1); | |
1205 | ||
1206 | x=(d*tg2)/(tg2-tg1); | |
1207 | pt2.SetCoord( P.X() + x*D.X() | |
1208 | ,P.Y() + x*D.Y() | |
1209 | ,P.Z() + x*D.Z()); | |
1210 | param2=Abs(x*tg1); | |
1211 | dir1 = dir2 = D; | |
1212 | nbint=2; | |
1213 | typeres=IntAna_Circle; | |
1214 | } | |
1215 | else { | |
4bd102b8 | 1216 | if (fabs(d) < TOL_APEX_CONF) { |
7fd59977 | 1217 | typeres=IntAna_Same; |
1218 | } | |
1219 | else { | |
1220 | typeres=IntAna_Circle; | |
1221 | nbint=1; | |
1222 | x=d*0.5; | |
1223 | pt1.SetCoord( P.X() + x*D.X() | |
1224 | ,P.Y() + x*D.Y() | |
1225 | ,P.Z() + x*D.Z()); | |
1226 | param1 = Abs(x * tg1); | |
1227 | dir1 = D; | |
1228 | } | |
1229 | } | |
1230 | } //-- fin A1A2.Same | |
1231 | // 2 | |
1232 | else if((Abs(tg1-tg2)<myEPSILON_ANGLE_CONE) && (A1A2.Parallel())) { | |
1233 | //-- voir AnVer12mai98 | |
1234 | Standard_Real DistA1A2=A1A2.Distance(); | |
1235 | gp_Dir DA1=Con1.Position().Direction(); | |
1236 | gp_Vec O1O2(Con1.Apex(),Con2.Apex()); | |
1237 | Standard_Real O1O2_DA1=gp_Vec(DA1).Dot(O1O2); | |
1238 | ||
1239 | gp_Vec O1_Proj_A2(O1O2.X()-O1O2_DA1*DA1.X(), | |
1240 | O1O2.Y()-O1O2_DA1*DA1.Y(), | |
1241 | O1O2.Z()-O1O2_DA1*DA1.Z()); | |
1242 | gp_Dir DB1=gp_Dir(O1_Proj_A2); | |
1243 | ||
1244 | Standard_Real yO1O2=O1O2.Dot(gp_Vec(DA1)); | |
1245 | Standard_Real ABSTG1 = Abs(tg1); | |
1246 | Standard_Real X2 = (DistA1A2/ABSTG1 - yO1O2)*0.5; | |
1247 | Standard_Real X1 = X2+yO1O2; | |
1248 | ||
1249 | gp_Pnt P1(Con1.Apex().X() + X1*( DA1.X() + ABSTG1*DB1.X()), | |
1250 | Con1.Apex().Y() + X1*( DA1.Y() + ABSTG1*DB1.Y()), | |
1251 | Con1.Apex().Z() + X1*( DA1.Z() + ABSTG1*DB1.Z())); | |
1252 | ||
1253 | gp_Pnt MO1O2(0.5*(Con1.Apex().X()+Con2.Apex().X()), | |
1254 | 0.5*(Con1.Apex().Y()+Con2.Apex().Y()), | |
1255 | 0.5*(Con1.Apex().Z()+Con2.Apex().Z())); | |
1256 | gp_Vec P1MO1O2(P1,MO1O2); | |
1257 | ||
1258 | gp_Dir DA1_X_DB1=DA1.Crossed(DB1); | |
1259 | gp_Dir OrthoPln = DA1_X_DB1.Crossed(gp_Dir(P1MO1O2)); | |
1260 | ||
1261 | IntAna_QuadQuadGeo INTER_QUAD_PLN(gp_Pln(P1,OrthoPln),Con1,Tol,Tol); | |
1262 | if(INTER_QUAD_PLN.IsDone()) { | |
1263 | switch(INTER_QUAD_PLN.TypeInter()) { | |
1264 | case IntAna_Ellipse: { | |
1265 | typeres=IntAna_Ellipse; | |
1266 | gp_Elips E=INTER_QUAD_PLN.Ellipse(1); | |
1267 | pt1 = E.Location(); | |
1268 | dir1 = E.Position().Direction(); | |
1269 | dir2 = E.Position().XDirection(); | |
1270 | param1 = E.MajorRadius(); | |
1271 | param1bis = E.MinorRadius(); | |
1272 | nbint = 1; | |
1273 | break; | |
1274 | } | |
1275 | case IntAna_Circle: { | |
1276 | typeres=IntAna_Circle; | |
1277 | gp_Circ C=INTER_QUAD_PLN.Circle(1); | |
1278 | pt1 = C.Location(); | |
1279 | dir1 = C.Position().XDirection(); | |
1280 | dir2 = C.Position().YDirection(); | |
1281 | param1 = C.Radius(); | |
1282 | nbint = 1; | |
1283 | break; | |
1284 | } | |
1285 | case IntAna_Hyperbola: { | |
1286 | typeres=IntAna_Hyperbola; | |
1287 | gp_Hypr H=INTER_QUAD_PLN.Hyperbola(1); | |
1288 | pt1 = pt2 = H.Location(); | |
1289 | dir1 = H.Position().Direction(); | |
1290 | dir2 = H.Position().XDirection(); | |
1291 | param1 = param2 = H.MajorRadius(); | |
1292 | param1bis = param2bis = H.MinorRadius(); | |
1293 | nbint = 2; | |
1294 | break; | |
1295 | } | |
1296 | case IntAna_Line: { | |
1297 | typeres=IntAna_Line; | |
1298 | gp_Lin H=INTER_QUAD_PLN.Line(1); | |
1299 | pt1 = pt2 = H.Location(); | |
1300 | dir1 = dir2 = H.Position().Direction(); | |
1301 | param1 = param2 = 0.0; | |
1302 | param1bis = param2bis = 0.0; | |
1303 | nbint = 2; | |
1304 | break; | |
1305 | } | |
1306 | default: | |
1307 | typeres=IntAna_NoGeometricSolution; | |
1308 | } | |
1309 | } | |
1310 | }// else if((Abs(tg1-tg2)<EPSILON_ANGLE_CONE) && (A1A2.Parallel())) | |
7fd59977 | 1311 | // 3 |
1312 | else if (aDA1A2<aTol2) { | |
7fd59977 | 1313 | // |
1314 | // When apices are coinsided there can be 3 possible cases | |
1315 | // 3.1 - empty solution (iRet=0) | |
1316 | // 3.2 - one line when cone1 touches cone2 (iRet=1) | |
1317 | // 3.3 - two lines when cone1 intersects cone2 (iRet=2) | |
1318 | // | |
1319 | Standard_Integer iRet; | |
1320 | Standard_Real aGamma, aBeta1, aBeta2; | |
1321 | Standard_Real aD1, aR1, aTgBeta1, aTgBeta2, aHalfPI; | |
1322 | Standard_Real aCosGamma, aSinGamma, aDx, aR2, aRD2, aD2; | |
1323 | gp_Pnt2d aP0, aPA1, aP1, aPA2; | |
1324 | gp_Vec2d aVAx2; | |
1325 | gp_Ax1 aAx1, aAx2; | |
1326 | // | |
1327 | // Preliminary analysis. Determination of iRet | |
1328 | // | |
1329 | iRet=0; | |
c6541a0c | 1330 | aHalfPI=0.5*M_PI; |
7fd59977 | 1331 | aD1=1.; |
1332 | aPA1.SetCoord(aD1, 0.); | |
1333 | aP0.SetCoord(0., 0.); | |
1334 | // | |
1335 | aAx1=Con1.Axis(); | |
1336 | aAx2=Con2.Axis(); | |
1337 | aGamma=aAx1.Angle(aAx2); | |
1338 | if (aGamma>aHalfPI){ | |
c6541a0c | 1339 | aGamma=M_PI-aGamma; |
7fd59977 | 1340 | } |
1341 | aCosGamma=Cos(aGamma); | |
1342 | aSinGamma=Sin(aGamma); | |
1343 | // | |
1344 | aBeta1=Con1.SemiAngle(); | |
1345 | aTgBeta1=Tan(aBeta1); | |
1346 | aTgBeta1=Abs(aTgBeta1); | |
1347 | // | |
1348 | aBeta2=Con2.SemiAngle(); | |
1349 | aTgBeta2=Tan(aBeta2); | |
1350 | aTgBeta2=Abs(aTgBeta2); | |
1351 | // | |
1352 | aR1=aD1*aTgBeta1; | |
1353 | aP1.SetCoord(aD1, aR1); | |
1354 | // | |
1355 | // PA2 | |
1356 | aVAx2.SetCoord(aCosGamma, aSinGamma); | |
1357 | gp_Dir2d aDAx2(aVAx2); | |
1358 | gp_Lin2d aLAx2(aP0, aDAx2); | |
1359 | // | |
1360 | gp_Vec2d aV(aP0, aP1); | |
1361 | aDx=aVAx2.Dot(aV); | |
1362 | aPA2=aP0.Translated(aDx*aDAx2); | |
1363 | // | |
1364 | // aR2 | |
1365 | aDx=aPA2.Distance(aP0); | |
1366 | aR2=aDx*aTgBeta2; | |
1367 | // | |
1368 | // aRD2 | |
1369 | aRD2=aPA2.Distance(aP1); | |
1370 | // | |
1371 | if (aRD2>(aR2+Tol)) { | |
1372 | iRet=0; | |
7fd59977 | 1373 | typeres=IntAna_Empty; //nothing |
4101383e | 1374 | return; |
7fd59977 | 1375 | } |
1376 | // | |
1377 | iRet=1; //touch case => 1 line | |
1378 | if (aRD2<(aR2-Tol)) { | |
1379 | iRet=2;//intersection => couple of lines | |
1380 | } | |
1381 | // | |
1382 | // Finding the solution in 3D | |
1383 | // | |
1384 | Standard_Real aDa; | |
1385 | gp_Pnt aQApex1, aQA1, aQA2, aQX, aQX1, aQX2; | |
1386 | gp_Dir aD3Ax1, aD3Ax2; | |
1387 | gp_Lin aLin; | |
1388 | IntAna_QuadQuadGeo aIntr; | |
1389 | // | |
1390 | aQApex1=Con1.Apex(); | |
1391 | aD3Ax1=aAx1.Direction(); | |
1392 | aQA1.SetCoord(aQApex1.X()+aD1*aD3Ax1.X(), | |
1393 | aQApex1.Y()+aD1*aD3Ax1.Y(), | |
1394 | aQApex1.Z()+aD1*aD3Ax1.Z()); | |
1395 | // | |
1396 | aDx=aD3Ax1.Dot(aAx2.Direction()); | |
1397 | if (aDx<0.) { | |
1398 | aAx2.Reverse(); | |
1399 | } | |
1400 | aD3Ax2=aAx2.Direction(); | |
1401 | // | |
1402 | aD2=aD1*sqrt((1.+aTgBeta1*aTgBeta1)/(1.+aTgBeta2*aTgBeta2)); | |
1403 | // | |
1404 | aQA2.SetCoord(aQApex1.X()+aD2*aD3Ax2.X(), | |
1405 | aQApex1.Y()+aD2*aD3Ax2.Y(), | |
1406 | aQApex1.Z()+aD2*aD3Ax2.Z()); | |
1407 | // | |
1408 | gp_Pln aPln1(aQA1, aD3Ax1); | |
1409 | gp_Pln aPln2(aQA2, aD3Ax2); | |
1410 | // | |
1411 | aIntr.Perform(aPln1, aPln2, Tol, Tol); | |
1412 | if (!aIntr.IsDone()) { | |
1413 | iRet=-1; // just in case. it must not be so | |
1414 | typeres=IntAna_NoGeometricSolution; | |
1415 | return; | |
1416 | } | |
1417 | // | |
1418 | aLin=aIntr.Line(1); | |
1419 | const gp_Dir& aDLin=aLin.Direction(); | |
1420 | gp_Vec aVLin(aDLin); | |
1421 | gp_Pnt aOrig=aLin.Location(); | |
1422 | gp_Vec aVr(aQA1, aOrig); | |
1423 | aDx=aVLin.Dot(aVr); | |
1424 | aQX=aOrig.Translated(aDx*aVLin); | |
1425 | // | |
1426 | // Final part | |
1427 | // | |
1428 | typeres=IntAna_Line; | |
1429 | // | |
1430 | param1=0.; | |
1431 | param2 =0.; | |
1432 | param1bis=0.; | |
1433 | param2bis=0.; | |
1434 | // | |
1435 | if (iRet==1) { | |
1436 | // one line | |
1437 | nbint=1; | |
1438 | pt1=aQApex1; | |
1439 | gp_Vec aVX(aQApex1, aQX); | |
1440 | dir1=gp_Dir(aVX); | |
7fd59977 | 1441 | } |
1442 | ||
1443 | else {//iRet=2 | |
1444 | // two lines | |
1445 | nbint=2; | |
1446 | aDa=aQA1.Distance(aQX); | |
1447 | aDx=sqrt(aR1*aR1-aDa*aDa); | |
1448 | aQX1=aQX.Translated(aDx*aVLin); | |
1449 | aQX2=aQX.Translated(-aDx*aVLin); | |
1450 | // | |
1451 | pt1=aQApex1; | |
1452 | pt2=aQApex1; | |
1453 | gp_Vec aVX1(aQApex1, aQX1); | |
1454 | dir1=gp_Dir(aVX1); | |
1455 | gp_Vec aVX2(aQApex1, aQX2); | |
1456 | dir2=gp_Dir(aVX2); | |
7fd59977 | 1457 | } |
1458 | } //else if (aDA1A2<aTol2) { | |
7fd59977 | 1459 | //Case when cones have common generatrix |
1460 | else if(A1A2.Intersect()) { | |
1461 | //Check if apex of one cone belongs another one | |
1462 | Standard_Real u, v, tol2 = Tol*Tol; | |
1463 | ElSLib::Parameters(Con2, aPApex1, u, v); | |
1464 | gp_Pnt p = ElSLib::Value(u, v, Con2); | |
1465 | if(aPApex1.SquareDistance(p) > tol2) { | |
1466 | typeres=IntAna_NoGeometricSolution; | |
1467 | return; | |
1468 | } | |
1469 | // | |
1470 | ElSLib::Parameters(Con1, aPApex2, u, v); | |
1471 | p = ElSLib::Value(u, v, Con1); | |
1472 | if(aPApex2.SquareDistance(p) > tol2) { | |
1473 | typeres=IntAna_NoGeometricSolution; | |
1474 | return; | |
1475 | } | |
1476 | ||
1477 | //Cones have a common generatrix passing through apexes | |
1478 | myCommonGen = Standard_True; | |
1479 | ||
1480 | //common generatrix of cones | |
1481 | gp_Lin aGen(aPApex1, gp_Dir(gp_Vec(aPApex1, aPApex2))); | |
1482 | ||
1483 | //Intersection point of axes | |
1484 | gp_Pnt aPAxeInt = A1A2.PtIntersect(); | |
1485 | ||
1486 | //Characteristic point of intersection curve | |
1487 | u = ElCLib::Parameter(aGen, aPAxeInt); | |
1488 | myPChar = ElCLib::Value(u, aGen); | |
1489 | ||
1490 | ||
1491 | //Other generatrixes of cones laying in maximal plane | |
c6541a0c D |
1492 | gp_Lin aGen1 = aGen.Rotated(Con1.Axis(), M_PI); |
1493 | gp_Lin aGen2 = aGen.Rotated(Con2.Axis(), M_PI); | |
7fd59977 | 1494 | // |
1495 | //Intersection point of generatrixes | |
1496 | gp_Dir aN; //solution plane normal | |
1497 | gp_Dir aD1 = aGen1.Direction(); | |
1498 | ||
1499 | gp_Dir aD2(aD1.Crossed(aGen.Direction())); | |
1500 | ||
1501 | if(aD1.IsParallel(aGen2.Direction(), Precision::Angular())) { | |
1502 | aN = aD1.Crossed(aD2); | |
1503 | } | |
1504 | else if(aGen1.SquareDistance(aGen2) > tol2) { | |
1505 | //Something wrong ??? | |
1506 | typeres=IntAna_NoGeometricSolution; | |
1507 | return; | |
1508 | } | |
1509 | else { | |
1510 | gp_Dir D1 = aGen1.Position().Direction(); | |
1511 | gp_Dir D2 = aGen2.Position().Direction(); | |
1512 | gp_Pnt O1 = aGen1.Location(); | |
1513 | gp_Pnt O2 = aGen2.Location(); | |
1514 | Standard_Real D1DotD2 = D1.Dot(D2); | |
1515 | Standard_Real aSin = 1.-D1DotD2*D1DotD2; | |
1516 | gp_Vec O1O2 (O1,O2); | |
1517 | Standard_Real U2 = (D1.XYZ()*(O1O2.Dot(D1))-(O1O2.XYZ())).Dot(D2.XYZ()); | |
1518 | U2 /= aSin; | |
1519 | gp_Pnt aPGint(ElCLib::Value(U2, aGen2)); | |
1520 | ||
1521 | aD1 = gp_Dir(gp_Vec(aPGint, myPChar)); | |
1522 | aN = aD1.Crossed(aD2); | |
1523 | } | |
1524 | //Plane that must contain intersection curves | |
1525 | gp_Pln anIntPln(myPChar, aN); | |
1526 | ||
1527 | IntAna_QuadQuadGeo INTER_QUAD_PLN(anIntPln,Con1,Tol,Tol); | |
1528 | ||
1529 | if(INTER_QUAD_PLN.IsDone()) { | |
1530 | switch(INTER_QUAD_PLN.TypeInter()) { | |
1531 | case IntAna_Ellipse: { | |
1532 | typeres=IntAna_Ellipse; | |
1533 | gp_Elips E=INTER_QUAD_PLN.Ellipse(1); | |
1534 | pt1 = E.Location(); | |
1535 | dir1 = E.Position().Direction(); | |
1536 | dir2 = E.Position().XDirection(); | |
1537 | param1 = E.MajorRadius(); | |
1538 | param1bis = E.MinorRadius(); | |
1539 | nbint = 1; | |
1540 | break; | |
1541 | } | |
1542 | case IntAna_Circle: { | |
1543 | typeres=IntAna_Circle; | |
1544 | gp_Circ C=INTER_QUAD_PLN.Circle(1); | |
1545 | pt1 = C.Location(); | |
1546 | dir1 = C.Position().XDirection(); | |
1547 | dir2 = C.Position().YDirection(); | |
1548 | param1 = C.Radius(); | |
1549 | nbint = 1; | |
1550 | break; | |
1551 | } | |
1552 | case IntAna_Parabola: { | |
1553 | typeres=IntAna_Parabola; | |
1554 | gp_Parab Prb=INTER_QUAD_PLN.Parabola(1); | |
1555 | pt1 = Prb.Location(); | |
1556 | dir1 = Prb.Position().Direction(); | |
1557 | dir2 = Prb.Position().XDirection(); | |
1558 | param1 = Prb.Focal(); | |
1559 | nbint = 1; | |
1560 | break; | |
1561 | } | |
1562 | case IntAna_Hyperbola: { | |
1563 | typeres=IntAna_Hyperbola; | |
1564 | gp_Hypr H=INTER_QUAD_PLN.Hyperbola(1); | |
1565 | pt1 = pt2 = H.Location(); | |
1566 | dir1 = H.Position().Direction(); | |
1567 | dir2 = H.Position().XDirection(); | |
1568 | param1 = param2 = H.MajorRadius(); | |
1569 | param1bis = param2bis = H.MinorRadius(); | |
1570 | nbint = 2; | |
1571 | break; | |
1572 | } | |
1573 | default: | |
1574 | typeres=IntAna_NoGeometricSolution; | |
1575 | } | |
1576 | } | |
1577 | } | |
4101383e | 1578 | |
7fd59977 | 1579 | else { |
1580 | typeres=IntAna_NoGeometricSolution; | |
1581 | } | |
1582 | } | |
1583 | //======================================================================= | |
1584 | //function : IntAna_QuadQuadGeo | |
1585 | //purpose : Sphere - Cone | |
1586 | //======================================================================= | |
1587 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo(const gp_Sphere& Sph, | |
1588 | const gp_Cone& Con, | |
1589 | const Standard_Real Tol) | |
1590 | : done(Standard_False), | |
1591 | nbint(0), | |
1592 | typeres(IntAna_Empty), | |
1593 | pt1(0,0,0), | |
1594 | pt2(0,0,0), | |
1595 | param1(0), | |
1596 | param2(0), | |
1597 | param1bis(0), | |
1598 | param2bis(0), | |
1599 | myCommonGen(Standard_False), | |
1600 | myPChar(0,0,0) | |
1601 | { | |
1602 | InitTolerances(); | |
1603 | Perform(Sph,Con,Tol); | |
1604 | } | |
1605 | //======================================================================= | |
1606 | //function : Perform | |
1607 | //purpose : | |
1608 | //======================================================================= | |
1609 | void IntAna_QuadQuadGeo::Perform(const gp_Sphere& Sph, | |
1610 | const gp_Cone& Con, | |
1611 | const Standard_Real) | |
1612 | { | |
77088633 | 1613 | |
1614 | // | |
7fd59977 | 1615 | done=Standard_True; |
77088633 | 1616 | // |
7fd59977 | 1617 | AxeOperator A1A2(Con.Axis(),Sph.Position().Axis()); |
1618 | gp_Pnt Pt=Sph.Location(); | |
77088633 | 1619 | // |
7fd59977 | 1620 | if((A1A2.Intersect() && (Pt.Distance(A1A2.PtIntersect())==0.0)) |
1621 | || A1A2.Same()) { | |
1622 | gp_Pnt ConApex= Con.Apex(); | |
1623 | Standard_Real dApexSphCenter=Pt.Distance(ConApex); | |
1624 | gp_Dir ConDir; | |
1625 | if(dApexSphCenter>RealEpsilon()) { | |
1626 | ConDir = gp_Dir(gp_Vec(ConApex,Pt)); | |
1627 | } | |
1628 | else { | |
1629 | ConDir = Con.Position().Direction(); | |
1630 | } | |
1631 | ||
1632 | Standard_Real Rad=Sph.Radius(); | |
1633 | Standard_Real tga=Tan(Con.SemiAngle()); | |
1634 | ||
1635 | ||
1636 | //-- 2 circles | |
1637 | //-- x: Roots of (x**2 + y**2 = Rad**2) | |
1638 | //-- tga = y / (x+dApexSphCenter) | |
1639 | Standard_Real tgatga = tga * tga; | |
1640 | math_DirectPolynomialRoots Eq( 1.0+tgatga | |
1641 | ,2.0*tgatga*dApexSphCenter | |
1642 | ,-Rad*Rad + dApexSphCenter*dApexSphCenter*tgatga); | |
1643 | if(Eq.IsDone()) { | |
1644 | Standard_Integer nbsol=Eq.NbSolutions(); | |
1645 | if(nbsol==0) { | |
1646 | typeres=IntAna_Empty; | |
1647 | } | |
1648 | else { | |
1649 | typeres=IntAna_Circle; | |
1650 | if(nbsol>=1) { | |
1651 | Standard_Real x = Eq.Value(1); | |
1652 | Standard_Real dApexSphCenterpx = dApexSphCenter+x; | |
1653 | nbint=1; | |
1654 | pt1.SetCoord( ConApex.X() + (dApexSphCenterpx) * ConDir.X() | |
1655 | ,ConApex.Y() + (dApexSphCenterpx) * ConDir.Y() | |
1656 | ,ConApex.Z() + (dApexSphCenterpx) * ConDir.Z()); | |
1657 | param1 = tga * dApexSphCenterpx; | |
1658 | param1 = Abs(param1); | |
1659 | dir1 = ConDir; | |
1660 | if(param1<=myEPSILON_MINI_CIRCLE_RADIUS) { | |
1661 | typeres=IntAna_PointAndCircle; | |
1662 | param1=0.0; | |
1663 | } | |
1664 | } | |
1665 | if(nbsol>=2) { | |
1666 | Standard_Real x=Eq.Value(2); | |
1667 | Standard_Real dApexSphCenterpx = dApexSphCenter+x; | |
1668 | nbint=2; | |
1669 | pt2.SetCoord( ConApex.X() + (dApexSphCenterpx) * ConDir.X() | |
1670 | ,ConApex.Y() + (dApexSphCenterpx) * ConDir.Y() | |
1671 | ,ConApex.Z() + (dApexSphCenterpx) * ConDir.Z()); | |
1672 | param2 = tga * dApexSphCenterpx; | |
1673 | param2 = Abs(param2); | |
1674 | dir2=ConDir; | |
1675 | if(param2<=myEPSILON_MINI_CIRCLE_RADIUS) { | |
1676 | typeres=IntAna_PointAndCircle; | |
1677 | param2=0.0; | |
1678 | } | |
1679 | } | |
1680 | } | |
1681 | } | |
1682 | else { | |
1683 | done=Standard_False; | |
1684 | } | |
1685 | } | |
1686 | else { | |
1687 | typeres=IntAna_NoGeometricSolution; | |
1688 | } | |
1689 | } | |
1690 | ||
1691 | //======================================================================= | |
1692 | //function : IntAna_QuadQuadGeo | |
1693 | //purpose : Sphere - Sphere | |
1694 | //======================================================================= | |
1695 | IntAna_QuadQuadGeo::IntAna_QuadQuadGeo( const gp_Sphere& Sph1 | |
1696 | ,const gp_Sphere& Sph2 | |
1697 | ,const Standard_Real Tol) | |
1698 | : done(Standard_False), | |
1699 | nbint(0), | |
1700 | typeres(IntAna_Empty), | |
1701 | pt1(0,0,0), | |
1702 | pt2(0,0,0), | |
1703 | param1(0), | |
1704 | param2(0), | |
1705 | param1bis(0), | |
1706 | param2bis(0), | |
1707 | myCommonGen(Standard_False), | |
1708 | myPChar(0,0,0) | |
1709 | { | |
1710 | InitTolerances(); | |
1711 | Perform(Sph1,Sph2,Tol); | |
1712 | } | |
1713 | //======================================================================= | |
1714 | //function : Perform | |
1715 | //purpose : | |
1716 | //======================================================================= | |
1717 | void IntAna_QuadQuadGeo::Perform(const gp_Sphere& Sph1, | |
1718 | const gp_Sphere& Sph2, | |
1719 | const Standard_Real Tol) | |
1720 | { | |
1721 | done=Standard_True; | |
1722 | gp_Pnt O1=Sph1.Location(); | |
1723 | gp_Pnt O2=Sph2.Location(); | |
1724 | Standard_Real dO1O2=O1.Distance(O2); | |
1725 | Standard_Real R1=Sph1.Radius(); | |
1726 | Standard_Real R2=Sph2.Radius(); | |
1727 | Standard_Real Rmin,Rmax; | |
1728 | typeres=IntAna_Empty; | |
1729 | param2bis=0.0; //-- pour eviter param2bis not used .... | |
1730 | ||
1731 | if(R1>R2) { Rmin=R2; Rmax=R1; } else { Rmin=R1; Rmax=R2; } | |
1732 | ||
1733 | if(dO1O2<=Tol && (Abs(R1-R2) <= Tol)) { | |
1734 | typeres = IntAna_Same; | |
1735 | } | |
1736 | else { | |
1737 | if(dO1O2<=Tol) { return; } | |
1738 | gp_Dir Dir=gp_Dir(gp_Vec(O1,O2)); | |
1739 | Standard_Real t = Rmax - dO1O2 - Rmin; | |
1740 | ||
1741 | //---------------------------------------------------------------------- | |
1742 | //-- |----------------- R1 --------------------| | |
1743 | //-- |----dO1O2-----|-----------R2----------| | |
1744 | //-- --->--<-- t | |
1745 | //-- | |
1746 | //-- |------ R1 ------|---------dO1O2----------| | |
1747 | //-- |-------------------R2-----------------------| | |
1748 | //-- --->--<-- t | |
1749 | //---------------------------------------------------------------------- | |
1750 | if(t >= 0.0 && t <=Tol) { | |
1751 | typeres = IntAna_Point; | |
1752 | nbint = 1; | |
1753 | Standard_Real t2; | |
1754 | if(R1==Rmax) t2=(R1 + (R2 + dO1O2)) * 0.5; | |
1755 | else t2=(-R1+(dO1O2-R2))*0.5; | |
1756 | ||
1757 | pt1.SetCoord( O1.X() + t2*Dir.X() | |
1758 | ,O1.Y() + t2*Dir.Y() | |
1759 | ,O1.Z() + t2*Dir.Z()); | |
1760 | } | |
1761 | else { | |
1762 | //----------------------------------------------------------------- | |
1763 | //-- |----------------- dO1O2 --------------------| | |
1764 | //-- |----R1-----|-----------R2----------|-Tol-| | |
1765 | //-- | |
1766 | //-- |----------------- Rmax --------------------| | |
1767 | //-- |----Rmin----|-------dO1O2-------|-Tol-| | |
1768 | //-- | |
1769 | //----------------------------------------------------------------- | |
1770 | if((dO1O2 > (R1+R2+Tol)) || (Rmax > (dO1O2+Rmin+Tol))) { | |
1771 | typeres=IntAna_Empty; | |
1772 | } | |
1773 | else { | |
1774 | //--------------------------------------------------------------- | |
1775 | //-- | |
1776 | //-- | |
1777 | //--------------------------------------------------------------- | |
1778 | Standard_Real Alpha=0.5*(R1*R1-R2*R2+dO1O2*dO1O2)/(dO1O2); | |
1779 | Standard_Real Beta = R1*R1-Alpha*Alpha; | |
1780 | Beta = (Beta>0.0)? Sqrt(Beta) : 0.0; | |
1781 | ||
1782 | if(Beta<= myEPSILON_MINI_CIRCLE_RADIUS) { | |
1783 | typeres = IntAna_Point; | |
1784 | Alpha = (R1 + (dO1O2 - R2)) * 0.5; | |
1785 | } | |
1786 | else { | |
1787 | typeres = IntAna_Circle; | |
1788 | dir1 = Dir; | |
1789 | param1 = Beta; | |
1790 | } | |
1791 | pt1.SetCoord( O1.X() + Alpha*Dir.X() | |
1792 | ,O1.Y() + Alpha*Dir.Y() | |
1793 | ,O1.Z() + Alpha*Dir.Z()); | |
1794 | ||
1795 | nbint=1; | |
1796 | } | |
1797 | } | |
1798 | } | |
1799 | } | |
1800 | //======================================================================= | |
1801 | //function : Point | |
1802 | //purpose : Returns a Point | |
1803 | //======================================================================= | |
1804 | gp_Pnt IntAna_QuadQuadGeo::Point(const Standard_Integer n) const | |
1805 | { | |
1806 | if(!done) { StdFail_NotDone::Raise(); } | |
1807 | if(n>nbint || n<1) { Standard_DomainError::Raise(); } | |
1808 | if(typeres==IntAna_PointAndCircle) { | |
1809 | if(n!=1) { Standard_DomainError::Raise(); } | |
1810 | if(param1==0.0) return(pt1); | |
1811 | return(pt2); | |
1812 | } | |
1813 | else if(typeres==IntAna_Point) { | |
1814 | if(n==1) return(pt1); | |
1815 | return(pt2); | |
1816 | } | |
1817 | ||
1818 | // WNT (what can you expect from MicroSoft ?) | |
1819 | return gp_Pnt(0,0,0); | |
1820 | } | |
1821 | //======================================================================= | |
1822 | //function : Line | |
1823 | //purpose : Returns a Line | |
1824 | //======================================================================= | |
1825 | gp_Lin IntAna_QuadQuadGeo::Line(const Standard_Integer n) const | |
1826 | { | |
1827 | if(!done) { StdFail_NotDone::Raise(); } | |
1828 | if((n>nbint) || (n<1) || (typeres!=IntAna_Line)) { | |
1829 | Standard_DomainError::Raise(); | |
1830 | } | |
1831 | if(n==1) { return(gp_Lin(pt1,dir1)); } | |
1832 | else { return(gp_Lin(pt2,dir2)); } | |
1833 | } | |
1834 | //======================================================================= | |
1835 | //function : Circle | |
1836 | //purpose : Returns a Circle | |
1837 | //======================================================================= | |
1838 | gp_Circ IntAna_QuadQuadGeo::Circle(const Standard_Integer n) const | |
1839 | { | |
1840 | if(!done) { StdFail_NotDone::Raise(); } | |
1841 | if(typeres==IntAna_PointAndCircle) { | |
1842 | if(n!=1) { Standard_DomainError::Raise(); } | |
1843 | if(param2==0.0) return(gp_Circ(DirToAx2(pt1,dir1),param1)); | |
1844 | return(gp_Circ(DirToAx2(pt2,dir2),param2)); | |
1845 | } | |
1846 | else if((n>nbint) || (n<1) || (typeres!=IntAna_Circle)) { | |
1847 | Standard_DomainError::Raise(); | |
1848 | } | |
1849 | if(n==1) { return(gp_Circ(DirToAx2(pt1,dir1),param1)); } | |
1850 | else { return(gp_Circ(DirToAx2(pt2,dir2),param2)); } | |
1851 | } | |
1852 | ||
1853 | //======================================================================= | |
1854 | //function : Ellipse | |
1855 | //purpose : Returns a Elips | |
1856 | //======================================================================= | |
1857 | gp_Elips IntAna_QuadQuadGeo::Ellipse(const Standard_Integer n) const | |
1858 | { | |
1859 | if(!done) { StdFail_NotDone::Raise(); } | |
1860 | if((n>nbint) || (n<1) || (typeres!=IntAna_Ellipse)) { | |
1861 | Standard_DomainError::Raise(); | |
1862 | } | |
1863 | ||
1864 | if(n==1) { | |
1865 | Standard_Real R1=param1, R2=param1bis, aTmp; | |
1866 | if (R1<R2) { | |
1867 | aTmp=R1; R1=R2; R2=aTmp; | |
1868 | } | |
1869 | gp_Ax2 anAx2(pt1, dir1 ,dir2); | |
1870 | gp_Elips anElips (anAx2, R1, R2); | |
1871 | return anElips; | |
1872 | } | |
1873 | else { | |
1874 | Standard_Real R1=param2, R2=param2bis, aTmp; | |
1875 | if (R1<R2) { | |
1876 | aTmp=R1; R1=R2; R2=aTmp; | |
1877 | } | |
1878 | gp_Ax2 anAx2(pt2, dir2 ,dir1); | |
1879 | gp_Elips anElips (anAx2, R1, R2); | |
1880 | return anElips; | |
1881 | } | |
1882 | } | |
1883 | //======================================================================= | |
1884 | //function : Parabola | |
1885 | //purpose : Returns a Parabola | |
1886 | //======================================================================= | |
1887 | gp_Parab IntAna_QuadQuadGeo::Parabola(const Standard_Integer n) const | |
1888 | { | |
1889 | if(!done) { | |
1890 | StdFail_NotDone::Raise(); | |
1891 | } | |
1892 | if (typeres!=IntAna_Parabola) { | |
1893 | Standard_DomainError::Raise(); | |
1894 | } | |
1895 | if((n>nbint) || (n!=1)) { | |
1896 | Standard_OutOfRange::Raise(); | |
1897 | } | |
1898 | return(gp_Parab(gp_Ax2( pt1 | |
1899 | ,dir1 | |
1900 | ,dir2) | |
1901 | ,param1)); | |
1902 | } | |
1903 | //======================================================================= | |
1904 | //function : Hyperbola | |
1905 | //purpose : Returns a Hyperbola | |
1906 | //======================================================================= | |
1907 | gp_Hypr IntAna_QuadQuadGeo::Hyperbola(const Standard_Integer n) const | |
1908 | { | |
1909 | if(!done) { | |
1910 | StdFail_NotDone::Raise(); | |
1911 | } | |
1912 | if((n>nbint) || (n<1) || (typeres!=IntAna_Hyperbola)) { | |
1913 | Standard_DomainError::Raise(); | |
1914 | } | |
1915 | if(n==1) { | |
1916 | return(gp_Hypr(gp_Ax2( pt1 | |
1917 | ,dir1 | |
1918 | ,dir2) | |
1919 | ,param1,param1bis)); | |
1920 | } | |
1921 | else { | |
1922 | return(gp_Hypr(gp_Ax2( pt2 | |
1923 | ,dir1 | |
1924 | ,dir2.Reversed()) | |
1925 | ,param2,param2bis)); | |
1926 | } | |
1927 | } | |
7fd59977 | 1928 | //======================================================================= |
1929 | //function : HasCommonGen | |
1930 | //purpose : | |
1931 | //======================================================================= | |
7fd59977 | 1932 | Standard_Boolean IntAna_QuadQuadGeo::HasCommonGen() const |
1933 | { | |
1934 | return myCommonGen; | |
1935 | } | |
7fd59977 | 1936 | //======================================================================= |
1937 | //function : PChar | |
1938 | //purpose : | |
1939 | //======================================================================= | |
7fd59977 | 1940 | const gp_Pnt& IntAna_QuadQuadGeo::PChar() const |
1941 | { | |
1942 | return myPChar; | |
1943 | } | |
77088633 | 1944 | //======================================================================= |
1945 | //function : RefineDir | |
1946 | //purpose : | |
1947 | //======================================================================= | |
1948 | void RefineDir(gp_Dir& aDir) | |
1949 | { | |
1950 | Standard_Integer k, m, n; | |
1951 | Standard_Real aC[3]; | |
1952 | // | |
1953 | aDir.Coord(aC[0], aC[1], aC[2]); | |
1954 | // | |
1955 | m=0; | |
1956 | n=0; | |
1957 | for (k=0; k<3; ++k) { | |
1958 | if (aC[k]==1. || aC[k]==-1.) { | |
1959 | ++m; | |
1960 | } | |
1961 | else if (aC[k]!=0.) { | |
1962 | ++n; | |
1963 | } | |
1964 | } | |
1965 | // | |
1966 | if (m && n) { | |
1967 | Standard_Real aEps, aR1, aR2, aNum; | |
1968 | // | |
1969 | aEps=RealEpsilon(); | |
1970 | aR1=1.-aEps; | |
1971 | aR2=1.+aEps; | |
1972 | // | |
1973 | for (k=0; k<3; ++k) { | |
1974 | m=(aC[k]>0.); | |
1975 | aNum=(m)? aC[k] : -aC[k]; | |
1976 | if (aNum>aR1 && aNum<aR2) { | |
1977 | if (m) { | |
1978 | aC[k]=1.; | |
1979 | } | |
1980 | else { | |
1981 | aC[k]=-1.; | |
1982 | } | |
1983 | // | |
1984 | aC[(k+1)%3]=0.; | |
1985 | aC[(k+2)%3]=0.; | |
1986 | break; | |
1987 | } | |
1988 | } | |
1989 | aDir.SetCoord(aC[0], aC[1], aC[2]); | |
1990 | } | |
1991 | } | |
7fd59977 | 1992 | |
1993 | ||
1994 |