1 // Created on: 1992-05-07
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <IntAna_ListOfCurve.hxx>
18 #include <IntAna_ListIteratorOfListOfCurve.hxx>
19 #include <IntPatch_WLine.hxx>
23 Standard_Boolean ExploreCurve(const gp_Cylinder& aCy,
26 const Standard_Real aTol,
27 IntAna_ListOfCurve& aLC);
29 Standard_Boolean IsToReverse(const gp_Cylinder& Cy1,
30 const gp_Cylinder& Cy2,
31 const Standard_Real Tol);
33 // ------------------------------------------------------------------
34 // MinMax : Replaces theParMIN = MIN(theParMIN, theParMAX),
35 // theParMAX = MAX(theParMIN, theParMAX).
36 // ------------------------------------------------------------------
37 static inline void MinMax(Standard_Real& theParMIN, Standard_Real& theParMAX)
39 if(theParMIN > theParMAX)
41 const Standard_Real aux = theParMAX;
42 theParMAX = theParMIN;
48 //=======================================================================
49 //function : ProcessBounds
51 //=======================================================================
52 void ProcessBounds(const Handle(IntPatch_ALine)& alig, //-- ligne courante
53 const IntPatch_SequenceOfLine& slin,
54 const IntSurf_Quadric& Quad1,
55 const IntSurf_Quadric& Quad2,
56 Standard_Boolean& procf,
57 const gp_Pnt& ptf, //-- Debut Ligne Courante
58 const Standard_Real first, //-- Paramf
59 Standard_Boolean& procl,
60 const gp_Pnt& ptl, //-- Fin Ligne courante
61 const Standard_Real last, //-- Paraml
62 Standard_Boolean& Multpoint,
63 const Standard_Real Tol)
66 Standard_Real U1,V1,U2,V2;
71 j = slin.Length() + 1;
78 //-- On prend les lignes deja enregistrees
80 while (j <= slin.Length()) {
81 if(slin.Value(j)->ArcType() == IntPatch_Analytic) {
82 const Handle(IntPatch_ALine)& aligold = *((Handle(IntPatch_ALine)*)&slin.Value(j));
85 //-- On prend les vertex des lignes deja enregistrees
87 while (k <= aligold->NbVertex()) {
88 ptsol = aligold->Vertex(k);
90 d=ptf.Distance(ptsol.Value());
92 if (!ptsol.IsMultiple()) {
93 //-- le point ptsol (de aligold) est declare multiple sur aligold
94 Multpoint = Standard_True;
95 ptsol.SetMultiple(Standard_True);
96 aligold->Replace(k,ptsol);
98 ptsol.SetParameter(first);
99 alig->AddVertex(ptsol);
100 alig->SetFirstPoint(alig->NbVertex());
101 procf = Standard_True;
103 //-- On restore le point avec son parametre sur aligold
104 ptsol = aligold->Vertex(k);
109 if (ptl.Distance(ptsol.Value()) <= Tol) {
110 if (!ptsol.IsMultiple()) {
111 Multpoint = Standard_True;
112 ptsol.SetMultiple(Standard_True);
113 aligold->Replace(k,ptsol);
115 ptsol.SetParameter(last);
116 alig->AddVertex(ptsol);
117 alig->SetLastPoint(alig->NbVertex());
118 procl = Standard_True;
120 //-- On restore le point avec son parametre sur aligold
121 ptsol = aligold->Vertex(k);
125 if (procf && procl) {
126 k = aligold->NbVertex()+1;
132 if (procf && procl) {
140 if (!procf && !procl) {
141 Quad1.Parameters(ptf,U1,V1);
142 Quad2.Parameters(ptf,U2,V2);
143 ptsol.SetValue(ptf,Tol,Standard_False);
144 ptsol.SetParameters(U1,V1,U2,V2);
145 ptsol.SetParameter(first);
146 if (ptf.Distance(ptl) <= Tol) {
147 ptsol.SetMultiple(Standard_True); // a voir
148 Multpoint = Standard_True; // a voir de meme
149 alig->AddVertex(ptsol);
150 alig->SetFirstPoint(alig->NbVertex());
152 ptsol.SetParameter(last);
153 alig->AddVertex(ptsol);
154 alig->SetLastPoint(alig->NbVertex());
157 alig->AddVertex(ptsol);
158 alig->SetFirstPoint(alig->NbVertex());
159 Quad1.Parameters(ptl,U1,V1);
160 Quad2.Parameters(ptl,U2,V2);
161 ptsol.SetValue(ptl,Tol,Standard_False);
162 ptsol.SetParameters(U1,V1,U2,V2);
163 ptsol.SetParameter(last);
164 alig->AddVertex(ptsol);
165 alig->SetLastPoint(alig->NbVertex());
169 Quad1.Parameters(ptf,U1,V1);
170 Quad2.Parameters(ptf,U2,V2);
171 ptsol.SetValue(ptf,Tol,Standard_False);
172 ptsol.SetParameters(U1,V1,U2,V2);
173 ptsol.SetParameter(first);
174 alig->AddVertex(ptsol);
175 alig->SetFirstPoint(alig->NbVertex());
178 Quad1.Parameters(ptl,U1,V1);
179 Quad2.Parameters(ptl,U2,V2);
180 ptsol.SetValue(ptl,Tol,Standard_False);
181 ptsol.SetParameters(U1,V1,U2,V2);
182 ptsol.SetParameter(last);
183 alig->AddVertex(ptsol);
184 alig->SetLastPoint(alig->NbVertex());
187 //=======================================================================
190 //=======================================================================
191 Standard_Boolean IntCyCy(const IntSurf_Quadric& Quad1,
192 const IntSurf_Quadric& Quad2,
193 const Standard_Real Tol,
194 Standard_Boolean& Empty,
195 Standard_Boolean& Same,
196 Standard_Boolean& Multpoint,
197 IntPatch_SequenceOfLine& slin,
198 IntPatch_SequenceOfPoint& spnt)
201 IntPatch_Point ptsol;
205 IntSurf_TypeTrans trans1,trans2;
206 IntAna_ResultType typint;
211 gp_Cylinder Cy1(Quad1.Cylinder());
212 gp_Cylinder Cy2(Quad2.Cylinder());
214 IntAna_QuadQuadGeo inter(Cy1,Cy2,Tol);
218 return Standard_False;
221 typint = inter.TypeInter();
222 Standard_Integer NbSol = inter.NbSolutions();
223 Empty = Standard_False;
224 Same = Standard_False;
230 Empty = Standard_True;
236 Same = Standard_True;
242 gp_Pnt psol(inter.Point(1));
243 Standard_Real U1,V1,U2,V2;
244 Quad1.Parameters(psol,U1,V1);
245 Quad2.Parameters(psol,U2,V2);
246 ptsol.SetValue(psol,Tol,Standard_True);
247 ptsol.SetParameters(U1,V1,U2,V2);
256 { // Cylinders are tangent to each other by line
257 linsol = inter.Line(1);
258 ptref = linsol.Location();
259 gp_Dir crb1(gp_Vec(ptref,Cy1.Location()));
260 gp_Dir crb2(gp_Vec(ptref,Cy2.Location()));
261 gp_Vec norm1(Quad1.Normale(ptref));
262 gp_Vec norm2(Quad2.Normale(ptref));
263 IntSurf_Situation situcyl1;
264 IntSurf_Situation situcyl2;
266 if (crb1.Dot(crb2) < 0.)
267 { // centre de courbures "opposes"
268 if (norm1.Dot(crb1) > 0.)
270 situcyl2 = IntSurf_Inside;
274 situcyl2 = IntSurf_Outside;
277 if (norm2.Dot(crb2) > 0.)
279 situcyl1 = IntSurf_Inside;
283 situcyl1 = IntSurf_Outside;
288 if (Cy1.Radius() < Cy2.Radius())
290 if (norm1.Dot(crb1) > 0.)
292 situcyl2 = IntSurf_Inside;
296 situcyl2 = IntSurf_Outside;
299 if (norm2.Dot(crb2) > 0.)
301 situcyl1 = IntSurf_Outside;
305 situcyl1 = IntSurf_Inside;
310 if (norm1.Dot(crb1) > 0.)
312 situcyl2 = IntSurf_Outside;
316 situcyl2 = IntSurf_Inside;
319 if (norm2.Dot(crb2) > 0.)
321 situcyl1 = IntSurf_Inside;
325 situcyl1 = IntSurf_Outside;
330 Handle(IntPatch_GLine) glig = new IntPatch_GLine(linsol, Standard_True, situcyl1, situcyl2);
335 for (i=1; i <= NbSol; i++)
337 linsol = inter.Line(i);
338 ptref = linsol.Location();
339 gp_Vec lsd = linsol.Direction();
340 Standard_Real qwe = lsd.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref));
343 trans1 = IntSurf_Out;
346 else if (qwe <-0.00000001)
349 trans2 = IntSurf_Out;
353 trans1=trans2=IntSurf_Undecided;
356 Handle(IntPatch_GLine) glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
367 IntPatch_Point pmult1, pmult2;
369 elipsol = inter.Ellipse(1);
371 gp_Pnt pttang1(ElCLib::Value(0.5*M_PI, elipsol));
372 gp_Pnt pttang2(ElCLib::Value(1.5*M_PI, elipsol));
374 Multpoint = Standard_True;
375 pmult1.SetValue(pttang1,Tol,Standard_True);
376 pmult2.SetValue(pttang2,Tol,Standard_True);
377 pmult1.SetMultiple(Standard_True);
378 pmult2.SetMultiple(Standard_True);
380 Standard_Real oU1,oV1,oU2,oV2;
381 Quad1.Parameters(pttang1,oU1,oV1);
382 Quad2.Parameters(pttang1,oU2,oV2);
383 pmult1.SetParameters(oU1,oV1,oU2,oV2);
385 Quad1.Parameters(pttang2,oU1,oV1);
386 Quad2.Parameters(pttang2,oU2,oV2);
387 pmult2.SetParameters(oU1,oV1,oU2,oV2);
389 // on traite la premiere ellipse
391 //-- Calcul de la Transition de la ligne
392 ElCLib::D1(0.,elipsol,ptref,Tgt);
393 Standard_Real qwe=Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref));
396 trans1 = IntSurf_Out;
399 else if (qwe<-0.00000001)
402 trans2 = IntSurf_Out;
406 trans1=trans2=IntSurf_Undecided;
409 //-- Transition calculee au point 0 -> Trans2 , Trans1
410 //-- car ici, on devarit calculer en PI
411 Handle(IntPatch_GLine) glig = new IntPatch_GLine(elipsol,Standard_False,trans2,trans1);
414 Standard_Real aU1, aV1, aU2, aV2;
416 gp_Pnt aP (ElCLib::Value(0., elipsol));
418 aIP.SetValue(aP,Tol,Standard_False);
419 aIP.SetMultiple(Standard_False);
421 Quad1.Parameters(aP, aU1, aV1);
422 Quad2.Parameters(aP, aU2, aV2);
423 aIP.SetParameters(aU1, aV1, aU2, aV2);
425 aIP.SetParameter(0.);
426 glig->AddVertex(aIP);
427 glig->SetFirstPoint(1);
429 aIP.SetParameter(2.*M_PI);
430 glig->AddVertex(aIP);
431 glig->SetLastPoint(2);
434 pmult1.SetParameter(0.5*M_PI);
435 glig->AddVertex(pmult1);
437 pmult2.SetParameter(1.5*M_PI);
438 glig->AddVertex(pmult2);
443 //-- Transitions calculee au point 0 OK
445 // on traite la deuxieme ellipse
446 elipsol = inter.Ellipse(2);
448 Standard_Real param1 = ElCLib::Parameter(elipsol,pttang1);
449 Standard_Real param2 = ElCLib::Parameter(elipsol,pttang2);
450 Standard_Real parampourtransition = 0.0;
453 pmult1.SetParameter(0.5*M_PI);
454 pmult2.SetParameter(1.5*M_PI);
455 parampourtransition = M_PI;
458 pmult1.SetParameter(1.5*M_PI);
459 pmult2.SetParameter(0.5*M_PI);
460 parampourtransition = 0.0;
463 //-- Calcul des transitions de ligne pour la premiere ligne
464 ElCLib::D1(parampourtransition,elipsol,ptref,Tgt);
465 qwe=Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref));
468 trans1 = IntSurf_Out;
471 else if(qwe< -0.00000001)
474 trans2 = IntSurf_Out;
478 trans1=trans2=IntSurf_Undecided;
481 //-- La transition a ete calculee sur un point de cette ligne
482 glig = new IntPatch_GLine(elipsol,Standard_False,trans1,trans2);
485 Standard_Real aU1, aV1, aU2, aV2;
487 gp_Pnt aP (ElCLib::Value(0., elipsol));
489 aIP.SetValue(aP,Tol,Standard_False);
490 aIP.SetMultiple(Standard_False);
492 Quad1.Parameters(aP, aU1, aV1);
493 Quad2.Parameters(aP, aU2, aV2);
494 aIP.SetParameters(aU1, aV1, aU2, aV2);
496 aIP.SetParameter(0.);
497 glig->AddVertex(aIP);
498 glig->SetFirstPoint(1);
500 aIP.SetParameter(2.*M_PI);
501 glig->AddVertex(aIP);
502 glig->SetLastPoint(2);
505 glig->AddVertex(pmult1);
506 glig->AddVertex(pmult2);
512 case IntAna_NoGeometricSolution:
514 Standard_Boolean bReverse;
515 Standard_Real U1,V1,U2,V2;
518 bReverse=IsToReverse(Cy1, Cy2, Tol);
521 Cy2=Quad1.Cylinder();
522 Cy1=Quad2.Cylinder();
525 IntAna_IntQuadQuad anaint(Cy1,Cy2,Tol);
526 if (!anaint.IsDone())
528 return Standard_False;
531 if (anaint.NbPnt() == 0 && anaint.NbCurve() == 0)
533 Empty = Standard_True;
537 NbSol = anaint.NbPnt();
538 for (i = 1; i <= NbSol; i++)
540 psol = anaint.Point(i);
541 Quad1.Parameters(psol,U1,V1);
542 Quad2.Parameters(psol,U2,V2);
543 ptsol.SetValue(psol,Tol,Standard_True);
544 ptsol.SetParameters(U1,V1,U2,V2);
548 gp_Pnt ptvalid, ptf, ptl;
551 Standard_Real first,last,para;
552 IntAna_Curve curvsol;
553 Standard_Boolean tgfound;
554 Standard_Integer kount;
556 NbSol = anaint.NbCurve();
557 for (i = 1; i <= NbSol; i++)
559 curvsol = anaint.Curve(i);
560 curvsol.Domain(first,last);
561 ptf = curvsol.Value(first);
562 ptl = curvsol.Value(last);
566 tgfound = Standard_False;
570 para = (1.123*first + para)/2.123;
571 tgfound = curvsol.D1u(para,ptvalid,tgvalid);
579 Handle(IntPatch_ALine) alig;
582 Standard_Real qwe = tgvalid.DotCross( Quad2.Normale(ptvalid),
583 Quad1.Normale(ptvalid));
586 trans1 = IntSurf_Out;
589 else if(qwe<-0.00000001)
592 trans2 = IntSurf_Out;
596 trans1=trans2=IntSurf_Undecided;
598 alig = new IntPatch_ALine(curvsol,Standard_False,trans1,trans2);
602 alig = new IntPatch_ALine(curvsol,Standard_False);
603 //-- cout << "Transition indeterminee" << endl;
606 Standard_Boolean TempFalse1 = Standard_False;
607 Standard_Boolean TempFalse2 = Standard_False;
609 ProcessBounds(alig,slin,Quad1,Quad2,TempFalse1,ptf,first,
610 TempFalse2,ptl,last,Multpoint,Tol);
618 return Standard_False;
621 return Standard_True;
624 //=======================================================================
625 //function : ShortCosForm
626 //purpose : Represents theCosFactor*cosA+theSinFactor*sinA as
627 // theCoeff*cos(A-theAngle) if it is possibly (all angles are
629 //=======================================================================
630 static void ShortCosForm( const Standard_Real theCosFactor,
631 const Standard_Real theSinFactor,
632 Standard_Real& theCoeff,
633 Standard_Real& theAngle)
635 theCoeff = sqrt(theCosFactor*theCosFactor+theSinFactor*theSinFactor);
637 if(IsEqual(theCoeff, 0.0))
643 theAngle = acos(Abs(theCosFactor/theCoeff));
645 if(theSinFactor > 0.0)
647 if(IsEqual(theCosFactor, 0.0))
651 else if(theCosFactor < 0.0)
653 theAngle = M_PI-theAngle;
656 else if(IsEqual(theSinFactor, 0.0))
658 if(theCosFactor < 0.0)
663 if(theSinFactor < 0.0)
665 if(theCosFactor > 0.0)
667 theAngle = 2.0*M_PI-theAngle;
669 else if(IsEqual(theCosFactor, 0.0))
671 theAngle = 3.0*M_PI/2.0;
673 else if(theCosFactor < 0.0)
675 theAngle = M_PI+theAngle;
687 //Stores equations coefficients
690 stCoeffsValue(const gp_Cylinder&, const gp_Cylinder&);
700 Standard_Real mK21; //sinU2
701 Standard_Real mK11; //sinU1
702 Standard_Real mL21; //cosU2
703 Standard_Real mL11; //cosU1
704 Standard_Real mM1; //Free member
706 Standard_Real mK22; //sinU2
707 Standard_Real mK12; //sinU1
708 Standard_Real mL22; //cosU2
709 Standard_Real mL12; //cosU1
710 Standard_Real mM2; //Free member
718 Standard_Real mPSIV1;
720 Standard_Real mPSIV2;
728 stCoeffsValue::stCoeffsValue( const gp_Cylinder& theCyl1,
729 const gp_Cylinder& theCyl2)
731 const Standard_Real aNulValue = 0.01*Precision::PConfusion();
733 mVecA1 = -theCyl1.Radius()*theCyl1.XAxis().Direction();
734 mVecA2 = theCyl2.Radius()*theCyl2.XAxis().Direction();
736 mVecB1 = -theCyl1.Radius()*theCyl1.YAxis().Direction();
737 mVecB2 = theCyl2.Radius()*theCyl2.YAxis().Direction();
739 mVecC1 = theCyl1.Axis().Direction();
740 mVecC2 = -(theCyl2.Axis().Direction());
742 mVecD = theCyl2.Location().XYZ() - theCyl1.Location().XYZ();
744 enum CoupleOfEquation
750 }aFoundCouple = COENONE;
753 Standard_Real aDetV1V2 = 0.0;
755 const Standard_Real aDelta1 = mVecC1.X()*mVecC2.Y()-mVecC1.Y()*mVecC2.X(); //1-2
756 const Standard_Real aDelta2 = mVecC1.Y()*mVecC2.Z()-mVecC1.Z()*mVecC2.Y(); //2-3
757 const Standard_Real aDelta3 = mVecC1.X()*mVecC2.Z()-mVecC1.Z()*mVecC2.X(); //1-3
758 const Standard_Real anAbsD1 = Abs(aDelta1); //1-2
759 const Standard_Real anAbsD2 = Abs(aDelta2); //2-3
760 const Standard_Real anAbsD3 = Abs(aDelta3); //1-3
762 if(anAbsD1 >= anAbsD2)
764 if(anAbsD3 > anAbsD1)
766 aFoundCouple = COE13;
771 aFoundCouple = COE12;
777 if(anAbsD3 > anAbsD2)
779 aFoundCouple = COE13;
784 aFoundCouple = COE23;
789 if(Abs(aDetV1V2) < aNulValue)
791 Standard_Failure::Raise("Error. Exception in divide by zerro (IntCyCyTrim)!!!!");
800 gp_Vec aVTemp = mVecA1;
801 mVecA1.SetX(aVTemp.Y());
802 mVecA1.SetY(aVTemp.Z());
803 mVecA1.SetZ(aVTemp.X());
806 mVecA2.SetX(aVTemp.Y());
807 mVecA2.SetY(aVTemp.Z());
808 mVecA2.SetZ(aVTemp.X());
811 mVecB1.SetX(aVTemp.Y());
812 mVecB1.SetY(aVTemp.Z());
813 mVecB1.SetZ(aVTemp.X());
816 mVecB2.SetX(aVTemp.Y());
817 mVecB2.SetY(aVTemp.Z());
818 mVecB2.SetZ(aVTemp.X());
821 mVecC1.SetX(aVTemp.Y());
822 mVecC1.SetY(aVTemp.Z());
823 mVecC1.SetZ(aVTemp.X());
826 mVecC2.SetX(aVTemp.Y());
827 mVecC2.SetY(aVTemp.Z());
828 mVecC2.SetZ(aVTemp.X());
831 mVecD.SetX(aVTemp.Y());
832 mVecD.SetY(aVTemp.Z());
833 mVecD.SetZ(aVTemp.X());
839 gp_Vec aVTemp = mVecA1;
840 mVecA1.SetY(aVTemp.Z());
841 mVecA1.SetZ(aVTemp.Y());
844 mVecA2.SetY(aVTemp.Z());
845 mVecA2.SetZ(aVTemp.Y());
848 mVecB1.SetY(aVTemp.Z());
849 mVecB1.SetZ(aVTemp.Y());
852 mVecB2.SetY(aVTemp.Z());
853 mVecB2.SetZ(aVTemp.Y());
856 mVecC1.SetY(aVTemp.Z());
857 mVecC1.SetZ(aVTemp.Y());
860 mVecC2.SetY(aVTemp.Z());
861 mVecC2.SetZ(aVTemp.Y());
864 mVecD.SetY(aVTemp.Z());
865 mVecD.SetZ(aVTemp.Y());
873 //------- For V1 (begin)
875 mK21 = (mVecC2.Y()*mVecB2.X()-mVecC2.X()*mVecB2.Y())/aDetV1V2;
877 mK11 = (mVecC2.Y()*mVecB1.X()-mVecC2.X()*mVecB1.Y())/aDetV1V2;
879 mL21 = (mVecC2.Y()*mVecA2.X()-mVecC2.X()*mVecA2.Y())/aDetV1V2;
881 mL11 = (mVecC2.Y()*mVecA1.X()-mVecC2.X()*mVecA1.Y())/aDetV1V2;
883 mM1 = (mVecC2.Y()*mVecD.X()-mVecC2.X()*mVecD.Y())/aDetV1V2;
884 //------- For V1 (end)
886 //------- For V2 (begin)
888 mK22 = (mVecC1.X()*mVecB2.Y()-mVecC1.Y()*mVecB2.X())/aDetV1V2;
890 mK12 = (mVecC1.X()*mVecB1.Y()-mVecC1.Y()*mVecB1.X())/aDetV1V2;
892 mL22 = (mVecC1.X()*mVecA2.Y()-mVecC1.Y()*mVecA2.X())/aDetV1V2;
894 mL12 = (mVecC1.X()*mVecA1.Y()-mVecC1.Y()*mVecA1.X())/aDetV1V2;
896 mM2 = (mVecC1.X()*mVecD.Y()-mVecC1.Y()*mVecD.X())/aDetV1V2;
897 //------- For V1 (end)
899 ShortCosForm(mL11, mK11, mK1, mFIV1);
900 ShortCosForm(mL21, mK21, mL1, mPSIV1);
901 ShortCosForm(mL12, mK12, mK2, mFIV2);
902 ShortCosForm(mL22, mK22, mL2, mPSIV2);
904 const Standard_Real aA1=mVecC1.Z()*mK21+mVecC2.Z()*mK22-mVecB2.Z(), //sinU2
905 aA2=mVecC1.Z()*mL21+mVecC2.Z()*mL22-mVecA2.Z(), //cosU2
906 aB1=mVecB1.Z()-mVecC1.Z()*mK11-mVecC2.Z()*mK12, //sinU1
907 aB2=mVecA1.Z()-mVecC1.Z()*mL11-mVecC2.Z()*mL12; //cosU1
909 mC =mVecD.Z() -mVecC1.Z()*mM1 -mVecC2.Z()*mM2; //Free
911 Standard_Real aA = 0.0;
913 ShortCosForm(aB2,aB1,mB,mFI1);
914 ShortCosForm(aA2,aA1,aA,mFI2);
920 //=======================================================================
921 //function : SearchOnVBounds
923 //=======================================================================
924 static Standard_Boolean SearchOnVBounds(const SearchBoundType theSBType,
925 const stCoeffsValue& theCoeffs,
926 const Standard_Real theVzad,
927 const Standard_Real theInitU2,
928 const Standard_Real theInitMainVar,
929 Standard_Real& theMainVariableValue)
931 const Standard_Real aMaxError = 4.0*M_PI; // two periods
933 theMainVariableValue = RealLast();
934 const Standard_Real aTol2 = Precision::PConfusion()*Precision::PConfusion();
935 Standard_Real aMainVarPrev = theInitMainVar, aU2Prev = theInitU2, anOtherVar = theVzad;
937 Standard_Real anError = RealLast();
938 Standard_Integer aNbIter = 0;
942 return Standard_False;
944 gp_Vec aVecMainVar = theCoeffs.mVecA1 * sin(aMainVarPrev) - theCoeffs.mVecB1 * cos(aMainVarPrev);
945 gp_Vec aVecFreeMem = (theCoeffs.mVecA2 * aU2Prev + theCoeffs.mVecB2) * sin(aU2Prev) -
946 (theCoeffs.mVecB2 * aU2Prev - theCoeffs.mVecA2) * cos(aU2Prev) +
947 (theCoeffs.mVecA1 * aMainVarPrev + theCoeffs.mVecB1) * sin(aMainVarPrev) -
948 (theCoeffs.mVecB1 * aMainVarPrev - theCoeffs.mVecA1) * cos(aMainVarPrev) + theCoeffs.mVecD;
950 gp_Vec aVecVar1 = theCoeffs.mVecA2 * sin(aU2Prev) - theCoeffs.mVecB2 * cos(aU2Prev);
956 aVecVar2 = theCoeffs.mVecC2;
957 aVecFreeMem -= theCoeffs.mVecC1 * theVzad;
961 aVecVar2 = theCoeffs.mVecC1;
962 aVecFreeMem -= theCoeffs.mVecC2 * theVzad;
966 return Standard_False;
969 Standard_Real aDetMainSyst = aVecMainVar.X()*(aVecVar1.Y()*aVecVar2.Z()-aVecVar1.Z()*aVecVar2.Y())-
970 aVecMainVar.Y()*(aVecVar1.X()*aVecVar2.Z()-aVecVar1.Z()*aVecVar2.X())+
971 aVecMainVar.Z()*(aVecVar1.X()*aVecVar2.Y()-aVecVar1.Y()*aVecVar2.X());
973 if(IsEqual(aDetMainSyst, 0.0))
975 return Standard_False;
979 Standard_Real aDetMainVar = aVecFreeMem.X()*(aVecVar1.Y()*aVecVar2.Z()-aVecVar1.Z()*aVecVar2.Y())-
980 aVecFreeMem.Y()*(aVecVar1.X()*aVecVar2.Z()-aVecVar1.Z()*aVecVar2.X())+
981 aVecFreeMem.Z()*(aVecVar1.X()*aVecVar2.Y()-aVecVar1.Y()*aVecVar2.X());
983 Standard_Real aDetVar1 = aVecMainVar.X()*(aVecFreeMem.Y()*aVecVar2.Z()-aVecFreeMem.Z()*aVecVar2.Y())-
984 aVecMainVar.Y()*(aVecFreeMem.X()*aVecVar2.Z()-aVecFreeMem.Z()*aVecVar2.X())+
985 aVecMainVar.Z()*(aVecFreeMem.X()*aVecVar2.Y()-aVecFreeMem.Y()*aVecVar2.X());
987 Standard_Real aDetVar2 = aVecMainVar.X()*(aVecVar1.Y()*aVecFreeMem.Z()-aVecVar1.Z()*aVecFreeMem.Y())-
988 aVecMainVar.Y()*(aVecVar1.X()*aVecFreeMem.Z()-aVecVar1.Z()*aVecFreeMem.X())+
989 aVecMainVar.Z()*(aVecVar1.X()*aVecFreeMem.Y()-aVecVar1.Y()*aVecFreeMem.X());
991 Standard_Real aDelta = aDetMainVar/aDetMainSyst-aMainVarPrev;
993 if(Abs(aDelta) > aMaxError)
994 return Standard_False;
996 anError = aDelta*aDelta;
997 aMainVarPrev += aDelta;
1000 aDelta = aDetVar1/aDetMainSyst-aU2Prev;
1002 if(Abs(aDelta) > aMaxError)
1003 return Standard_False;
1005 anError += aDelta*aDelta;
1009 aDelta = aDetVar2/aDetMainSyst-anOtherVar;
1010 anError += aDelta*aDelta;
1011 anOtherVar += aDelta;
1013 while(anError > aTol2);
1015 theMainVariableValue = aMainVarPrev;
1017 return Standard_True;
1020 //=======================================================================
1021 //function : InscribePoint
1022 //purpose : If theFlForce==TRUE theUGiven will be adjasted forceful.
1023 //=======================================================================
1024 static Standard_Boolean InscribePoint(const Standard_Real theUfTarget,
1025 const Standard_Real theUlTarget,
1026 Standard_Real& theUGiven,
1027 const Standard_Real theTol2D,
1028 const Standard_Real thePeriod,
1029 const Standard_Boolean theFlForce)
1031 if((theUfTarget - theUGiven <= theTol2D) &&
1032 (theUGiven - theUlTarget <= theTol2D))
1033 {//it has already inscribed
1042 Standard_Real anUtemp = theUGiven + thePeriod;
1043 if((theUfTarget - anUtemp <= theTol2D) &&
1044 (anUtemp - theUlTarget <= theTol2D))
1046 theUGiven = anUtemp;
1047 return Standard_True;
1050 anUtemp = theUGiven - thePeriod;
1051 if((theUfTarget - anUtemp <= theTol2D) &&
1052 (anUtemp - theUlTarget <= theTol2D))
1054 theUGiven = anUtemp;
1058 return Standard_True;
1061 if(IsEqual(thePeriod, 0.0))
1062 {//it cannot be inscribed
1063 return Standard_False;
1066 Standard_Real aDU = theUGiven - theUfTarget;
1073 while(((theUGiven - theUfTarget)*aDU < 0.0) && !((theUfTarget - theUGiven <= theTol2D) && (theUGiven - theUlTarget <= theTol2D)))
1078 return ((theUfTarget - theUGiven <= theTol2D) && (theUGiven - theUlTarget <= theTol2D));
1081 //=======================================================================
1082 //function : InscribeInterval
1083 //purpose : Adjusts theUfGiven and after that fits theUlGiven to result
1084 //=======================================================================
1085 static Standard_Boolean InscribeInterval(const Standard_Real theUfTarget,
1086 const Standard_Real theUlTarget,
1087 Standard_Real& theUfGiven,
1088 Standard_Real& theUlGiven,
1089 const Standard_Real theTol2D,
1090 const Standard_Real thePeriod)
1092 Standard_Real anUpar = theUfGiven;
1093 const Standard_Real aDelta = theUlGiven - theUfGiven;
1094 if(InscribePoint(theUfTarget, theUlTarget, anUpar,
1095 theTol2D, thePeriod, Standard_False))
1097 theUfGiven = anUpar;
1098 theUlGiven = theUfGiven + aDelta;
1102 anUpar = theUlGiven;
1103 if(InscribePoint(theUfTarget, theUlTarget, anUpar,
1104 theTol2D, thePeriod, Standard_False))
1106 theUlGiven = anUpar;
1107 theUfGiven = theUlGiven - aDelta;
1111 return Standard_False;
1115 return Standard_True;
1118 //=======================================================================
1119 //function : InscribeAndSortArray
1120 //purpose : Sort from Min to Max value
1121 //=======================================================================
1122 static void InscribeAndSortArray( Standard_Real theArr[],
1123 const Standard_Integer theNOfMembers,
1124 const Standard_Real theUf,
1125 const Standard_Real theUl,
1126 const Standard_Real theTol2D,
1127 const Standard_Real thePeriod)
1129 for(Standard_Integer i = 0; i < theNOfMembers; i++)
1131 if(Precision::IsInfinite(theArr[i]))
1134 theArr[i] = -theArr[i];
1139 InscribePoint(theUf, theUl, theArr[i], theTol2D, thePeriod, Standard_False);
1141 for(Standard_Integer j = i - 1; j >= 0; j--)
1144 if(theArr[j+1] < theArr[j])
1146 Standard_Real anUtemp = theArr[j+1];
1147 theArr[j+1] = theArr[j];
1148 theArr[j] = anUtemp;
1155 //=======================================================================
1156 //function : AddPointIntoWL
1157 //purpose : Surf1 is a surface, whose U-par is variable.
1158 //=======================================================================
1159 static Standard_Boolean AddPointIntoWL( const IntSurf_Quadric& theQuad1,
1160 const IntSurf_Quadric& theQuad2,
1161 const Standard_Boolean isTheReverse,
1162 const gp_Pnt2d& thePntOnSurf1,
1163 const gp_Pnt2d& thePntOnSurf2,
1164 const Standard_Real theUfSurf1,
1165 const Standard_Real theUlSurf1,
1166 const Standard_Real thePeriodOfSurf1,
1167 const Handle(IntSurf_LineOn2S)& theLine,
1168 const Standard_Real theTol3D,
1169 const Standard_Real theTol2D,
1170 const Standard_Boolean theFlForce)
1172 gp_Pnt aPt1(theQuad1.Value(thePntOnSurf1.X(), thePntOnSurf1.Y())),
1173 aPt2(theQuad2.Value(thePntOnSurf2.X(), thePntOnSurf2.Y()));
1175 Standard_Real anUpar = thePntOnSurf1.X();
1176 if(!InscribePoint(theUfSurf1, theUlSurf1, anUpar, theTol2D,
1177 thePeriodOfSurf1, theFlForce))
1178 return Standard_False;
1180 IntSurf_PntOn2S aPnt;
1184 aPnt.SetValue((aPt1.XYZ()+aPt2.XYZ())/2.0,
1185 thePntOnSurf2.X(), thePntOnSurf2.Y(),
1186 anUpar, thePntOnSurf1.Y());
1190 aPnt.SetValue((aPt1.XYZ()+aPt2.XYZ())/2.0,
1191 anUpar, thePntOnSurf1.Y(),
1192 thePntOnSurf2.X(), thePntOnSurf2.Y());
1195 const Standard_Integer aNbPnts = theLine->NbPoints();
1198 Standard_Real aUl = 0.0, aVl = 0.0;
1199 const IntSurf_PntOn2S aPlast = theLine->Value(aNbPnts);
1201 aPlast.ParametersOnS2(aUl, aVl);
1203 aPlast.ParametersOnS1(aUl, aVl);
1206 {//Parameter value will be always increased.
1207 return Standard_False;
1210 //theTol2D is minimal step along parameter changed.
1211 //Therefore, if we apply this minimal step two
1212 //neighbour points will be always "same". Consequently,
1213 //we should reduce tolerance for IsSame checking.
1214 const Standard_Real aDTol = 1.0-Epsilon(1.0);
1215 if(aPnt.IsSame(aPlast, theTol3D*aDTol, theTol2D*aDTol))
1217 theLine->RemovePoint(aNbPnts);
1222 return Standard_True;
1225 //=======================================================================
1226 //function : AddBoundaryPoint
1228 //=======================================================================
1229 static Standard_Boolean AddBoundaryPoint( const IntSurf_Quadric& theQuad1,
1230 const IntSurf_Quadric& theQuad2,
1231 const Handle(IntPatch_WLine)& theWL,
1232 const stCoeffsValue& theCoeffs,
1233 const Bnd_Box2d& theUVSurf1,
1234 const Bnd_Box2d& theUVSurf2,
1235 const Standard_Real theTol3D,
1236 const Standard_Real theTol2D,
1237 const Standard_Real thePeriod,
1238 const Standard_Real theNulValue,
1239 const Standard_Real theU1,
1240 const Standard_Real theU2,
1241 const Standard_Real theV1,
1242 const Standard_Real theV1Prev,
1243 const Standard_Real theV2,
1244 const Standard_Real theV2Prev,
1245 const Standard_Boolean isTheReverse,
1246 const Standard_Real theArccosFactor,
1247 const Standard_Boolean theFlForce,
1248 Standard_Boolean& isTheFound1,
1249 Standard_Boolean& isTheFound2)
1251 Standard_Real aUSurf1f = 0.0, //const
1255 Standard_Real aUSurf2f = 0.0, //const
1260 theUVSurf1.Get(aUSurf1f, aVSurf1f, aUSurf1l, aVSurf1l);
1261 theUVSurf2.Get(aUSurf2f, aVSurf2f, aUSurf2l, aVSurf2l);
1263 SearchBoundType aTS1 = SearchNONE, aTS2 = SearchNONE;
1264 Standard_Real aV1zad = aVSurf1f, aV2zad = aVSurf2f;
1266 Standard_Real anUpar1 = theU1, anUpar2 = theU1;
1267 Standard_Real aVf = theV1, aVl = theV1Prev;
1269 if((aVf <= aVSurf1f) && (aVSurf1f <= aVl))
1273 isTheFound1 = SearchOnVBounds(aTS1, theCoeffs, aVSurf1f, theU2, theU1, anUpar1);
1275 else if((aVf <= aVSurf1l) && (aVSurf1l <= aVl))
1279 isTheFound1 = SearchOnVBounds(aTS1, theCoeffs, aVSurf1l, theU2, theU1, anUpar1);
1286 if((aVf <= aVSurf2f) && (aVSurf2f <= aVl))
1290 isTheFound2 = SearchOnVBounds(aTS2, theCoeffs, aVSurf2f, theU2, theU1, anUpar2);
1292 else if((aVf <= aVSurf2l) && (aVSurf2l <= aVl))
1296 isTheFound2 = SearchOnVBounds(aTS2, theCoeffs, aVSurf2l, theU2, theU1, anUpar2);
1299 if(anUpar1 < anUpar2)
1303 Standard_Real anArg = theCoeffs.mB * cos(anUpar1 - theCoeffs.mFI1) + theCoeffs.mC;
1305 if(theNulValue > 1.0 - anArg)
1307 if(anArg + 1.0 < theNulValue)
1310 Standard_Real aU2 = theCoeffs.mFI2 + theArccosFactor * acos(anArg);
1312 if(InscribePoint(aUSurf2f, aUSurf2l, aU2, theTol2D, thePeriod, Standard_False))
1314 const Standard_Real aV1 =
1315 (aTS1 == SearchV1) ? aV1zad :
1316 theCoeffs.mK21 * sin(aU2) + theCoeffs.mK11 * sin(anUpar1) +
1317 theCoeffs.mL21 * cos(aU2) + theCoeffs.mL11 * cos(anUpar1) + theCoeffs.mM1;
1318 const Standard_Real aV2 =
1319 (aTS1 == SearchV2) ? aV2zad :
1320 theCoeffs.mK22 * sin(aU2) + theCoeffs.mK12 * sin(anUpar1) +
1321 theCoeffs.mL22 * cos(aU2) + theCoeffs.mL12 * cos(anUpar1) + theCoeffs.mM2;
1323 AddPointIntoWL(theQuad1, theQuad2, isTheReverse,
1324 gp_Pnt2d(anUpar1, aV1), gp_Pnt2d(aU2, aV2),
1325 aUSurf1f, aUSurf1l, thePeriod,
1326 theWL->Curve(), theTol3D, theTol2D, theFlForce);
1330 isTheFound1 = Standard_False;
1336 Standard_Real anArg = theCoeffs.mB * cos(anUpar2 - theCoeffs.mFI1) + theCoeffs.mC;
1338 if(theNulValue > 1.0 - anArg)
1340 if(anArg + 1.0 < theNulValue)
1343 Standard_Real aU2 = theCoeffs.mFI2 + theArccosFactor * acos(anArg);
1344 if(InscribePoint(aUSurf2f, aUSurf2l, aU2, theTol2D, thePeriod, Standard_False))
1346 const Standard_Real aV1 =
1347 (aTS2 == SearchV1) ? aV1zad :
1348 theCoeffs.mK21 * sin(aU2) + theCoeffs.mK11 * sin(anUpar2) +
1349 theCoeffs.mL21 * cos(aU2) + theCoeffs.mL11 * cos(anUpar2) + theCoeffs.mM1;
1350 const Standard_Real aV2 =
1351 (aTS2 == SearchV2) ? aV2zad :
1352 theCoeffs.mK22 * sin(aU2) + theCoeffs.mK12 * sin(anUpar2) +
1353 theCoeffs.mL22 * cos(aU2) + theCoeffs.mL12 * cos(anUpar2) + theCoeffs.mM2;
1355 AddPointIntoWL(theQuad1, theQuad2, isTheReverse,
1356 gp_Pnt2d(anUpar2, aV1), gp_Pnt2d(aU2, aV2),
1357 aUSurf1f, aUSurf1l, thePeriod,
1358 theWL->Curve(),theTol3D, theTol2D, theFlForce);
1362 isTheFound2 = Standard_False;
1370 Standard_Real anArg = theCoeffs.mB * cos(anUpar2 - theCoeffs.mFI1) + theCoeffs.mC;
1372 if(theNulValue > 1.0 - anArg)
1374 if(anArg + 1.0 < theNulValue)
1377 Standard_Real aU2 = theCoeffs.mFI2 + theArccosFactor * acos(anArg);
1379 if(InscribePoint(aUSurf2f, aUSurf2l, aU2, theTol2D, thePeriod, Standard_False))
1381 const Standard_Real aV1 = (aTS2 == SearchV1) ? aV1zad :
1382 theCoeffs.mK21 * sin(aU2) + theCoeffs.mK11 * sin(anUpar2) +
1383 theCoeffs.mL21 * cos(aU2) + theCoeffs.mL11 * cos(anUpar2) + theCoeffs.mM1;
1384 const Standard_Real aV2 = (aTS2 == SearchV2) ? aV2zad :
1385 theCoeffs.mK22 * sin(aU2) + theCoeffs.mK12 * sin(anUpar2) +
1386 theCoeffs.mL22 * cos(aU2) + theCoeffs.mL12 * cos(anUpar2) + theCoeffs.mM2;
1388 AddPointIntoWL(theQuad1, theQuad2, isTheReverse,
1389 gp_Pnt2d(anUpar2, aV1), gp_Pnt2d(aU2, aV2),
1390 aUSurf1f, aUSurf1l, thePeriod,
1391 theWL->Curve(), theTol3D, theTol2D, theFlForce);
1395 isTheFound2 = Standard_False;
1401 Standard_Real anArg = theCoeffs.mB*cos(anUpar1-theCoeffs.mFI1)+theCoeffs.mC;
1403 if(theNulValue > 1.0 - anArg)
1405 if(anArg + 1.0 < theNulValue)
1408 Standard_Real aU2 = theCoeffs.mFI2+theArccosFactor*acos(anArg);
1409 if(InscribePoint(aUSurf2f, aUSurf2l, aU2, theTol2D, thePeriod, Standard_False))
1411 const Standard_Real aV1 = (aTS1 == SearchV1) ? aV1zad :
1412 theCoeffs.mK21 * sin(aU2) + theCoeffs.mK11 * sin(anUpar1) +
1413 theCoeffs.mL21 * cos(aU2) + theCoeffs.mL11 * cos(anUpar1) + theCoeffs.mM1;
1414 const Standard_Real aV2 = (aTS1 == SearchV2) ? aV2zad :
1415 theCoeffs.mK22 * sin(aU2) + theCoeffs.mK12 * sin(anUpar1) +
1416 theCoeffs.mL22 * cos(aU2) + theCoeffs.mL12 * cos(anUpar1) + theCoeffs.mM2;
1418 AddPointIntoWL(theQuad1, theQuad2, isTheReverse,
1419 gp_Pnt2d(anUpar1, aV1), gp_Pnt2d(aU2, aV2),
1420 aUSurf1f, aUSurf1l, thePeriod,
1421 theWL->Curve(), theTol3D, theTol2D, theFlForce);
1425 isTheFound1 = Standard_False;
1430 return Standard_True;
1433 //=======================================================================
1434 //function : SeekAdditionalPoints
1436 //=======================================================================
1437 static void SeekAdditionalPoints( const IntSurf_Quadric& theQuad1,
1438 const IntSurf_Quadric& theQuad2,
1439 const Handle(IntSurf_LineOn2S)& theLile,
1440 const stCoeffsValue& theCoeffs,
1441 const Standard_Integer theMinNbPoints,
1442 const Standard_Real theU2f,
1443 const Standard_Real theU2l,
1444 const Standard_Real theTol2D,
1445 const Standard_Real thePeriodOfSurf2,
1446 const Standard_Real theArccosFactor,
1447 const Standard_Boolean isTheReverse)
1449 Standard_Integer aNbPoints = theLile->NbPoints();
1450 if(aNbPoints >= theMinNbPoints)
1455 Standard_Real U1prec = 0.0, V1prec = 0.0, U2prec = 0.0, V2prec = 0.0;
1457 Standard_Integer aNbPointsPrev = 0;
1458 while(aNbPoints < theMinNbPoints && (aNbPoints != aNbPointsPrev))
1460 aNbPointsPrev = aNbPoints;
1461 for(Standard_Integer fp = 1, lp = 2; fp < aNbPoints; fp = lp + 1)
1463 Standard_Real U1f = 0.0, V1f = 0.0; //first point in 1st suraface
1464 Standard_Real U1l = 0.0, V1l = 0.0; //last point in 1st suraface
1466 Standard_Real U2f = 0.0, V2f = 0.0; //first point in 2nd suraface
1467 Standard_Real U2l = 0.0, V2l = 0.0; //last point in 2nd suraface
1473 theLile->Value(fp).ParametersOnS2(U1f, V1f);
1474 theLile->Value(lp).ParametersOnS2(U1l, V1l);
1476 theLile->Value(fp).ParametersOnS1(U2f, V2f);
1477 theLile->Value(lp).ParametersOnS1(U2l, V2l);
1481 theLile->Value(fp).ParametersOnS1(U1f, V1f);
1482 theLile->Value(lp).ParametersOnS1(U1l, V1l);
1484 theLile->Value(fp).ParametersOnS2(U2f, V2f);
1485 theLile->Value(lp).ParametersOnS2(U2l, V2l);
1488 if(Abs(U1l - U1f) <= theTol2D)
1490 //Step is minimal. It is not necessary to divide it.
1494 U1prec = 0.5*(U1f+U1l);
1496 Standard_Real anArg = theCoeffs.mB * cos(U1prec - theCoeffs.mFI1) + theCoeffs.mC;
1502 U2prec = theCoeffs.mFI2 + theArccosFactor*acos(anArg);
1503 InscribePoint(theU2f, theU2l, U2prec, theTol2D, thePeriodOfSurf2, Standard_False);
1507 V1prec = theCoeffs.mK21 * sin(U2prec) +
1508 theCoeffs.mK11 * sin(U1prec) +
1509 theCoeffs.mL21 * cos(U2prec) +
1510 theCoeffs.mL11 * cos(U1prec) + theCoeffs.mM1;
1511 V2prec = theCoeffs.mK22 * sin(U2prec) +
1512 theCoeffs.mK12 * sin(U1prec) +
1513 theCoeffs.mL22 * cos(U2prec) +
1514 theCoeffs.mL12 * cos(U1prec) + theCoeffs.mM2;
1516 aP1 = theQuad1.Value(U1prec, V1prec);
1517 aP2 = theQuad2.Value(U2prec, V2prec);
1519 gp_Pnt aPInt(0.5*(aP1.XYZ() + aP2.XYZ()));
1522 //cout << "|P1Pi| = " << aP1.SquareDistance(aPInt) << "; |P2Pi| = " << aP2.SquareDistance(aPInt) << endl;
1525 IntSurf_PntOn2S anIP;
1528 anIP.SetValue(aPInt, U2prec, V2prec, U1prec, V1prec);
1532 anIP.SetValue(aPInt, U1prec, V1prec, U2prec, V2prec);
1535 theLile->InsertBefore(lp, anIP);
1537 aNbPoints = theLile->NbPoints();
1538 if(aNbPoints >= theMinNbPoints)
1546 //=======================================================================
1547 //function : CriticalPointsComputing
1549 //=======================================================================
1550 static void CriticalPointsComputing(const stCoeffsValue& theCoeffs,
1551 const Standard_Real theUSurf1f,
1552 const Standard_Real theUSurf1l,
1553 const Standard_Real theUSurf2f,
1554 const Standard_Real theUSurf2l,
1555 const Standard_Real thePeriod,
1556 const Standard_Real theTol2D,
1557 const Standard_Integer theNbCritPointsMax,
1558 Standard_Real theU1crit[])
1561 theU1crit[1] = thePeriod;
1562 theU1crit[2] = theUSurf1f;
1563 theU1crit[3] = theUSurf1l;
1565 const Standard_Real aCOS = cos(theCoeffs.mFI2);
1566 const Standard_Real aBSB = Abs(theCoeffs.mB);
1567 if((theCoeffs.mC - aBSB <= aCOS) && (aCOS <= theCoeffs.mC + aBSB))
1569 Standard_Real anArg = (aCOS - theCoeffs.mC) / theCoeffs.mB;
1575 theU1crit[4] = -acos(anArg) + theCoeffs.mFI1;
1576 theU1crit[5] = acos(anArg) + theCoeffs.mFI1;
1579 Standard_Real aSf = cos(theUSurf2f - theCoeffs.mFI2);
1580 Standard_Real aSl = cos(theUSurf2l - theCoeffs.mFI2);
1583 theU1crit[6] = Abs((aSl - theCoeffs.mC) / theCoeffs.mB) < 1.0 ? -acos((aSl - theCoeffs.mC) / theCoeffs.mB) + theCoeffs.mFI1 : -Precision::Infinite();
1584 theU1crit[7] = Abs((aSf - theCoeffs.mC) / theCoeffs.mB) < 1.0 ? -acos((aSf - theCoeffs.mC) / theCoeffs.mB) + theCoeffs.mFI1 : Precision::Infinite();
1585 theU1crit[8] = Abs((aSf - theCoeffs.mC) / theCoeffs.mB) < 1.0 ? acos((aSf - theCoeffs.mC) / theCoeffs.mB) + theCoeffs.mFI1 : -Precision::Infinite();
1586 theU1crit[9] = Abs((aSl - theCoeffs.mC) / theCoeffs.mB) < 1.0 ? acos((aSl - theCoeffs.mC) / theCoeffs.mB) + theCoeffs.mFI1 : Precision::Infinite();
1588 //preparative treatment of array
1589 InscribeAndSortArray(theU1crit, theNbCritPointsMax, 0.0, thePeriod, theTol2D, thePeriod);
1590 for(Standard_Integer i = 1; i < theNbCritPointsMax; i++)
1592 Standard_Real &a = theU1crit[i],
1593 &b = theU1crit[i-1];
1594 const Standard_Real aRemain = fmod(Abs(a - b), thePeriod); // >= 0, because Abs(a - b) >= 0
1595 if((Abs(a - b) < theTol2D) || (aRemain < theTol2D) || (Abs(aRemain - thePeriod) < theTol2D))
1598 b = Precision::Infinite();
1603 //=======================================================================
1604 //function : IntCyCyTrim
1606 //=======================================================================
1607 Standard_Boolean IntCyCyTrim( const IntSurf_Quadric& theQuad1,
1608 const IntSurf_Quadric& theQuad2,
1609 const Standard_Real theTol3D,
1610 const Standard_Real theTol2D,
1611 const Bnd_Box2d& theUVSurf1,
1612 const Bnd_Box2d& theUVSurf2,
1613 const Standard_Boolean isTheReverse,
1614 Standard_Boolean& isTheEmpty,
1615 IntPatch_SequenceOfLine& theSlin,
1616 IntPatch_SequenceOfPoint& theSPnt)
1618 Standard_Real aUSurf1f = 0.0, //const
1622 Standard_Real aUSurf2f = 0.0, //const
1627 theUVSurf1.Get(aUSurf1f, aVSurf1f, aUSurf1l, aVSurf1l);
1628 theUVSurf2.Get(aUSurf2f, aVSurf2f, aUSurf2l, aVSurf2l);
1630 const Standard_Real aNulValue = 0.01*Precision::PConfusion();
1632 const gp_Cylinder& aCyl1 = theQuad1.Cylinder(),
1633 aCyl2 = theQuad2.Cylinder();
1635 IntAna_QuadQuadGeo anInter(aCyl1,aCyl2,theTol3D);
1637 if (!anInter.IsDone())
1639 return Standard_False;
1642 IntAna_ResultType aTypInt = anInter.TypeInter();
1644 if(aTypInt != IntAna_NoGeometricSolution)
1645 { //It is not necessary (because result is an analytic curve) or
1646 //it is impossible to make Walking-line.
1648 return Standard_False;
1653 const Standard_Integer aNbMaxPoints = 2000;
1654 const Standard_Integer aNbMinPoints = 200;
1655 const Standard_Integer aNbPoints = Min(Max(aNbMinPoints,
1656 RealToInt(20.0*aCyl1.Radius())), aNbMaxPoints);
1657 const Standard_Real aPeriod = 2.0*M_PI;
1658 const Standard_Real aStepMin = theTol2D,
1659 aStepMax = (aUSurf1l-aUSurf1f)/IntToReal(aNbPoints);
1660 const Standard_Integer aNbWLines = 2;
1662 const stCoeffsValue anEquationCoeffs(aCyl1, aCyl2);
1665 const Standard_Integer aNbOfBoundaries = 2;
1666 Standard_Real aU1f[aNbOfBoundaries] = {-Precision::Infinite(), -Precision::Infinite()};
1667 Standard_Real aU1l[aNbOfBoundaries] = {Precision::Infinite(), Precision::Infinite()};
1669 if(anEquationCoeffs.mB > 0.0)
1671 if(anEquationCoeffs.mB + Abs(anEquationCoeffs.mC) < -1.0)
1672 {//There is NOT intersection
1673 return Standard_True;
1675 else if(anEquationCoeffs.mB + Abs(anEquationCoeffs.mC) <= 1.0)
1677 aU1f[0] = anEquationCoeffs.mFI1;
1678 aU1l[0] = aPeriod + anEquationCoeffs.mFI1;
1680 else if((1 + anEquationCoeffs.mC <= anEquationCoeffs.mB) &&
1681 (anEquationCoeffs.mB <= 1 - anEquationCoeffs.mC))
1683 Standard_Real anArg = -(anEquationCoeffs.mC + 1) / anEquationCoeffs.mB;
1689 const Standard_Real aDAngle = acos(anArg);
1690 //(U=[0;aDAngle]+aFI1) || (U=[2*PI-aDAngle;2*PI]+aFI1)
1691 aU1f[0] = anEquationCoeffs.mFI1;
1692 aU1l[0] = aDAngle + anEquationCoeffs.mFI1;
1693 aU1f[1] = aPeriod - aDAngle + anEquationCoeffs.mFI1;
1694 aU1l[1] = aPeriod + anEquationCoeffs.mFI1;
1696 else if((1 - anEquationCoeffs.mC <= anEquationCoeffs.mB) &&
1697 (anEquationCoeffs.mB <= 1 + anEquationCoeffs.mC))
1699 Standard_Real anArg = (1 - anEquationCoeffs.mC) / anEquationCoeffs.mB;
1705 const Standard_Real aDAngle = acos(anArg);
1706 //U=[aDAngle;2*PI-aDAngle]+aFI1
1708 aU1f[0] = aDAngle + anEquationCoeffs.mFI1;
1709 aU1l[0] = aPeriod - aDAngle + anEquationCoeffs.mFI1;
1711 else if(anEquationCoeffs.mB - Abs(anEquationCoeffs.mC) >= 1.0)
1713 Standard_Real anArg1 = (1 - anEquationCoeffs.mC) / anEquationCoeffs.mB,
1714 anArg2 = -(anEquationCoeffs.mC + 1) / anEquationCoeffs.mB;
1725 const Standard_Real aDAngle1 = acos(anArg1), aDAngle2 = acos(anArg2);
1726 //(U=[aDAngle1;aDAngle2]+aFI1) ||
1727 //(U=[2*PI-aDAngle2;2*PI-aDAngle1]+aFI1)
1729 aU1f[0] = aDAngle1 + anEquationCoeffs.mFI1;
1730 aU1l[0] = aDAngle2 + anEquationCoeffs.mFI1;
1731 aU1f[1] = aPeriod - aDAngle2 + anEquationCoeffs.mFI1;
1732 aU1l[1] = aPeriod - aDAngle1 + anEquationCoeffs.mFI1;
1736 Standard_Failure::Raise("Error. Exception. Unhandled case (Range computation)!");
1739 else if(anEquationCoeffs.mB < 0.0)
1741 if(anEquationCoeffs.mB + Abs(anEquationCoeffs.mC) > 1.0)
1742 {//There is NOT intersection
1743 return Standard_True;
1745 else if(-anEquationCoeffs.mB + Abs(anEquationCoeffs.mC) <= 1.0)
1747 aU1f[0] = anEquationCoeffs.mFI1;
1748 aU1l[0] = aPeriod + anEquationCoeffs.mFI1;
1750 else if((-anEquationCoeffs.mC - 1 <= anEquationCoeffs.mB) &&
1751 ( anEquationCoeffs.mB <= anEquationCoeffs.mC - 1))
1753 Standard_Real anArg = (1 - anEquationCoeffs.mC) / anEquationCoeffs.mB;
1759 const Standard_Real aDAngle = acos(anArg);
1760 //(U=[0;aDAngle]+aFI1) || (U=[2*PI-aDAngle;2*PI]+aFI1)
1762 aU1f[0] = anEquationCoeffs.mFI1;
1763 aU1l[0] = aDAngle + anEquationCoeffs.mFI1;
1764 aU1f[1] = aPeriod - aDAngle + anEquationCoeffs.mFI1;
1765 aU1l[1] = aPeriod + anEquationCoeffs.mFI1;
1767 else if((anEquationCoeffs.mC - 1 <= anEquationCoeffs.mB) &&
1768 (anEquationCoeffs.mB <= -anEquationCoeffs.mB - 1))
1770 Standard_Real anArg = -(anEquationCoeffs.mC + 1) / anEquationCoeffs.mB;
1776 const Standard_Real aDAngle = acos(anArg);
1777 //U=[aDAngle;2*PI-aDAngle]+aFI1
1779 aU1f[0] = aDAngle + anEquationCoeffs.mFI1;
1780 aU1l[0] = aPeriod - aDAngle + anEquationCoeffs.mFI1;
1782 else if(-anEquationCoeffs.mB - Abs(anEquationCoeffs.mC) >= 1.0)
1784 Standard_Real anArg1 = -(anEquationCoeffs.mC + 1) / anEquationCoeffs.mB,
1785 anArg2 = (1 - anEquationCoeffs.mC) / anEquationCoeffs.mB;
1796 const Standard_Real aDAngle1 = acos(anArg1), aDAngle2 = acos(anArg2);
1797 //(U=[aDAngle1;aDAngle2]+aFI1) ||
1798 //(U=[2*PI-aDAngle2;2*PI-aDAngle1]+aFI1)
1800 aU1f[0] = aDAngle1 + anEquationCoeffs.mFI1;
1801 aU1l[0] = aDAngle2 + anEquationCoeffs.mFI1;
1802 aU1f[1] = aPeriod - aDAngle2 + anEquationCoeffs.mFI1;
1803 aU1l[1] = aPeriod - aDAngle1 + anEquationCoeffs.mFI1;
1807 Standard_Failure::Raise("Error. Exception. Unhandled case (Range computation)!");
1812 Standard_Failure::Raise("Error. Exception. Unhandled case (B-parameter computation)!");
1815 for(Standard_Integer i = 0; i < aNbOfBoundaries; i++)
1817 if(Precision::IsInfinite(aU1f[i]) && Precision::IsInfinite(aU1l[i]))
1820 InscribeInterval(aUSurf1f, aUSurf1l, aU1f[i], aU1l[i], theTol2D, aPeriod);
1823 if( !Precision::IsInfinite(aU1f[0]) && !Precision::IsInfinite(aU1f[1]) &&
1824 !Precision::IsInfinite(aU1l[0]) && !Precision::IsInfinite(aU1l[1]))
1826 if( ((aU1f[1] <= aU1l[0]) || (aU1l[1] <= aU1l[0])) &&
1827 ((aU1f[0] <= aU1l[1]) || (aU1l[0] <= aU1l[1])))
1828 {//Join all intervals to one
1829 aU1f[0] = Min(aU1f[0], aU1f[1]);
1830 aU1l[0] = Max(aU1l[0], aU1l[1]);
1832 aU1f[1] = -Precision::Infinite();
1833 aU1l[1] = Precision::Infinite();
1838 //[0...1] - in these points parameter U1 goes through
1839 // the seam-edge of the first cylinder.
1840 //[2...3] - First and last U1 parameter.
1841 //[4...5] - in these points parameter U2 goes through
1842 // the seam-edge of the second cylinder.
1843 //[6...9] - in these points an intersection line goes through
1844 // U-boundaries of the second surface.
1845 const Standard_Integer aNbCritPointsMax = 10;
1846 Standard_Real anU1crit[aNbCritPointsMax] = {Precision::Infinite(),
1847 Precision::Infinite(),
1848 Precision::Infinite(),
1849 Precision::Infinite(),
1850 Precision::Infinite(),
1851 Precision::Infinite(),
1852 Precision::Infinite(),
1853 Precision::Infinite(),
1854 Precision::Infinite(),
1855 Precision::Infinite()};
1857 CriticalPointsComputing(anEquationCoeffs, aUSurf1f, aUSurf1l, aUSurf2f, aUSurf2l,
1858 aPeriod, theTol2D, aNbCritPointsMax, anU1crit);
1861 //Getting Walking-line
1865 WLFStatus_Absent = 0,
1866 WLFStatus_Exist = 1,
1867 WLFStatus_Broken = 2
1870 for(Standard_Integer aCurInterval = 0; aCurInterval < aNbOfBoundaries; aCurInterval++)
1872 if(Precision::IsInfinite(aU1f[aCurInterval]) && Precision::IsInfinite(aU1l[aCurInterval]))
1875 Standard_Boolean isAddedIntoWL[aNbWLines];
1876 for(Standard_Integer i = 0; i < aNbWLines; i++)
1877 isAddedIntoWL[i] = Standard_False;
1879 Standard_Real anUf = aU1f[aCurInterval], anUl = aU1l[aCurInterval];
1880 const Standard_Boolean isDeltaPeriod = IsEqual(anUl-anUf, aPeriod);
1882 //Inscribe and sort critical points
1883 InscribeAndSortArray(anU1crit, aNbCritPointsMax, anUf, anUl, theTol2D, aPeriod);
1887 Standard_Real aU2[aNbWLines], aV1[aNbWLines], aV2[aNbWLines];
1888 WLFStatus aWLFindStatus[aNbWLines];
1889 Standard_Real aV1Prev[aNbWLines], aV2Prev[aNbWLines];
1890 Standard_Real anArccosFactor[aNbWLines] = {1.0, -1.0};
1891 Standard_Boolean isAddingWLEnabled[aNbWLines];
1893 Handle(IntSurf_LineOn2S) aL2S[aNbWLines];
1894 Handle(IntPatch_WLine) aWLine[aNbWLines];
1895 for(Standard_Integer i = 0; i < aNbWLines; i++)
1897 aL2S[i] = new IntSurf_LineOn2S();
1898 aWLine[i] = new IntPatch_WLine(aL2S[i], Standard_False);
1899 aWLFindStatus[i] = WLFStatus_Absent;
1900 isAddingWLEnabled[i] = Standard_True;
1901 aU2[i] = aV1[i] = aV2[i] = 0.0;
1902 aV1Prev[i] = aV2Prev[i] = 0.0;
1905 Standard_Real anU1 = anUf;
1907 Standard_Real aCriticalDelta[aNbCritPointsMax];
1908 for(Standard_Integer i = 0; i < aNbCritPointsMax; i++)
1909 aCriticalDelta[i] = anU1 - anU1crit[i];
1911 Standard_Boolean isFirst = Standard_True;
1917 if(IsEqual(anU1, anUl))
1919 //if isAddedIntoWL* == TRUE WLine contains only one point
1920 //(which was end point of previous WLine). If we will
1921 //add point found on the current step WLine will contain only
1922 //two points. At that both these points will be equal to the
1923 //points found earlier. Therefore, new WLine will repeat
1924 //already existing WLine. Consequently, it is necessary
1925 //to forbid building new line in this case.
1927 for(Standard_Integer i = 0; i < aNbWLines; i++)
1928 isAddingWLEnabled[i] = !isAddedIntoWL[i];
1932 for(Standard_Integer i = 0; i < aNbCritPointsMax; i++)
1934 if((anU1 - anU1crit[i])*aCriticalDelta[i] < 0.0)
1938 for(Standard_Integer i = 0; i < aNbWLines; i++)
1939 aWLFindStatus[i] = WLFStatus_Broken;
1945 Standard_Real anArg = anEquationCoeffs.mB *
1946 cos(anU1 - anEquationCoeffs.mFI1) + anEquationCoeffs.mC;
1948 if(aNulValue > 1.0 - anArg)
1950 if(anArg + 1.0 < aNulValue)
1953 for(Standard_Integer i = 0; i < aNbWLines; i++)
1955 const Standard_Integer aNbPntsWL = aWLine[i].IsNull() ? 0 :
1956 aWLine[i]->Curve()->NbPoints();
1957 aU2[i] = anEquationCoeffs.mFI2 + anArccosFactor[i]*acos(anArg);
1959 InscribePoint(aUSurf2f, aUSurf2l, aU2[i], theTol2D, aPeriod, Standard_False);
1962 {//the line has not contained any points yet
1963 if(((aUSurf2l - aUSurf2f) >= aPeriod) &&
1964 ((Abs(aU2[i] - aUSurf2f) < theTol2D) ||
1965 (Abs(aU2[i]-aUSurf2l) < theTol2D)))
1967 const Standard_Real anU1Temp = anU1 + aStepMin;
1968 Standard_Real anArgTemp = anEquationCoeffs.mB *
1969 cos(anU1Temp - anEquationCoeffs.mFI1) +
1970 anEquationCoeffs.mC;
1972 if(aNulValue > 1.0 - anArgTemp)
1975 if(anArgTemp + 1.0 < aNulValue)
1978 Standard_Real aU2Temp = anEquationCoeffs.mFI2 +
1979 anArccosFactor[i]*acos(anArgTemp);
1981 InscribePoint(aUSurf2f, aUSurf2l, aU2Temp, theTol2D, aPeriod, Standard_False);
1983 if(2.0*Abs(aU2Temp - aU2[i]) > aPeriod)
1985 if(aU2Temp > aU2[i])
1995 if(((aUSurf2l - aUSurf2f) >= aPeriod) &&
1996 ((Abs(aU2[i] - aUSurf2f) < theTol2D) ||
1997 (Abs(aU2[i]-aUSurf2l) < theTol2D)))
1999 Standard_Real aU2prev = 0.0, aV2prev = 0.0;
2001 aWLine[i]->Curve()->Value(aNbPntsWL).ParametersOnS1(aU2prev, aV2prev);
2003 aWLine[i]->Curve()->Value(aNbPntsWL).ParametersOnS2(aU2prev, aV2prev);
2005 if(2.0*Abs(aU2prev - aU2[i]) > aPeriod)
2007 if(aU2prev > aU2[i])
2015 if(aWLFindStatus[i] == WLFStatus_Broken)
2017 if(Abs(aU2[i]) <= theTol2D)
2019 else if(Abs(aU2[i] - aPeriod) <= theTol2D)
2021 else if(Abs(aU2[i] - aUSurf2f) <= theTol2D)
2023 else if(Abs(aU2[i] - aUSurf2l) <= theTol2D)
2027 aV1[i] = anEquationCoeffs.mK21 * sin(aU2[i]) +
2028 anEquationCoeffs.mK11 * sin(anU1) +
2029 anEquationCoeffs.mL21 * cos(aU2[i]) +
2030 anEquationCoeffs.mL11 * cos(anU1) + anEquationCoeffs.mM1;
2032 aV2[i] = anEquationCoeffs.mK22 * sin(aU2[i]) +
2033 anEquationCoeffs.mK12 * sin(anU1) +
2034 anEquationCoeffs.mL22 * cos(aU2[i]) +
2035 anEquationCoeffs.mL12 * cos(anU1) + anEquationCoeffs.mM2;
2039 aV1Prev[i] = aV1[i];
2040 aV2Prev[i] = aV2[i];
2042 }//for(Standard_Integer i = 0; i < aNbWLines; i++)
2044 isFirst = Standard_False;
2046 //Looking for points into WLine
2047 Standard_Boolean isBroken = Standard_False;
2048 for(Standard_Integer i = 0; i < aNbWLines; i++)
2050 if(!isAddingWLEnabled[i])
2052 aV1Prev[i] = aV1[i];
2053 aV2Prev[i] = aV2[i];
2055 if(aWLFindStatus[i] == WLFStatus_Broken)
2056 isBroken = Standard_True;
2061 if( ((aUSurf2f-aU2[i]) <= theTol2D) && ((aU2[i]-aUSurf2l) <= theTol2D) &&
2062 ((aVSurf1f - aV1[i]) <= theTol2D) && ((aV1[i] - aVSurf1l) <= theTol2D) &&
2063 ((aVSurf2f - aV2[i]) <= theTol2D) && ((aV2[i] - aVSurf2l) <= theTol2D))
2065 Standard_Boolean isForce = Standard_False;
2066 if(aWLFindStatus[i] == WLFStatus_Absent)
2068 Standard_Boolean isFound1 = Standard_False, isFound2 = Standard_False;
2070 if(((aUSurf2l - aUSurf2f) >= aPeriod) && (Abs(anU1-aUSurf1l) < theTol2D))
2072 isForce = Standard_True;
2075 AddBoundaryPoint( theQuad1, theQuad2, aWLine[i], anEquationCoeffs,
2076 theUVSurf1, theUVSurf2, theTol3D, theTol2D, aPeriod,
2077 aNulValue, anU1, aU2[i], aV1[i], aV1Prev[i],
2078 aV2[i], aV2Prev[i], isTheReverse,
2079 anArccosFactor[i], isForce, isFound1, isFound2);
2081 if(isFound1 || isFound2)
2083 aWLFindStatus[i] = WLFStatus_Exist;
2087 if(( aWLFindStatus[i] != WLFStatus_Broken) || (aWLine[i]->NbPnts() >= 1))
2089 if(AddPointIntoWL(theQuad1, theQuad2, isTheReverse,
2090 gp_Pnt2d(anU1, aV1[i]), gp_Pnt2d(aU2[i], aV2[i]),
2091 aUSurf1f, aUSurf1l, aPeriod,
2092 aWLine[i]->Curve(), theTol3D, theTol2D, isForce))
2094 if(aWLFindStatus[i] == WLFStatus_Absent)
2096 aWLFindStatus[i] = WLFStatus_Exist;
2103 if(aWLFindStatus[i] == WLFStatus_Exist)
2105 Standard_Boolean isFound1 = Standard_False, isFound2 = Standard_False;
2107 AddBoundaryPoint( theQuad1, theQuad2, aWLine[i], anEquationCoeffs,
2108 theUVSurf1, theUVSurf2, theTol3D, theTol2D, aPeriod,
2109 aNulValue, anU1, aU2[i], aV1[i], aV1Prev[i],
2110 aV2[i], aV2Prev[i], isTheReverse,
2111 anArccosFactor[i], Standard_False, isFound1, isFound2);
2113 if(isFound1 || isFound2)
2114 aWLFindStatus[i] = WLFStatus_Broken; //start a new line
2118 aV1Prev[i] = aV1[i];
2119 aV2Prev[i] = aV2[i];
2121 if(aWLFindStatus[i] == WLFStatus_Broken)
2122 isBroken = Standard_True;
2123 }//for(Standard_Integer i = 0; i < aNbWLines; i++)
2126 {//current lines are filled. Go to the next lines
2133 Standard_Real aStepU1 = aStepMax;
2135 for(Standard_Integer i = 0; i < aNbWLines; i++)
2137 Standard_Real aDeltaU1V1 = aStepU1, aDeltaU1V2 = aStepU1;
2139 Standard_Real aFact1 = !IsEqual(sin(aU2[i] - anEquationCoeffs.mFI2), 0.0) ?
2140 anEquationCoeffs.mK1 * sin(anU1 - anEquationCoeffs.mFIV1) +
2141 anEquationCoeffs.mL1 * anEquationCoeffs.mB * sin(aU2[i] - anEquationCoeffs.mPSIV1) *
2142 sin(anU1 - anEquationCoeffs.mFI1)/sin(aU2[i]-anEquationCoeffs.mFI2) : 0.0,
2143 aFact2 = !IsEqual(sin(aU2[i]-anEquationCoeffs.mFI2), 0.0) ?
2144 anEquationCoeffs.mK2 * sin(anU1 - anEquationCoeffs.mFIV2) +
2145 anEquationCoeffs.mL2 * anEquationCoeffs.mB * sin(aU2[i] - anEquationCoeffs.mPSIV2) *
2146 sin(anU1 - anEquationCoeffs.mFI1)/sin(aU2[i] - anEquationCoeffs.mFI2) : 0.0;
2148 Standard_Real aDeltaV1 = (aVSurf1l - aVSurf1f)/IntToReal(aNbPoints),
2149 aDeltaV2 = (aVSurf2l - aVSurf2f)/IntToReal(aNbPoints);
2151 if((aV1[i] < aVSurf1f) && (aFact1 < 0.0))
2152 {//Make close to aVSurf1f by increasing anU1
2153 aDeltaV1 = Min(aDeltaV1, Abs(aV1[i]-aVSurf1f));
2156 if((aV1[i] > aVSurf1l) && (aFact1 > 0.0))
2157 {//Make close to aVSurf1l by increasing anU1
2158 aDeltaV1 = Min(aDeltaV1, Abs(aV1[i]-aVSurf1l));
2161 if((aV2[i] < aVSurf2f) && (aFact2 < 0.0))
2162 {//Make close to aVSurf2f by increasing anU1
2163 aDeltaV2 = Min(aDeltaV2, Abs(aV2[i]-aVSurf2f));
2166 if((aV2[i] > aVSurf2l) && (aFact2 > 0.0))
2167 {//Make close to aVSurf2l by increasing anU1
2168 aDeltaV2 = Min(aDeltaV2, Abs(aV2[i]-aVSurf1l));
2171 aDeltaU1V1 = !IsEqual(aFact1,0.0)? Abs(aDeltaV1/aFact1) : aStepMax;
2172 aDeltaU1V2 = !IsEqual(aFact2,0.0)? Abs(aDeltaV2/aFact2) : aStepMax;
2174 if(aDeltaU1V1 < aStepU1)
2175 aStepU1 = aDeltaU1V1;
2177 if(aDeltaU1V2 < aStepU1)
2178 aStepU1 = aDeltaU1V2;
2181 if(aStepU1 < aStepMin)
2184 if(aStepU1 > aStepMax)
2189 const Standard_Real aDiff = anU1 - anUl;
2190 if((0.0 < aDiff) && (aDiff < aStepU1-Precision::PConfusion()))
2195 for(Standard_Integer i = 0; i < aNbWLines; i++)
2197 if(aWLine[i]->NbPnts() != 1)
2198 isAddedIntoWL[i] = Standard_False;
2202 for(Standard_Integer i = 0; i < aNbWLines; i++)
2204 if((aWLine[i]->NbPnts() == 1) && (!isAddedIntoWL[i]))
2206 isTheEmpty = Standard_False;
2207 Standard_Real u1, v1, u2, v2;
2208 aWLine[i]->Point(1).Parameters(u1, v1, u2, v2);
2210 aP.SetParameter(u1);
2211 aP.SetParameters(u1, v1, u2, v2);
2212 aP.SetTolerance(theTol3D);
2213 aP.SetValue(aWLine[i]->Point(1).Value());
2217 else if(aWLine[i]->NbPnts() > 1)
2219 Standard_Boolean isGood = Standard_True;
2221 if(aWLine[i]->NbPnts() == 2)
2223 const IntSurf_PntOn2S& aPf = aWLine[i]->Point(1);
2224 const IntSurf_PntOn2S& aPl = aWLine[i]->Point(2);
2226 if(aPf.IsSame(aPl, Precision::Confusion()))
2227 isGood = Standard_False;
2232 isTheEmpty = Standard_False;
2233 isAddedIntoWL[i] = Standard_True;
2234 SeekAdditionalPoints( theQuad1, theQuad2, aWLine[i]->Curve(),
2235 anEquationCoeffs, aNbPoints, aUSurf2f, aUSurf2l,
2236 theTol2D, aPeriod, anArccosFactor[i], isTheReverse);
2238 aWLine[i]->ComputeVertexParameters(theTol3D);
2239 theSlin.Append(aWLine[i]);
2244 isAddedIntoWL[i] = Standard_False;
2250 return Standard_True;
2253 //=======================================================================
2254 //function : IntCySp
2256 //=======================================================================
2257 Standard_Boolean IntCySp(const IntSurf_Quadric& Quad1,
2258 const IntSurf_Quadric& Quad2,
2259 const Standard_Real Tol,
2260 const Standard_Boolean Reversed,
2261 Standard_Boolean& Empty,
2262 Standard_Boolean& Multpoint,
2263 IntPatch_SequenceOfLine& slin,
2264 IntPatch_SequenceOfPoint& spnt)
2269 IntSurf_TypeTrans trans1,trans2;
2270 IntAna_ResultType typint;
2271 IntPatch_Point ptsol;
2278 Cy = Quad1.Cylinder();
2279 Sp = Quad2.Sphere();
2282 Cy = Quad2.Cylinder();
2283 Sp = Quad1.Sphere();
2285 IntAna_QuadQuadGeo inter(Cy,Sp,Tol);
2287 if (!inter.IsDone()) {return Standard_False;}
2289 typint = inter.TypeInter();
2290 Standard_Integer NbSol = inter.NbSolutions();
2291 Empty = Standard_False;
2297 Empty = Standard_True;
2303 gp_Pnt psol(inter.Point(1));
2304 Standard_Real U1,V1,U2,V2;
2305 Quad1.Parameters(psol,U1,V1);
2306 Quad2.Parameters(psol,U2,V2);
2307 ptsol.SetValue(psol,Tol,Standard_True);
2308 ptsol.SetParameters(U1,V1,U2,V2);
2315 cirsol = inter.Circle(1);
2318 ElCLib::D1(0.,cirsol,ptref,Tgt);
2321 gp_Vec TestCurvature(ptref,Sp.Location());
2322 gp_Vec Normsp,Normcyl;
2324 Normcyl = Quad1.Normale(ptref);
2325 Normsp = Quad2.Normale(ptref);
2328 Normcyl = Quad2.Normale(ptref);
2329 Normsp = Quad1.Normale(ptref);
2332 IntSurf_Situation situcyl;
2333 IntSurf_Situation situsp;
2335 if (Normcyl.Dot(TestCurvature) > 0.) {
2336 situsp = IntSurf_Outside;
2337 if (Normsp.Dot(Normcyl) > 0.) {
2338 situcyl = IntSurf_Inside;
2341 situcyl = IntSurf_Outside;
2345 situsp = IntSurf_Inside;
2346 if (Normsp.Dot(Normcyl) > 0.) {
2347 situcyl = IntSurf_Outside;
2350 situcyl = IntSurf_Inside;
2353 Handle(IntPatch_GLine) glig;
2355 glig = new IntPatch_GLine(cirsol, Standard_True, situcyl, situsp);
2358 glig = new IntPatch_GLine(cirsol, Standard_True, situsp, situcyl);
2363 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) > 0.0) {
2364 trans1 = IntSurf_Out;
2365 trans2 = IntSurf_In;
2368 trans1 = IntSurf_In;
2369 trans2 = IntSurf_Out;
2371 Handle(IntPatch_GLine) glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
2374 cirsol = inter.Circle(2);
2375 ElCLib::D1(0.,cirsol,ptref,Tgt);
2376 Standard_Real qwe = Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref));
2377 if(qwe> 0.0000001) {
2378 trans1 = IntSurf_Out;
2379 trans2 = IntSurf_In;
2381 else if(qwe<-0.0000001) {
2382 trans1 = IntSurf_In;
2383 trans2 = IntSurf_Out;
2386 trans1=trans2=IntSurf_Undecided;
2388 glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
2394 case IntAna_NoGeometricSolution:
2397 Standard_Real U1,V1,U2,V2;
2398 IntAna_IntQuadQuad anaint(Cy,Sp,Tol);
2399 if (!anaint.IsDone()) {
2400 return Standard_False;
2403 if (anaint.NbPnt()==0 && anaint.NbCurve()==0) {
2404 Empty = Standard_True;
2408 NbSol = anaint.NbPnt();
2409 for (i = 1; i <= NbSol; i++) {
2410 psol = anaint.Point(i);
2411 Quad1.Parameters(psol,U1,V1);
2412 Quad2.Parameters(psol,U2,V2);
2413 ptsol.SetValue(psol,Tol,Standard_True);
2414 ptsol.SetParameters(U1,V1,U2,V2);
2418 gp_Pnt ptvalid,ptf,ptl;
2420 Standard_Real first,last,para;
2421 IntAna_Curve curvsol;
2422 Standard_Boolean tgfound;
2423 Standard_Integer kount;
2425 NbSol = anaint.NbCurve();
2426 for (i = 1; i <= NbSol; i++) {
2427 curvsol = anaint.Curve(i);
2428 curvsol.Domain(first,last);
2429 ptf = curvsol.Value(first);
2430 ptl = curvsol.Value(last);
2434 tgfound = Standard_False;
2437 para = (1.123*first + para)/2.123;
2438 tgfound = curvsol.D1u(para,ptvalid,tgvalid);
2441 tgfound = kount > 5;
2444 Handle(IntPatch_ALine) alig;
2446 Standard_Real qwe = tgvalid.DotCross(Quad2.Normale(ptvalid),
2447 Quad1.Normale(ptvalid));
2448 if(qwe> 0.00000001) {
2449 trans1 = IntSurf_Out;
2450 trans2 = IntSurf_In;
2452 else if(qwe<-0.00000001) {
2453 trans1 = IntSurf_In;
2454 trans2 = IntSurf_Out;
2457 trans1=trans2=IntSurf_Undecided;
2459 alig = new IntPatch_ALine(curvsol,Standard_False,trans1,trans2);
2462 alig = new IntPatch_ALine(curvsol,Standard_False);
2464 Standard_Boolean TempFalse1a = Standard_False;
2465 Standard_Boolean TempFalse2a = Standard_False;
2467 //-- ptf et ptl : points debut et fin de alig
2469 ProcessBounds(alig,slin,Quad1,Quad2,TempFalse1a,ptf,first,
2470 TempFalse2a,ptl,last,Multpoint,Tol);
2472 } //-- boucle sur les lignes
2473 } //-- solution avec au moins une lihne
2479 return Standard_False;
2482 return Standard_True;
2484 //=======================================================================
2485 //function : IntCyCo
2487 //=======================================================================
2488 Standard_Boolean IntCyCo(const IntSurf_Quadric& Quad1,
2489 const IntSurf_Quadric& Quad2,
2490 const Standard_Real Tol,
2491 const Standard_Boolean Reversed,
2492 Standard_Boolean& Empty,
2493 Standard_Boolean& Multpoint,
2494 IntPatch_SequenceOfLine& slin,
2495 IntPatch_SequenceOfPoint& spnt)
2498 IntPatch_Point ptsol;
2502 IntSurf_TypeTrans trans1,trans2;
2503 IntAna_ResultType typint;
2510 Cy = Quad1.Cylinder();
2514 Cy = Quad2.Cylinder();
2517 IntAna_QuadQuadGeo inter(Cy,Co,Tol);
2519 if (!inter.IsDone()) {return Standard_False;}
2521 typint = inter.TypeInter();
2522 Standard_Integer NbSol = inter.NbSolutions();
2523 Empty = Standard_False;
2527 case IntAna_Empty : {
2528 Empty = Standard_True;
2532 case IntAna_Point :{
2533 gp_Pnt psol(inter.Point(1));
2534 Standard_Real U1,V1,U2,V2;
2535 Quad1.Parameters(psol,U1,V1);
2536 Quad1.Parameters(psol,U2,V2);
2537 ptsol.SetValue(psol,Tol,Standard_True);
2538 ptsol.SetParameters(U1,V1,U2,V2);
2543 case IntAna_Circle: {
2549 for(j=1; j<=2; ++j) {
2550 cirsol = inter.Circle(j);
2551 ElCLib::D1(0.,cirsol,ptref,Tgt);
2552 qwe = Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref));
2553 if(qwe> 0.00000001) {
2554 trans1 = IntSurf_Out;
2555 trans2 = IntSurf_In;
2557 else if(qwe<-0.00000001) {
2558 trans1 = IntSurf_In;
2559 trans2 = IntSurf_Out;
2562 trans1=trans2=IntSurf_Undecided;
2564 Handle(IntPatch_GLine) glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
2570 case IntAna_NoGeometricSolution: {
2572 Standard_Real U1,V1,U2,V2;
2573 IntAna_IntQuadQuad anaint(Cy,Co,Tol);
2574 if (!anaint.IsDone()) {
2575 return Standard_False;
2578 if (anaint.NbPnt() == 0 && anaint.NbCurve() == 0) {
2579 Empty = Standard_True;
2582 NbSol = anaint.NbPnt();
2583 for (i = 1; i <= NbSol; i++) {
2584 psol = anaint.Point(i);
2585 Quad1.Parameters(psol,U1,V1);
2586 Quad2.Parameters(psol,U2,V2);
2587 ptsol.SetValue(psol,Tol,Standard_True);
2588 ptsol.SetParameters(U1,V1,U2,V2);
2592 gp_Pnt ptvalid, ptf, ptl;
2595 Standard_Real first,last,para;
2596 Standard_Boolean tgfound,firstp,lastp,kept;
2597 Standard_Integer kount;
2600 //IntAna_Curve curvsol;
2602 IntAna_ListOfCurve aLC;
2603 IntAna_ListIteratorOfListOfCurve aIt;
2606 NbSol = anaint.NbCurve();
2607 for (i = 1; i <= NbSol; ++i) {
2608 kept = Standard_False;
2609 //curvsol = anaint.Curve(i);
2612 ExploreCurve(Cy, Co, aC, 10.*Tol, aLC);
2614 aIt.Initialize(aLC);
2615 for (; aIt.More(); aIt.Next()) {
2616 IntAna_Curve& curvsol=aIt.Value();
2618 curvsol.Domain(first, last);
2619 firstp = !curvsol.IsFirstOpen();
2620 lastp = !curvsol.IsLastOpen();
2622 ptf = curvsol.Value(first);
2625 ptl = curvsol.Value(last);
2629 tgfound = Standard_False;
2632 para = (1.123*first + para)/2.123;
2633 tgfound = curvsol.D1u(para,ptvalid,tgvalid);
2636 tgfound = kount > 5;
2639 Handle(IntPatch_ALine) alig;
2641 Standard_Real qwe = tgvalid.DotCross(Quad2.Normale(ptvalid),
2642 Quad1.Normale(ptvalid));
2643 if(qwe> 0.00000001) {
2644 trans1 = IntSurf_Out;
2645 trans2 = IntSurf_In;
2647 else if(qwe<-0.00000001) {
2648 trans1 = IntSurf_In;
2649 trans2 = IntSurf_Out;
2652 trans1=trans2=IntSurf_Undecided;
2654 alig = new IntPatch_ALine(curvsol,Standard_False,trans1,trans2);
2655 kept = Standard_True;
2658 ptvalid = curvsol.Value(para);
2659 alig = new IntPatch_ALine(curvsol,Standard_False);
2660 kept = Standard_True;
2661 //-- cout << "Transition indeterminee" << endl;
2664 Standard_Boolean Nfirstp = !firstp;
2665 Standard_Boolean Nlastp = !lastp;
2666 ProcessBounds(alig,slin,Quad1,Quad2,Nfirstp,ptf,first,
2667 Nlastp,ptl,last,Multpoint,Tol);
2670 } // for (; aIt.More(); aIt.Next())
2671 } // for (i = 1; i <= NbSol; ++i)
2677 return Standard_False;
2679 } // switch (typint)
2681 return Standard_True;
2683 //=======================================================================
2684 //function : ExploreCurve
2686 //=======================================================================
2687 Standard_Boolean ExploreCurve(const gp_Cylinder& ,//aCy,
2690 const Standard_Real aTol,
2691 IntAna_ListOfCurve& aLC)
2694 Standard_Boolean bFind=Standard_False;
2695 Standard_Real aTheta, aT1, aT2, aDst;
2705 aC.Domain(aT1, aT2);
2708 aDst=aPx.Distance(aPapx);
2713 aDst=aPx.Distance(aPapx);
2718 bFind=aC.FindParameter(aPapx, aTheta);
2723 aPx=aC.Value(aTheta);
2724 aDst=aPx.Distance(aPapx);
2729 // need to be splitted at aTheta
2730 IntAna_Curve aC1, aC2;
2733 aC1.SetDomain(aT1, aTheta);
2735 aC2.SetDomain(aTheta, aT2);
2743 //=======================================================================
2744 //function : IsToReverse
2746 //=======================================================================
2747 Standard_Boolean IsToReverse(const gp_Cylinder& Cy1,
2748 const gp_Cylinder& Cy2,
2749 const Standard_Real Tol)
2751 Standard_Boolean bRet;
2752 Standard_Real aR1,aR2, dR, aSc1, aSc2;
2754 bRet=Standard_False;
2766 gp_Dir aDZ(0.,0.,1.);
2768 const gp_Dir& aDir1=Cy1.Axis().Direction();
2774 const gp_Dir& aDir2=Cy2.Axis().Direction();