1 // File: IntPatch_ImpImpIntersection_3.gxx
2 // Created: Thu May 7 08:47:45 1992
3 // Author: Jacques GOUSSARD
4 // Copyright: OPEN CASCADE 1992
6 Standard_Boolean IntPP (const IntSurf_Quadric& Quad1,
7 const IntSurf_Quadric& Quad2,
8 const Standard_Real Tolang,
9 const Standard_Real TolTang,
10 Standard_Boolean& Same,
11 IntPatch_SequenceOfLine& slin)
12 // Traitement du cas Plan/Plan
14 IntSurf_TypeTrans trans1,trans2;
15 IntAna_ResultType typint;
16 gp_Pln pl1(Quad1.Plane());
17 gp_Pln pl2(Quad2.Plane());
19 IntAna_QuadQuadGeo inter(pl1,pl2,Tolang,TolTang);
20 if (!inter.IsDone()) {return Standard_False;}
21 Same = Standard_False;
22 typint = inter.TypeInter();
23 if (typint == IntAna_Same) { // cas faces confondues
26 else if (typint != IntAna_Empty) { // on a une ligne
27 gp_Lin linsol = inter.Line(1);
28 Standard_Real discri = linsol.Direction().DotCross
29 (Quad2.Normale(linsol.Location()),
30 Quad1.Normale(linsol.Location()));
40 Handle(IntPatch_GLine) glig = new IntPatch_GLine (linsol,Standard_False,trans1,trans2);
45 //====================================================================================
46 Standard_Boolean IntPCy (const IntSurf_Quadric& Quad1,
47 const IntSurf_Quadric& Quad2,
48 const Standard_Real Tolang,
49 const Standard_Real TolTang,
50 const Standard_Boolean Reversed,
51 Standard_Boolean& Empty,
52 IntPatch_SequenceOfLine& slin)
54 // Traitement du cas Plan/Cylindre et reciproquement
59 IntSurf_TypeTrans trans1,trans2;
60 IntAna_ResultType typint;
62 IntAna_QuadQuadGeo inter;
65 Cy = Quad2.Cylinder();
69 Cy = Quad1.Cylinder();
71 inter.Perform(Pl,Cy,Tolang,TolTang);
72 if (!inter.IsDone()) {return Standard_False;}
73 typint = inter.TypeInter();
74 Standard_Integer NbSol = inter.NbSolutions();
75 Empty = Standard_False;
81 Empty = Standard_True;
87 gp_Lin linsol = inter.Line(1);
88 gp_Pnt orig(linsol.Location());
89 if (NbSol == 1) { // ligne de tangence
90 gp_Vec TestCurvature(orig,Cy.Location());
93 Normp = Quad1.Normale(orig);
94 Normcyl = Quad2.Normale(orig);
97 Normp = Quad2.Normale(orig);
98 Normcyl = Quad1.Normale(orig);
101 IntSurf_Situation situcyl;
102 IntSurf_Situation situp;
104 if (Normp.Dot(TestCurvature) > 0.) {
105 situcyl = IntSurf_Outside;
106 if (Normp.Dot(Normcyl) > 0.) {
107 situp = IntSurf_Inside;
110 situp = IntSurf_Outside;
114 situcyl = IntSurf_Inside;
115 if (Normp.Dot(Normcyl) > 0.) {
116 situp = IntSurf_Outside;
119 situp = IntSurf_Inside;
122 Handle(IntPatch_GLine) glig;
124 glig = new IntPatch_GLine(linsol, Standard_True, situp, situcyl);
127 glig = new IntPatch_GLine(linsol, Standard_True, situcyl, situp);
131 else { // on a 2 droites. Il faut determiner les transitions
134 if (linsol.Direction().DotCross(Quad2.Normale(orig),
135 Quad1.Normale(orig)) >0.) {
136 trans1 = IntSurf_Out;
141 trans2 = IntSurf_Out;
143 Handle(IntPatch_GLine) glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
146 linsol = inter.Line(2);
147 orig = linsol.Location();
149 if (linsol.Direction().DotCross(Quad2.Normale(orig),
150 Quad1.Normale(orig)) >0.) {
151 trans1 = IntSurf_Out;
156 trans2 = IntSurf_Out;
158 glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
166 gp_Circ cirsol = inter.Circle(1);
169 ElCLib::D1(0.,cirsol,ptref,Tgt);
171 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) > 0.0) {
172 trans1 = IntSurf_Out;
177 trans2 = IntSurf_Out;
179 Handle(IntPatch_GLine) glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
186 gp_Elips elipsol = inter.Ellipse(1);
189 ElCLib::D1(0.,elipsol,ptref,Tgt);
191 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) > 0.0) {
192 trans1 = IntSurf_Out;
197 trans2 = IntSurf_Out;
199 Handle(IntPatch_GLine) glig = new IntPatch_GLine(elipsol,Standard_False,trans1,trans2);
206 return Standard_False; // on ne doit pas passer ici
209 return Standard_True;
211 //====================================================================================
212 Standard_Boolean IntPSp (const IntSurf_Quadric& Quad1,
213 const IntSurf_Quadric& Quad2,
214 const Standard_Real TolTang,
215 const Standard_Boolean Reversed,
216 Standard_Boolean& Empty,
217 IntPatch_SequenceOfLine& slin,
218 IntPatch_SequenceOfPoint& spnt)
220 // Traitement du cas Plan/Sphere et reciproquement
225 IntSurf_TypeTrans trans1,trans2;
226 IntAna_ResultType typint;
228 IntAna_QuadQuadGeo inter;
237 inter.Perform(Pl,Sp);
239 if (!inter.IsDone()) {return Standard_False;}
241 typint = inter.TypeInter();
242 Empty = Standard_False;
248 Empty = Standard_True;
254 gp_Pnt psol = inter.Point(1);
255 Standard_Real U1,V1,U2,V2;
256 Quad1.Parameters(psol,U1,V1);
257 Quad2.Parameters(psol,U2,V2);
258 IntPatch_Point ptsol;
259 ptsol.SetValue(psol,TolTang,Standard_True);
260 ptsol.SetParameters(U1,V1,U2,V2);
267 cirsol = inter.Circle(1);
270 ElCLib::D1(0.,cirsol,ptref,Tgt);
272 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) >0.) {
273 trans1 = IntSurf_Out;
278 trans2 = IntSurf_Out;
280 Handle(IntPatch_GLine) glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
287 return Standard_False; // on ne doit pas passer ici
290 return Standard_True;
292 //====================================================================================
293 Standard_Boolean IntPCo (const IntSurf_Quadric& Quad1,
294 const IntSurf_Quadric& Quad2,
295 const Standard_Real Tolang,
296 const Standard_Real TolTang,
297 const Standard_Boolean Reversed,
298 Standard_Boolean& Empty,
299 Standard_Boolean& Multpoint,
300 IntPatch_SequenceOfLine& slin,
301 IntPatch_SequenceOfPoint& spnt)
303 // Traitement du cas Plan/Cone et reciproquement
310 IntSurf_TypeTrans trans1,trans2;
311 IntAna_ResultType typint;
313 IntAna_QuadQuadGeo inter;
325 inter.Perform(Pl,Co,Tolang,TolTang);
326 if (!inter.IsDone()) {return Standard_False;}
328 typint = inter.TypeInter();
329 Standard_Integer NbSol = inter.NbSolutions();
330 Empty = Standard_False;
336 gp_Pnt psol = inter.Point(1);
337 Standard_Real U1,V1,U2,V2;
338 Quad1.Parameters(psol,U1,V1);
339 Quad2.Parameters(psol,U2,V2);
340 IntPatch_Point ptsol;
341 ptsol.SetValue(psol,TolTang,Standard_False);
342 ptsol.SetParameters(U1,V1,U2,V2);
349 gp_Lin linsol = inter.Line(1);
350 if (linsol.Direction().Dot(Co.Axis().Direction()) <0.) {
351 linsol.SetDirection(linsol.Direction().Reversed());
353 Standard_Real para = ElCLib::Parameter(linsol, apex);
354 gp_Pnt ptbid (ElCLib::Value(para+5.,linsol));
355 Standard_Real U1,V1,U2,V2;
356 Quad1.Parameters(apex,U1,V1);
357 Quad2.Parameters(apex,U2,V2);
359 if (NbSol == 1) { // ligne de tangence
360 IntPatch_Point ptsol;
361 ptsol.SetValue(apex,TolTang,Standard_False);
362 ptsol.SetParameters(U1,V1,U2,V2);
363 ptsol.SetParameter(para);
364 gp_Pnt ptbid2(apex.XYZ() + 5.*Co.Axis().Direction().XYZ());
365 gp_Vec TestCurvature(ptbid,ptbid2);
368 Normp = Quad1.Normale(ptbid);
369 Normco = Quad2.Normale(ptbid);
372 Normp = Quad2.Normale(ptbid);
373 Normco = Quad1.Normale(ptbid);
376 IntSurf_Situation situco,situco_otherside;
377 IntSurf_Situation situp,situp_otherside;
379 if (Normp.Dot(TestCurvature) > 0.) {
380 situco = IntSurf_Outside;
381 situco_otherside = IntSurf_Inside;
382 if (Normp.Dot(Normco) > 0.) {
383 situp = IntSurf_Inside;
384 situp_otherside = IntSurf_Outside;
387 situp = IntSurf_Outside;
388 situp_otherside = IntSurf_Inside;
392 situco = IntSurf_Inside;
393 situco_otherside = IntSurf_Outside;
394 if (Normp.Dot(Normco) > 0.) {
395 situp = IntSurf_Outside;
396 situp_otherside = IntSurf_Inside;
399 situp = IntSurf_Inside;
400 situp_otherside = IntSurf_Outside;
403 //----------------------------------------------------------
404 //-- Apex ---> Cone.Direction
406 Handle(IntPatch_GLine) glig;
408 glig = new IntPatch_GLine(linsol, Standard_True, situp, situco);
411 glig = new IntPatch_GLine(linsol, Standard_True, situco, situp);
413 glig->AddVertex(ptsol);
414 glig->SetFirstPoint(1);
416 //----------------------------------------------------------
417 //-- -Cone.Direction <------- Apex
419 linsol.SetDirection(linsol.Direction().Reversed());
421 glig = new IntPatch_GLine(linsol, Standard_True, situp_otherside, situco_otherside);
424 glig = new IntPatch_GLine(linsol, Standard_True, situco_otherside, situp_otherside);
426 glig->AddVertex(ptsol);
427 glig->SetFirstPoint(1);
431 // on a 2 droites. Il faut determiner les transitions
432 // de chacune. On oriente chaque ligne dans le sens
433 // de l axe du cone. Les transitions de chaque ligne seront
434 // inverses l une de l autre => on ne fait le calcul que sur
436 if (linsol.Direction().DotCross
437 (Quad2.Normale(ptbid),Quad1.Normale(ptbid)) >0.) {
438 trans1 = IntSurf_Out;
443 trans2 = IntSurf_Out;
446 Multpoint = Standard_True;
447 //------------------------------------------- Ligne 1 -------
448 IntPatch_Point ptsol;
449 ptsol.SetValue(apex,TolTang,Standard_False);
450 ptsol.SetParameters(U1,V1,U2,V2);
451 ptsol.SetParameter(para);
452 ptsol.SetMultiple(Standard_True);
453 Handle(IntPatch_GLine) glig;
454 glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
455 glig->AddVertex(ptsol);
456 glig->SetFirstPoint(1);
458 //-----------------------------------------------------------
459 //-- Other Side : Les transitions restent les memes
460 //-- linsol -> -linsol et Quad1(2).N -> -Quad1(2).N
462 linsol.SetDirection(linsol.Direction().Reversed());
463 glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
464 para = ElCLib::Parameter(linsol, apex);
465 ptsol.SetParameter(para);
466 glig->AddVertex(ptsol);
467 glig->SetFirstPoint(1);
470 //------------------------------------------- Ligne 2 -------
471 linsol = inter.Line(2);
472 if (linsol.Direction().Dot(Co.Axis().Direction()) <0.) {
473 linsol.SetDirection(linsol.Direction().Reversed());
475 para = ElCLib::Parameter(linsol, apex);
476 ptbid = ElCLib::Value(para+5.,linsol);
477 if (linsol.Direction().DotCross
478 (Quad2.Normale(ptbid),Quad1.Normale(ptbid)) >0.) {
479 trans1 = IntSurf_Out;
484 trans2 = IntSurf_Out;
486 ptsol.SetParameter(para);
487 glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
488 para = ElCLib::Parameter(linsol, apex);
489 ptsol.SetParameter(para);
490 glig->AddVertex(ptsol);
491 glig->SetFirstPoint(1);
493 //-----------------------------------------------------------
494 //-- Other Side : Les transitions restent les memes
495 //-- linsol -> -linsol et Quad1(2).N -> -Quad1(2).N
497 linsol.SetDirection(linsol.Direction().Reversed());
498 glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
499 para = ElCLib::Parameter(linsol, apex);
500 ptsol.SetParameter(para);
501 glig->AddVertex(ptsol);
502 glig->SetFirstPoint(1);
510 gp_Circ cirsol = inter.Circle(1);
512 if (ElCLib::LineParameter(Co.Axis(),cirsol.Location()) <
513 ElCLib::LineParameter(Co.Axis(),apex) ) {
514 Empty = Standard_True;
522 ElCLib::D1(0.,cirsol,ptref,Tgt);
524 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) >0.) {
525 trans1 = IntSurf_Out;
530 trans2 = IntSurf_Out;
532 Handle(IntPatch_GLine) glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
540 gp_Elips elipsol = inter.Ellipse(1);
542 if (ElCLib::LineParameter(Co.Axis(),elipsol.Location()) <
543 ElCLib::LineParameter(Co.Axis(),apex) ) {
544 Empty = Standard_True;
551 ElCLib::D1(0.,elipsol,ptref,Tgt);
553 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) >0.) {
554 trans1 = IntSurf_Out;
559 trans2 = IntSurf_Out;
561 Handle(IntPatch_GLine) glig = new IntPatch_GLine(elipsol,Standard_False,trans1,trans2);
567 case IntAna_Parabola:
569 gp_Parab parabsol = inter.Parabola(1);
571 if (ElCLib::LineParameter(Co.Axis(),parabsol.Focus()) <
572 ElCLib::LineParameter(Co.Axis(),apex) ) {
573 Empty = Standard_True;
579 gp_Vec Tgtorig(parabsol.YAxis().Direction());
580 Standard_Real ptran = Tgtorig.DotCross(Quad2.Normale(parabsol.Location()),
581 Quad1.Normale(parabsol.Location()));
582 if (ptran >0.00000001) {
583 trans1 = IntSurf_Out;
586 else if (ptran <-0.00000001) {
588 trans2 = IntSurf_Out;
591 trans1=trans2=IntSurf_Undecided;
593 Handle(IntPatch_GLine) glig = new IntPatch_GLine(parabsol,Standard_False,trans1,trans2);
599 case IntAna_Hyperbola:
604 for(Standard_Integer i=1; i<=2; i++) {
605 gp_Hypr hyprsol = inter.Hyperbola(i);
606 tophypr = ElCLib::Value(hyprsol.MajorRadius(),
608 Tgttop = hyprsol.YAxis().Direction();
609 Standard_Real qwe = Tgttop.DotCross(Quad2.Normale(tophypr),
610 Quad1.Normale(tophypr));
612 if (qwe>0.00000001) {
613 trans1 = IntSurf_Out;
616 else if (qwe<-0.00000001){
618 trans2 = IntSurf_Out;
621 trans1=trans2=IntSurf_Undecided;
623 Handle(IntPatch_GLine) glig = new IntPatch_GLine(hyprsol,Standard_False,trans1,trans2);
631 return Standard_False;
634 return Standard_True;
636 //====================================================================================