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.
18 #include <Bnd_Range.hxx>
19 #include <IntAna_ListOfCurve.hxx>
20 #include <math_Matrix.hxx>
21 #include <NCollection_IncAllocator.hxx>
22 #include <Standard_DivideByZero.hxx>
24 //If Abs(a) <= aNulValue then it is considered that a = 0.
25 static const Standard_Real aNulValue = 1.0e-11;
27 static void ShortCosForm( const Standard_Real theCosFactor,
28 const Standard_Real theSinFactor,
29 Standard_Real& theCoeff,
30 Standard_Real& theAngle);
32 static Standard_Boolean ExploreCurve(const gp_Cone& theCo,
34 const Standard_Real aTol,
35 IntAna_ListOfCurve& aLC);
37 static Standard_Boolean InscribePoint(const Standard_Real theUfTarget,
38 const Standard_Real theUlTarget,
39 Standard_Real& theUGiven,
40 const Standard_Real theTol2D,
41 const Standard_Real thePeriod,
42 const Standard_Boolean theFlForce);
45 class ComputationMethods
47 //Every cylinder can be represented by the following equation in parametric form:
48 // S(U,V) = L + R*cos(U)*Xd+R*sin(U)*Yd+V*Zd,
49 //where location L, directions Xd, Yd and Zd have type gp_XYZ.
51 //Intersection points between two cylinders can be found from the following system:
52 // S1(U1, V1) = S2(U2, V2)
54 // {X01 + R1*cos(U1)*Xx1 + R1*sin(U1)*Yx1 + V1*Zx1 = X02 + R2*cos(U2)*Xx2 + R2*sin(U2)*Yx2 + V2*Zx2
55 // {Y01 + R1*cos(U1)*Xy1 + R1*sin(U1)*Yy1 + V1*Zy1 = Y02 + R2*cos(U2)*Xy2 + R2*sin(U2)*Yy2 + V2*Zy2 (1)
56 // {Z01 + R1*cos(U1)*Xz1 + R1*sin(U1)*Yz1 + V1*Zz1 = Z02 + R2*cos(U2)*Xz2 + R2*sin(U2)*Yz2 + V2*Zz2
58 //The formula (1) can be rewritten as follows
59 // {C11*V1+C21*V2=A11*cos(U1)+B11*sin(U1)+A21*cos(U2)+B21*sin(U2)+D1
60 // {C12*V1+C22*V2=A12*cos(U1)+B12*sin(U1)+A22*cos(U2)+B22*sin(U2)+D2 (2)
61 // {C13*V1+C23*V2=A13*cos(U1)+B13*sin(U1)+A23*cos(U2)+B23*sin(U2)+D3
63 //Hereafter we consider that in system
64 // {C11*V1+C21*V2=A11*cos(U1)+B11*sin(U1)+A21*cos(U2)+B21*sin(U2)+D1 (3)
65 // {C12*V1+C22*V2=A12*cos(U1)+B12*sin(U1)+A22*cos(U2)+B22*sin(U2)+D2
66 //variables V1 and V2 can be found unambiguously, i.e. determinant
71 //In this case, variables V1 and V2 can be found as follows:
72 // {V1 = K11*sin(U1)+K21*sin(U2)+L11*cos(U1)+L21*cos(U2)+M1 = K1*cos(U1-FIV1)+L1*cos(U2-PSIV1)+M1 (4)
73 // {V2 = K12*sin(U1)+K22*sin(U2)+L12*cos(U1)+L22*cos(U2)+M2 = K2*cos(U2-FIV2)+L2*cos(U2-PSIV2)+M2
75 //Having substituted result of (4) to the 3rd equation of (2), we will obtain equation
76 // cos(U2-FI2) = B*cos(U1-FI1)+C. (5)
78 //I.e. when U1 is taken different given values (from domain), correspond U2 value can be computed
79 //from equation (5). After that, V1 and V2 can be computed from the system (4) (see
80 //CylCylComputeParameters(...) methods).
82 //It is important to remark that equation (5) (in general) has two solutions: U2=FI2 +/- f(U1).
83 //Therefore, we are getting here two intersection lines.
86 //Stores equations coefficients
89 stCoeffsValue(const gp_Cylinder&, const gp_Cylinder&);
99 Standard_Real mK21; //sinU2
100 Standard_Real mK11; //sinU1
101 Standard_Real mL21; //cosU2
102 Standard_Real mL11; //cosU1
103 Standard_Real mM1; //Free member
105 Standard_Real mK22; //sinU2
106 Standard_Real mK12; //sinU1
107 Standard_Real mL22; //cosU2
108 Standard_Real mL12; //cosU1
109 Standard_Real mM2; //Free member
117 Standard_Real mPSIV1;
119 Standard_Real mPSIV2;
128 //! Determines, if U2(U1) function is increasing.
129 static Standard_Boolean CylCylMonotonicity(const Standard_Real theU1par,
130 const Standard_Integer theWLIndex,
131 const stCoeffsValue& theCoeffs,
132 const Standard_Real thePeriod,
133 Standard_Boolean& theIsIncreasing);
135 //! Computes U2 (U-parameter of the 2nd cylinder) and, if theDelta != 0,
136 //! esimates the tolerance of U2-computing (estimation result is
137 //! assigned to *theDelta value).
138 static Standard_Boolean CylCylComputeParameters(const Standard_Real theU1par,
139 const Standard_Integer theWLIndex,
140 const stCoeffsValue& theCoeffs,
141 Standard_Real& theU2,
142 Standard_Real* const theDelta = 0);
144 static Standard_Boolean CylCylComputeParameters(const Standard_Real theU1,
145 const Standard_Real theU2,
146 const stCoeffsValue& theCoeffs,
147 Standard_Real& theV1,
148 Standard_Real& theV2);
150 static Standard_Boolean CylCylComputeParameters(const Standard_Real theU1par,
151 const Standard_Integer theWLIndex,
152 const stCoeffsValue& theCoeffs,
153 Standard_Real& theU2,
154 Standard_Real& theV1,
155 Standard_Real& theV2);
159 ComputationMethods::stCoeffsValue::stCoeffsValue(const gp_Cylinder& theCyl1,
160 const gp_Cylinder& theCyl2):
161 mVecA1(-theCyl1.Radius()*theCyl1.XAxis().Direction().XYZ()),
162 mVecA2(theCyl2.Radius()*theCyl2.XAxis().Direction().XYZ()),
163 mVecB1(-theCyl1.Radius()*theCyl1.YAxis().Direction().XYZ()),
164 mVecB2(theCyl2.Radius()*theCyl2.YAxis().Direction().XYZ()),
165 mVecC1(theCyl1.Axis().Direction().XYZ()),
166 mVecC2(theCyl2.Axis().Direction().XYZ().Reversed()),
167 mVecD(theCyl2.Location().XYZ() - theCyl1.Location().XYZ())
169 enum CoupleOfEquation
175 }aFoundCouple = COENONE;
178 Standard_Real aDetV1V2 = 0.0;
180 const Standard_Real aDelta1 = mVecC1(1)*mVecC2(2)-mVecC1(2)*mVecC2(1); //1-2
181 const Standard_Real aDelta2 = mVecC1(2)*mVecC2(3)-mVecC1(3)*mVecC2(2); //2-3
182 const Standard_Real aDelta3 = mVecC1(1)*mVecC2(3)-mVecC1(3)*mVecC2(1); //1-3
183 const Standard_Real anAbsD1 = Abs(aDelta1); //1-2
184 const Standard_Real anAbsD2 = Abs(aDelta2); //2-3
185 const Standard_Real anAbsD3 = Abs(aDelta3); //1-3
187 if(anAbsD1 >= anAbsD2)
189 if(anAbsD3 > anAbsD1)
191 aFoundCouple = COE13;
196 aFoundCouple = COE12;
202 if(anAbsD3 > anAbsD2)
204 aFoundCouple = COE13;
209 aFoundCouple = COE23;
214 // In point of fact, every determinant (aDelta1, aDelta2 and aDelta3) is
215 // cross-product between directions (i.e. sine of angle).
216 // If sine is too small then sine is (approx.) equal to angle itself.
217 // Therefore, in this case we should compare sine with angular tolerance.
218 // This constant is used for check if axes are parallel (see constructor
219 // AxeOperator::AxeOperator(...) in IntAna_QuadQuadGeo.cxx file).
220 if(Abs(aDetV1V2) < Precision::Angular())
222 throw Standard_Failure("Error. Exception in divide by zerro (IntCyCyTrim)!!!!");
231 math_Vector aVTemp(mVecA1);
232 mVecA1(1) = aVTemp(2);
233 mVecA1(2) = aVTemp(3);
234 mVecA1(3) = aVTemp(1);
237 mVecA2(1) = aVTemp(2);
238 mVecA2(2) = aVTemp(3);
239 mVecA2(3) = aVTemp(1);
242 mVecB1(1) = aVTemp(2);
243 mVecB1(2) = aVTemp(3);
244 mVecB1(3) = aVTemp(1);
247 mVecB2(1) = aVTemp(2);
248 mVecB2(2) = aVTemp(3);
249 mVecB2(3) = aVTemp(1);
252 mVecC1(1) = aVTemp(2);
253 mVecC1(2) = aVTemp(3);
254 mVecC1(3) = aVTemp(1);
257 mVecC2(1) = aVTemp(2);
258 mVecC2(2) = aVTemp(3);
259 mVecC2(3) = aVTemp(1);
262 mVecD(1) = aVTemp(2);
263 mVecD(2) = aVTemp(3);
264 mVecD(3) = aVTemp(1);
270 math_Vector aVTemp = mVecA1;
271 mVecA1(2) = aVTemp(3);
272 mVecA1(3) = aVTemp(2);
275 mVecA2(2) = aVTemp(3);
276 mVecA2(3) = aVTemp(2);
279 mVecB1(2) = aVTemp(3);
280 mVecB1(3) = aVTemp(2);
283 mVecB2(2) = aVTemp(3);
284 mVecB2(3) = aVTemp(2);
287 mVecC1(2) = aVTemp(3);
288 mVecC1(3) = aVTemp(2);
291 mVecC2(2) = aVTemp(3);
292 mVecC2(3) = aVTemp(2);
295 mVecD(2) = aVTemp(3);
296 mVecD(3) = aVTemp(2);
304 //------- For V1 (begin)
306 mK21 = (mVecC2(2)*mVecB2(1)-mVecC2(1)*mVecB2(2))/aDetV1V2;
308 mK11 = (mVecC2(2)*mVecB1(1)-mVecC2(1)*mVecB1(2))/aDetV1V2;
310 mL21 = (mVecC2(2)*mVecA2(1)-mVecC2(1)*mVecA2(2))/aDetV1V2;
312 mL11 = (mVecC2(2)*mVecA1(1)-mVecC2(1)*mVecA1(2))/aDetV1V2;
314 mM1 = (mVecC2(2)*mVecD(1)-mVecC2(1)*mVecD(2))/aDetV1V2;
315 //------- For V1 (end)
317 //------- For V2 (begin)
319 mK22 = (mVecC1(1)*mVecB2(2)-mVecC1(2)*mVecB2(1))/aDetV1V2;
321 mK12 = (mVecC1(1)*mVecB1(2)-mVecC1(2)*mVecB1(1))/aDetV1V2;
323 mL22 = (mVecC1(1)*mVecA2(2)-mVecC1(2)*mVecA2(1))/aDetV1V2;
325 mL12 = (mVecC1(1)*mVecA1(2)-mVecC1(2)*mVecA1(1))/aDetV1V2;
327 mM2 = (mVecC1(1)*mVecD(2)-mVecC1(2)*mVecD(1))/aDetV1V2;
328 //------- For V1 (end)
330 ShortCosForm(mL11, mK11, mK1, mFIV1);
331 ShortCosForm(mL21, mK21, mL1, mPSIV1);
332 ShortCosForm(mL12, mK12, mK2, mFIV2);
333 ShortCosForm(mL22, mK22, mL2, mPSIV2);
335 const Standard_Real aA1=mVecC1(3)*mK21+mVecC2(3)*mK22-mVecB2(3), //sinU2
336 aA2=mVecC1(3)*mL21+mVecC2(3)*mL22-mVecA2(3), //cosU2
337 aB1=mVecB1(3)-mVecC1(3)*mK11-mVecC2(3)*mK12, //sinU1
338 aB2=mVecA1(3)-mVecC1(3)*mL11-mVecC2(3)*mL12; //cosU1
340 mC =mVecD(3) - mVecC1(3)*mM1 -mVecC2(3)*mM2; //Free
342 Standard_Real aA = 0.0;
344 ShortCosForm(aB2,aB1,mB,mFI1);
345 ShortCosForm(aA2,aA1,aA,mFI2);
351 class WorkWithBoundaries
372 //Equal to 0 for 1st surface non-zero for 2nd one.
373 Standard_Integer mySurfID;
380 bool operator>(const StPInfo& theOther) const
382 return myU1 > theOther.myU1;
385 bool operator<(const StPInfo& theOther) const
387 return myU1 < theOther.myU1;
390 bool operator==(const StPInfo& theOther) const
392 return myU1 == theOther.myU1;
396 WorkWithBoundaries(const IntSurf_Quadric& theQuad1,
397 const IntSurf_Quadric& theQuad2,
398 const ComputationMethods::stCoeffsValue& theCoeffs,
399 const Bnd_Box2d& theUVSurf1,
400 const Bnd_Box2d& theUVSurf2,
401 const Standard_Integer theNbWLines,
402 const Standard_Real thePeriod,
403 const Standard_Real theTol3D,
404 const Standard_Real theTol2D,
405 const Standard_Boolean isTheReverse) :
406 myQuad1(theQuad1), myQuad2(theQuad2), myCoeffs(theCoeffs),
407 myUVSurf1(theUVSurf1), myUVSurf2(theUVSurf2), myNbWLines(theNbWLines),
408 myPeriod(thePeriod), myTol3D(theTol3D), myTol2D(theTol2D),
409 myIsReverse(isTheReverse)
413 // Returns parameters of system solved while finding
415 const ComputationMethods::stCoeffsValue &SICoeffs() const
420 // Returns quadric correspond to the index theIdx.
421 const IntSurf_Quadric& GetQSurface(const Standard_Integer theIdx) const
429 // Returns TRUE in case of reverting surfaces
430 Standard_Boolean IsReversed() const
435 // Returns 2D-tolerance
436 Standard_Real Get2dTolerance() const
441 // Returns 3D-tolerance
442 Standard_Real Get3dTolerance() const
447 // Returns UV-bounds of 1st surface
448 const Bnd_Box2d& UVS1() const
453 // Returns UV-bounds of 2nd surface
454 const Bnd_Box2d& UVS2() const
459 void AddBoundaryPoint(const Handle(IntPatch_WLine)& theWL,
460 const Standard_Real theU1,
461 const Standard_Real theU1Min,
462 const Standard_Real theU2,
463 const Standard_Real theV1,
464 const Standard_Real theV1Prev,
465 const Standard_Real theV2,
466 const Standard_Real theV2Prev,
467 const Standard_Integer theWLIndex,
468 const Standard_Boolean theFlForce,
469 Standard_Boolean& isTheFound1,
470 Standard_Boolean& isTheFound2) const;
472 static Standard_Boolean BoundariesComputing(const ComputationMethods::stCoeffsValue &theCoeffs,
473 const Standard_Real thePeriod,
474 Bnd_Range theURange[]);
476 void BoundaryEstimation(const gp_Cylinder& theCy1,
477 const gp_Cylinder& theCy2,
478 Bnd_Range& theOutBoxS1,
479 Bnd_Range& theOutBoxS2) const;
483 //Solves equation (2) (see declaration of ComputationMethods class) in case,
484 //when V1 or V2 (is set by theSBType argument) is known (corresponds to the boundary
485 //and equal to theVzad) but U1 is unknown. Computation is made by numeric methods and
486 //requires initial values (theVInit, theInitU2 and theInitMainVar).
488 SearchOnVBounds(const SearchBoundType theSBType,
489 const Standard_Real theVzad,
490 const Standard_Real theVInit,
491 const Standard_Real theInitU2,
492 const Standard_Real theInitMainVar,
493 Standard_Real& theMainVariableValue) const;
495 const WorkWithBoundaries& operator=(const WorkWithBoundaries&);
498 friend class ComputationMethods;
500 const IntSurf_Quadric& myQuad1;
501 const IntSurf_Quadric& myQuad2;
502 const ComputationMethods::stCoeffsValue& myCoeffs;
503 const Bnd_Box2d& myUVSurf1;
504 const Bnd_Box2d& myUVSurf2;
505 const Standard_Integer myNbWLines;
506 const Standard_Real myPeriod;
507 const Standard_Real myTol3D;
508 const Standard_Real myTol2D;
509 const Standard_Boolean myIsReverse;
512 static void SeekAdditionalPoints( const IntSurf_Quadric& theQuad1,
513 const IntSurf_Quadric& theQuad2,
514 const Handle(IntSurf_LineOn2S)& theLine,
515 const ComputationMethods::stCoeffsValue& theCoeffs,
516 const Standard_Integer theWLIndex,
517 const Standard_Integer theMinNbPoints,
518 const Standard_Integer theStartPointOnLine,
519 const Standard_Integer theEndPointOnLine,
520 const Standard_Real theTol2D,
521 const Standard_Real thePeriodOfSurf2,
522 const Standard_Boolean isTheReverse);
524 //=======================================================================
526 //purpose : Replaces theParMIN = MIN(theParMIN, theParMAX),
527 // theParMAX = MAX(theParMIN, theParMAX).
528 //=======================================================================
529 static inline void MinMax(Standard_Real& theParMIN, Standard_Real& theParMAX)
531 if(theParMIN > theParMAX)
533 const Standard_Real aux = theParMAX;
534 theParMAX = theParMIN;
539 //=======================================================================
540 //function : ExtremaLineLine
541 //purpose : Computes extrema between the given lines. Returns parameters
542 // on correspond curve (see correspond method for Extrema_ExtElC class).
543 //=======================================================================
544 static inline void ExtremaLineLine(const gp_Ax1& theC1,
546 const Standard_Real theCosA,
547 const Standard_Real theSqSinA,
548 Standard_Real& thePar1,
549 Standard_Real& thePar2)
551 const gp_Dir &aD1 = theC1.Direction(),
552 &aD2 = theC2.Direction();
554 const gp_XYZ aL1L2 = theC2.Location().XYZ() - theC1.Location().XYZ();
555 const Standard_Real aD1L = aD1.XYZ().Dot(aL1L2),
556 aD2L = aD2.XYZ().Dot(aL1L2);
558 thePar1 = (aD1L - theCosA * aD2L) / theSqSinA;
559 thePar2 = (theCosA * aD1L - aD2L) / theSqSinA;
562 //=======================================================================
563 //function : VBoundaryPrecise
564 //purpose : By default, we shall consider, that V1 and V2 will be increased
565 // if U1 is increased. But if it is not, new V1set and/or V2set
566 // must be computed as [V1current - DeltaV1] (analogically
567 // for V2). This function processes this case.
568 //=======================================================================
569 static void VBoundaryPrecise( const math_Matrix& theMatr,
570 const Standard_Real theV1AfterDecrByDelta,
571 const Standard_Real theV2AfterDecrByDelta,
572 Standard_Real& theV1Set,
573 Standard_Real& theV2Set)
575 //Now we are going to define if V1 (and V2) increases
576 //(or decreases) when U1 will increase.
577 const Standard_Integer aNbDim = 3;
578 math_Matrix aSyst(1, aNbDim, 1, aNbDim);
580 aSyst.SetCol(1, theMatr.Col(1));
581 aSyst.SetCol(2, theMatr.Col(2));
582 aSyst.SetCol(3, theMatr.Col(4));
584 //We have the system (see comment to StepComputing(...) function)
585 // {a11*dV1 + a12*dV2 + a14*dU2 = -a13*dU1
586 // {a21*dV1 + a22*dV2 + a24*dU2 = -a23*dU1
587 // {a31*dV1 + a32*dV2 + a34*dU2 = -a33*dU1
589 const Standard_Real aDet = aSyst.Determinant();
591 aSyst.SetCol(1, theMatr.Col(3));
592 const Standard_Real aDet1 = aSyst.Determinant();
594 aSyst.SetCol(1, theMatr.Col(1));
595 aSyst.SetCol(2, theMatr.Col(3));
597 const Standard_Real aDet2 = aSyst.Determinant();
600 // dV1 = -dU1*aDet1/aDet
601 // dV2 = -dU1*aDet2/aDet
603 //If U1 is increased then dU1 > 0.
604 //If (aDet1/aDet > 0) then dV1 < 0 and
605 //V1 will be decreased after increasing U1.
607 //We have analogical situation with V2-parameter.
611 theV1Set = theV1AfterDecrByDelta;
616 theV2Set = theV2AfterDecrByDelta;
620 //=======================================================================
621 //function : DeltaU1Computing
622 //purpose : Computes new step for U1 parameter.
623 //=======================================================================
625 Standard_Boolean DeltaU1Computing(const math_Matrix& theSyst,
626 const math_Vector& theFree,
627 Standard_Real& theDeltaU1Found)
629 Standard_Real aDet = theSyst.Determinant();
631 if(Abs(aDet) > aNulValue)
633 math_Matrix aSyst1(theSyst);
634 aSyst1.SetCol(2, theFree);
636 theDeltaU1Found = Abs(aSyst1.Determinant()/aDet);
637 return Standard_True;
640 return Standard_False;
643 //=======================================================================
644 //function : StepComputing
648 // theMatr must have 3*5-dimension strictly.
650 // {a11*V1+a12*V2+a13*dU1+a14*dU2=b1;
651 // {a21*V1+a22*V2+a23*dU1+a24*dU2=b2;
652 // {a31*V1+a32*V2+a33*dU1+a34*dU2=b3;
653 // theMatr must be following:
654 // (a11 a12 a13 a14 b1)
655 // (a21 a22 a23 a24 b2)
656 // (a31 a32 a33 a34 b3)
657 //=======================================================================
658 static Standard_Boolean StepComputing(const math_Matrix& theMatr,
659 const Standard_Real theV1Cur,
660 const Standard_Real theV2Cur,
661 const Standard_Real theDeltaV1,
662 const Standard_Real theDeltaV2,
663 Standard_Real& theDeltaU1Found/*,
664 Standard_Real& theDeltaU2Found,
665 Standard_Real& theV1Found,
666 Standard_Real& theV2Found*/)
668 #ifdef INTPATCH_IMPIMPINTERSECTION_DEBUG
673 printf("{%+10.20f*V1 + %+10.20f*V2 + %+10.20f*dU1 + %+10.20f*dU2 = %+10.20f\n",
674 theMatr(1,1), theMatr(1,2), theMatr(1,3), theMatr(1,4), theMatr(1,5));
675 printf("{%+10.20f*V1 + %+10.20f*V2 + %+10.20f*dU1 + %+10.20f*dU2 = %+10.20f\n",
676 theMatr(2,1), theMatr(2,2), theMatr(2,3), theMatr(2,4), theMatr(2,5));
677 printf("{%+10.20f*V1 + %+10.20f*V2 + %+10.20f*dU1 + %+10.20f*dU2 = %+10.20f\n",
678 theMatr(3,1), theMatr(3,2), theMatr(3,3), theMatr(3,4), theMatr(3,5));
682 Standard_Boolean isSuccess = Standard_False;
683 theDeltaU1Found/* = theDeltaU2Found*/ = RealLast();
684 //theV1Found = theV1set;
685 //theV2Found = theV2Set;
686 const Standard_Integer aNbDim = 3;
688 math_Matrix aSyst(1, aNbDim, 1, aNbDim);
689 math_Vector aFree(1, aNbDim);
691 //By default, increasing V1(U1) and V2(U1) functions is
693 Standard_Real aV1Set = theV1Cur + theDeltaV1,
694 aV2Set = theV2Cur + theDeltaV2;
696 //However, what is indeed?
697 VBoundaryPrecise( theMatr, theV1Cur - theDeltaV1,
698 theV2Cur - theDeltaV2, aV1Set, aV2Set);
700 aSyst.SetCol(2, theMatr.Col(3));
701 aSyst.SetCol(3, theMatr.Col(4));
703 for(Standard_Integer i = 0; i < 2; i++)
707 aSyst.SetCol(1, theMatr.Col(2));
708 aFree.Set(1, aNbDim, theMatr.Col(5)-aV1Set*theMatr.Col(1));
711 {//i==1 => V2 is known
712 aSyst.SetCol(1, theMatr.Col(1));
713 aFree.Set(1, aNbDim, theMatr.Col(5)-aV2Set*theMatr.Col(2));
716 Standard_Real aNewDU = theDeltaU1Found;
717 if(DeltaU1Computing(aSyst, aFree, aNewDU))
719 isSuccess = Standard_True;
720 if(aNewDU < theDeltaU1Found)
722 theDeltaU1Found = aNewDU;
729 aFree = theMatr.Col(5) - aV1Set*theMatr.Col(1) - aV2Set*theMatr.Col(2);
730 math_Matrix aSyst1(1, aNbDim, 1, 2);
731 aSyst1.SetCol(1, aSyst.Col(2));
732 aSyst1.SetCol(2, aSyst.Col(3));
734 //Now we have overdetermined system.
736 const Standard_Real aDet1 = theMatr(1,3)*theMatr(2,4) - theMatr(2,3)*theMatr(1,4);
737 const Standard_Real aDet2 = theMatr(1,3)*theMatr(3,4) - theMatr(3,3)*theMatr(1,4);
738 const Standard_Real aDet3 = theMatr(2,3)*theMatr(3,4) - theMatr(3,3)*theMatr(2,4);
739 const Standard_Real anAbsD1 = Abs(aDet1);
740 const Standard_Real anAbsD2 = Abs(aDet2);
741 const Standard_Real anAbsD3 = Abs(aDet3);
743 if(anAbsD1 >= anAbsD2)
745 if(anAbsD1 >= anAbsD3)
748 if(anAbsD1 <= aNulValue)
751 theDeltaU1Found = Abs(aFree(1)*theMatr(2,4) - aFree(2)*theMatr(1,4))/anAbsD1;
752 isSuccess = Standard_True;
757 if(anAbsD3 <= aNulValue)
760 theDeltaU1Found = Abs(aFree(2)*theMatr(3,4) - aFree(3)*theMatr(2,4))/anAbsD3;
761 isSuccess = Standard_True;
766 if(anAbsD2 >= anAbsD3)
769 if(anAbsD2 <= aNulValue)
772 theDeltaU1Found = Abs(aFree(1)*theMatr(3,4) - aFree(3)*theMatr(1,4))/anAbsD2;
773 isSuccess = Standard_True;
778 if(anAbsD3 <= aNulValue)
781 theDeltaU1Found = Abs(aFree(2)*theMatr(3,4) - aFree(3)*theMatr(2,4))/anAbsD3;
782 isSuccess = Standard_True;
790 //=======================================================================
791 //function : ProcessBounds
793 //=======================================================================
794 void ProcessBounds(const Handle(IntPatch_ALine)& alig, //-- ligne courante
795 const IntPatch_SequenceOfLine& slin,
796 const IntSurf_Quadric& Quad1,
797 const IntSurf_Quadric& Quad2,
798 Standard_Boolean& procf,
799 const gp_Pnt& ptf, //-- Debut Ligne Courante
800 const Standard_Real first, //-- Paramf
801 Standard_Boolean& procl,
802 const gp_Pnt& ptl, //-- Fin Ligne courante
803 const Standard_Real last, //-- Paraml
804 Standard_Boolean& Multpoint,
805 const Standard_Real Tol)
807 Standard_Integer j,k;
808 Standard_Real U1,V1,U2,V2;
809 IntPatch_Point ptsol;
812 if (procf && procl) {
813 j = slin.Length() + 1;
820 //-- On prend les lignes deja enregistrees
822 while (j <= slin.Length()) {
823 if(slin.Value(j)->ArcType() == IntPatch_Analytic) {
824 const Handle(IntPatch_ALine)& aligold = *((Handle(IntPatch_ALine)*)&slin.Value(j));
827 //-- On prend les vertex des lignes deja enregistrees
829 while (k <= aligold->NbVertex()) {
830 ptsol = aligold->Vertex(k);
832 d=ptf.Distance(ptsol.Value());
834 ptsol.SetTolerance(Tol);
835 if (!ptsol.IsMultiple()) {
836 //-- le point ptsol (de aligold) est declare multiple sur aligold
837 Multpoint = Standard_True;
838 ptsol.SetMultiple(Standard_True);
839 aligold->Replace(k,ptsol);
841 ptsol.SetParameter(first);
842 alig->AddVertex(ptsol);
843 alig->SetFirstPoint(alig->NbVertex());
844 procf = Standard_True;
846 //-- On restore le point avec son parametre sur aligold
847 ptsol = aligold->Vertex(k);
852 if (ptl.Distance(ptsol.Value()) <= Tol) {
853 ptsol.SetTolerance(Tol);
854 if (!ptsol.IsMultiple()) {
855 Multpoint = Standard_True;
856 ptsol.SetMultiple(Standard_True);
857 aligold->Replace(k,ptsol);
859 ptsol.SetParameter(last);
860 alig->AddVertex(ptsol);
861 alig->SetLastPoint(alig->NbVertex());
862 procl = Standard_True;
864 //-- On restore le point avec son parametre sur aligold
865 ptsol = aligold->Vertex(k);
869 if (procf && procl) {
870 k = aligold->NbVertex()+1;
876 if (procf && procl) {
885 ptsol.SetTolerance(Tol);
886 if (!procf && !procl) {
887 Quad1.Parameters(ptf,U1,V1);
888 Quad2.Parameters(ptf,U2,V2);
889 ptsol.SetValue(ptf,Tol,Standard_False);
890 ptsol.SetParameters(U1,V1,U2,V2);
891 ptsol.SetParameter(first);
892 if (ptf.Distance(ptl) <= Tol) {
893 ptsol.SetMultiple(Standard_True); // a voir
894 Multpoint = Standard_True; // a voir de meme
895 alig->AddVertex(ptsol);
896 alig->SetFirstPoint(alig->NbVertex());
898 ptsol.SetParameter(last);
899 alig->AddVertex(ptsol);
900 alig->SetLastPoint(alig->NbVertex());
903 alig->AddVertex(ptsol);
904 alig->SetFirstPoint(alig->NbVertex());
905 Quad1.Parameters(ptl,U1,V1);
906 Quad2.Parameters(ptl,U2,V2);
907 ptsol.SetValue(ptl,Tol,Standard_False);
908 ptsol.SetParameters(U1,V1,U2,V2);
909 ptsol.SetParameter(last);
910 alig->AddVertex(ptsol);
911 alig->SetLastPoint(alig->NbVertex());
915 Quad1.Parameters(ptf,U1,V1);
916 Quad2.Parameters(ptf,U2,V2);
917 ptsol.SetValue(ptf,Tol,Standard_False);
918 ptsol.SetParameters(U1,V1,U2,V2);
919 ptsol.SetParameter(first);
920 alig->AddVertex(ptsol);
921 alig->SetFirstPoint(alig->NbVertex());
924 Quad1.Parameters(ptl,U1,V1);
925 Quad2.Parameters(ptl,U2,V2);
926 ptsol.SetValue(ptl,Tol,Standard_False);
927 ptsol.SetParameters(U1,V1,U2,V2);
928 ptsol.SetParameter(last);
929 alig->AddVertex(ptsol);
930 alig->SetLastPoint(alig->NbVertex());
934 //=======================================================================
935 //function : CyCyAnalyticalIntersect
936 //purpose : Checks if intersection curve is analytical (line, circle, ellipse)
937 // and returns these curves.
938 //=======================================================================
939 Standard_Boolean CyCyAnalyticalIntersect( const IntSurf_Quadric& Quad1,
940 const IntSurf_Quadric& Quad2,
941 const IntAna_QuadQuadGeo& theInter,
942 const Standard_Real Tol,
943 Standard_Boolean& Empty,
944 Standard_Boolean& Same,
945 Standard_Boolean& Multpoint,
946 IntPatch_SequenceOfLine& slin,
947 IntPatch_SequenceOfPoint& spnt)
949 IntPatch_Point ptsol;
953 IntSurf_TypeTrans trans1,trans2;
954 IntAna_ResultType typint;
959 gp_Cylinder Cy1(Quad1.Cylinder());
960 gp_Cylinder Cy2(Quad2.Cylinder());
962 typint = theInter.TypeInter();
963 Standard_Integer NbSol = theInter.NbSolutions();
964 Empty = Standard_False;
965 Same = Standard_False;
971 Empty = Standard_True;
977 Same = Standard_True;
983 gp_Pnt psol(theInter.Point(1));
984 ptsol.SetValue(psol,Tol,Standard_True);
986 Standard_Real U1,V1,U2,V2;
987 Quad1.Parameters(psol, U1, V1);
988 Quad2.Parameters(psol, U2, V2);
990 ptsol.SetParameters(U1,V1,U2,V2);
999 { // Cylinders are tangent to each other by line
1000 linsol = theInter.Line(1);
1001 ptref = linsol.Location();
1004 gp_Dir crb1(gp_Vec(ptref,Cy1.Location()));
1005 gp_Dir crb2(gp_Vec(ptref,Cy2.Location()));
1007 //outer normal lines
1008 gp_Vec norm1(Quad1.Normale(ptref));
1009 gp_Vec norm2(Quad2.Normale(ptref));
1010 IntSurf_Situation situcyl1;
1011 IntSurf_Situation situcyl2;
1013 if (crb1.Dot(crb2) < 0.)
1014 { // centre de courbures "opposes"
1016 // Normal and Radius-vector of the 1st(!) cylinder
1017 // is used for judging what the situation of the 2nd(!)
1020 if (norm1.Dot(crb1) > 0.)
1022 situcyl2 = IntSurf_Inside;
1026 situcyl2 = IntSurf_Outside;
1029 if (norm2.Dot(crb2) > 0.)
1031 situcyl1 = IntSurf_Inside;
1035 situcyl1 = IntSurf_Outside;
1040 if (Cy1.Radius() < Cy2.Radius())
1042 if (norm1.Dot(crb1) > 0.)
1044 situcyl2 = IntSurf_Inside;
1048 situcyl2 = IntSurf_Outside;
1051 if (norm2.Dot(crb2) > 0.)
1053 situcyl1 = IntSurf_Outside;
1057 situcyl1 = IntSurf_Inside;
1062 if (norm1.Dot(crb1) > 0.)
1064 situcyl2 = IntSurf_Outside;
1068 situcyl2 = IntSurf_Inside;
1071 if (norm2.Dot(crb2) > 0.)
1073 situcyl1 = IntSurf_Inside;
1077 situcyl1 = IntSurf_Outside;
1082 Handle(IntPatch_GLine) glig = new IntPatch_GLine(linsol, Standard_True, situcyl1, situcyl2);
1087 for (i=1; i <= NbSol; i++)
1089 linsol = theInter.Line(i);
1090 ptref = linsol.Location();
1091 gp_Vec lsd = linsol.Direction();
1093 //Theoretically, qwe = +/- 1.0.
1094 Standard_Real qwe = lsd.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref));
1095 if (qwe >0.00000001)
1097 trans1 = IntSurf_Out;
1098 trans2 = IntSurf_In;
1100 else if (qwe <-0.00000001)
1102 trans1 = IntSurf_In;
1103 trans2 = IntSurf_Out;
1107 trans1=trans2=IntSurf_Undecided;
1110 Handle(IntPatch_GLine) glig = new IntPatch_GLine(linsol, Standard_False,trans1,trans2);
1117 case IntAna_Ellipse:
1121 IntPatch_Point pmult1, pmult2;
1123 elipsol = theInter.Ellipse(1);
1125 gp_Pnt pttang1(ElCLib::Value(0.5*M_PI, elipsol));
1126 gp_Pnt pttang2(ElCLib::Value(1.5*M_PI, elipsol));
1128 Multpoint = Standard_True;
1129 pmult1.SetValue(pttang1,Tol,Standard_True);
1130 pmult2.SetValue(pttang2,Tol,Standard_True);
1131 pmult1.SetMultiple(Standard_True);
1132 pmult2.SetMultiple(Standard_True);
1134 Standard_Real oU1,oV1,oU2,oV2;
1135 Quad1.Parameters(pttang1, oU1, oV1);
1136 Quad2.Parameters(pttang1, oU2, oV2);
1138 pmult1.SetParameters(oU1,oV1,oU2,oV2);
1139 Quad1.Parameters(pttang2,oU1,oV1);
1140 Quad2.Parameters(pttang2,oU2,oV2);
1142 pmult2.SetParameters(oU1,oV1,oU2,oV2);
1144 // on traite la premiere ellipse
1146 //-- Calcul de la Transition de la ligne
1147 ElCLib::D1(0.,elipsol,ptref,Tgt);
1149 //Theoretically, qwe = +/- |Tgt|.
1150 Standard_Real qwe=Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref));
1153 trans1 = IntSurf_Out;
1154 trans2 = IntSurf_In;
1156 else if (qwe<-0.00000001)
1158 trans1 = IntSurf_In;
1159 trans2 = IntSurf_Out;
1163 trans1=trans2=IntSurf_Undecided;
1166 //-- Transition calculee au point 0 -> Trans2 , Trans1
1167 //-- car ici, on devarit calculer en PI
1168 Handle(IntPatch_GLine) glig = new IntPatch_GLine(elipsol,Standard_False,trans2,trans1);
1171 Standard_Real aU1, aV1, aU2, aV2;
1173 gp_Pnt aP (ElCLib::Value(0., elipsol));
1175 aIP.SetValue(aP,Tol,Standard_False);
1176 aIP.SetMultiple(Standard_False);
1178 Quad1.Parameters(aP, aU1, aV1);
1179 Quad2.Parameters(aP, aU2, aV2);
1181 aIP.SetParameters(aU1, aV1, aU2, aV2);
1183 aIP.SetParameter(0.);
1184 glig->AddVertex(aIP);
1185 glig->SetFirstPoint(1);
1187 aIP.SetParameter(2.*M_PI);
1188 glig->AddVertex(aIP);
1189 glig->SetLastPoint(2);
1192 pmult1.SetParameter(0.5*M_PI);
1193 glig->AddVertex(pmult1);
1195 pmult2.SetParameter(1.5*M_PI);
1196 glig->AddVertex(pmult2);
1201 //-- Transitions calculee au point 0 OK
1203 // on traite la deuxieme ellipse
1204 elipsol = theInter.Ellipse(2);
1206 Standard_Real param1 = ElCLib::Parameter(elipsol,pttang1);
1207 Standard_Real param2 = ElCLib::Parameter(elipsol,pttang2);
1208 Standard_Real parampourtransition = 0.0;
1209 if (param1 < param2)
1211 pmult1.SetParameter(0.5*M_PI);
1212 pmult2.SetParameter(1.5*M_PI);
1213 parampourtransition = M_PI;
1216 pmult1.SetParameter(1.5*M_PI);
1217 pmult2.SetParameter(0.5*M_PI);
1218 parampourtransition = 0.0;
1221 //-- Calcul des transitions de ligne pour la premiere ligne
1222 ElCLib::D1(parampourtransition,elipsol,ptref,Tgt);
1224 //Theoretically, qwe = +/- |Tgt|.
1225 qwe=Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref));
1228 trans1 = IntSurf_Out;
1229 trans2 = IntSurf_In;
1231 else if(qwe< -0.00000001)
1233 trans1 = IntSurf_In;
1234 trans2 = IntSurf_Out;
1238 trans1=trans2=IntSurf_Undecided;
1241 //-- La transition a ete calculee sur un point de cette ligne
1242 glig = new IntPatch_GLine(elipsol,Standard_False,trans1,trans2);
1245 Standard_Real aU1, aV1, aU2, aV2;
1247 gp_Pnt aP (ElCLib::Value(0., elipsol));
1249 aIP.SetValue(aP,Tol,Standard_False);
1250 aIP.SetMultiple(Standard_False);
1253 Quad1.Parameters(aP, aU1, aV1);
1254 Quad2.Parameters(aP, aU2, aV2);
1256 aIP.SetParameters(aU1, aV1, aU2, aV2);
1258 aIP.SetParameter(0.);
1259 glig->AddVertex(aIP);
1260 glig->SetFirstPoint(1);
1262 aIP.SetParameter(2.*M_PI);
1263 glig->AddVertex(aIP);
1264 glig->SetLastPoint(2);
1267 glig->AddVertex(pmult1);
1268 glig->AddVertex(pmult2);
1274 case IntAna_Parabola:
1275 case IntAna_Hyperbola:
1276 throw Standard_Failure("IntCyCy(): Wrong intersection type!");
1279 // Circle is useful when we will work with trimmed surfaces
1280 // (two cylinders can be tangent by their basises, e.g. circle)
1281 case IntAna_NoGeometricSolution:
1283 return Standard_False;
1286 return Standard_True;
1289 //=======================================================================
1290 //function : ShortCosForm
1291 //purpose : Represents theCosFactor*cosA+theSinFactor*sinA as
1292 // theCoeff*cos(A-theAngle) if it is possibly (all angles are
1294 //=======================================================================
1295 static void ShortCosForm( const Standard_Real theCosFactor,
1296 const Standard_Real theSinFactor,
1297 Standard_Real& theCoeff,
1298 Standard_Real& theAngle)
1300 theCoeff = sqrt(theCosFactor*theCosFactor+theSinFactor*theSinFactor);
1302 if(IsEqual(theCoeff, 0.0))
1308 theAngle = acos(Abs(theCosFactor/theCoeff));
1310 if(theSinFactor > 0.0)
1312 if(IsEqual(theCosFactor, 0.0))
1314 theAngle = M_PI/2.0;
1316 else if(theCosFactor < 0.0)
1318 theAngle = M_PI-theAngle;
1321 else if(IsEqual(theSinFactor, 0.0))
1323 if(theCosFactor < 0.0)
1328 if(theSinFactor < 0.0)
1330 if(theCosFactor > 0.0)
1332 theAngle = 2.0*M_PI-theAngle;
1334 else if(IsEqual(theCosFactor, 0.0))
1336 theAngle = 3.0*M_PI/2.0;
1338 else if(theCosFactor < 0.0)
1340 theAngle = M_PI+theAngle;
1345 //=======================================================================
1346 //function : CylCylMonotonicity
1347 //purpose : Determines, if U2(U1) function is increasing.
1348 //=======================================================================
1349 Standard_Boolean ComputationMethods::CylCylMonotonicity(const Standard_Real theU1par,
1350 const Standard_Integer theWLIndex,
1351 const stCoeffsValue& theCoeffs,
1352 const Standard_Real thePeriod,
1353 Standard_Boolean& theIsIncreasing)
1355 // U2(U1) = FI2 + (+/-)acos(B*cos(U1 - FI1) + C);
1357 //Func. U2(X1) = FI2 + X1;
1358 //Func. X1(X2) = anArccosFactor*X2;
1359 //Func. X2(X3) = acos(X3);
1360 //Func. X3(X4) = B*X4 + C;
1361 //Func. X4(U1) = cos(U1 - FI1).
1364 //U2(X1) is always increasing.
1365 //X1(X2) is increasing if anArccosFactor > 0.0 and
1366 //is decreasing otherwise.
1367 //X2(X3) is always decreasing.
1368 //Therefore, U2(X3) is decreasing if anArccosFactor > 0.0 and
1369 //is increasing otherwise.
1370 //X3(X4) is increasing if B > 0 and is decreasing otherwise.
1371 //X4(U1) is increasing if U1 - FI1 in [PI, 2*PI) and
1372 //is decreasing U1 - FI1 in [0, PI) or if (U1 - FI1 == 2PI).
1373 //After that, we can predict behaviour of U2(U1) function:
1374 //if it is increasing or decreasing.
1376 //For "+/-" sign. If isPlus == TRUE, "+" is chosen, otherwise, we choose "-".
1377 Standard_Boolean isPlus = Standard_False;
1382 isPlus = Standard_True;
1385 isPlus = Standard_False;
1388 //throw Standard_Failure("Error. Range Error!!!!");
1389 return Standard_False;
1392 Standard_Real aU1Temp = theU1par - theCoeffs.mFI1;
1393 InscribePoint(0, thePeriod, aU1Temp, 0.0, thePeriod, Standard_False);
1395 theIsIncreasing = Standard_True;
1397 if(((M_PI - aU1Temp) < RealSmall()) && (aU1Temp < thePeriod))
1399 theIsIncreasing = Standard_False;
1402 if(theCoeffs.mB < 0.0)
1404 theIsIncreasing = !theIsIncreasing;
1409 theIsIncreasing = !theIsIncreasing;
1412 return Standard_True;
1415 //=======================================================================
1416 //function : CylCylComputeParameters
1417 //purpose : Computes U2 (U-parameter of the 2nd cylinder) and, if theDelta != 0,
1418 // estimates the tolerance of U2-computing (estimation result is
1419 // assigned to *theDelta value).
1420 //=======================================================================
1421 Standard_Boolean ComputationMethods::CylCylComputeParameters(const Standard_Real theU1par,
1422 const Standard_Integer theWLIndex,
1423 const stCoeffsValue& theCoeffs,
1424 Standard_Real& theU2,
1425 Standard_Real* const theDelta)
1427 //This formula is got from some experience and can be changed.
1428 const Standard_Real aTol0 = Min(10.0*Epsilon(1.0)*theCoeffs.mB, aNulValue);
1429 const Standard_Real aTol = 1.0 - aTol0;
1431 if(theWLIndex < 0 || theWLIndex > 1)
1432 return Standard_False;
1434 const Standard_Real aSign = theWLIndex ? -1.0 : 1.0;
1436 Standard_Real anArg = cos(theU1par - theCoeffs.mFI1);
1437 anArg = theCoeffs.mB*anArg + theCoeffs.mC;
1446 else if(anArg <= -aTol)
1455 //There is a case, when
1456 // const double aPar = 0.99999999999721167;
1457 // const double aFI2 = 2.3593296083566181e-006;
1460 // aPar - cos(aFI2) == -5.10703e-015 ==> cos(aFI2) == aPar.
1461 //Theoreticaly, in this case
1462 // aFI2 == +/- acos(aPar).
1464 // acos(aPar) - aFI2 == 2.16362e-009.
1465 //Error is quite big.
1467 //This error should be estimated. Let use following way, which is based
1468 //on expanding to Taylor series.
1470 // acos(p)-acos(p+x) = x/sqrt(1-p*p).
1472 //If p == (1-d) (when p > 0) or p == (-1+d) (when p < 0) then
1473 // acos(p)-acos(p+x) = x/sqrt(d*(2-d)).
1475 //Here always aTol0 <= d <= 1. Max(x) is considered (!) to be equal to aTol0.
1477 // 8*aTol0 <= acos(p)-acos(p+x) <= sqrt(2/(2-aTol0)-1),
1478 // because 0 < aTol0 < 1.
1479 //E.g. when aTol0 = 1.0e-11,
1480 // 8.0e-11 <= acos(p)-acos(p+x) < 2.24e-6.
1482 const Standard_Real aDelta = Min(1.0-anArg, 1.0+anArg);
1483 Standard_DivideByZero_Raise_if((aDelta*aDelta < RealSmall()) || (aDelta >= 2.0),
1484 "IntPatch_ImpImpIntersection_4.gxx, CylCylComputeParameters()");
1485 *theDelta = aTol0/sqrt(aDelta*(2.0-aDelta));
1488 theU2 = acos(anArg);
1489 theU2 = theCoeffs.mFI2 + aSign*theU2;
1491 return Standard_True;
1494 //=======================================================================
1495 //function : CylCylComputeParameters
1496 //purpose : Computes V1 and V2 (V-parameters of the 1st and 2nd cylinder respectively).
1497 //=======================================================================
1498 Standard_Boolean ComputationMethods::CylCylComputeParameters(const Standard_Real theU1,
1499 const Standard_Real theU2,
1500 const stCoeffsValue& theCoeffs,
1501 Standard_Real& theV1,
1502 Standard_Real& theV2)
1504 theV1 = theCoeffs.mK21 * sin(theU2) +
1505 theCoeffs.mK11 * sin(theU1) +
1506 theCoeffs.mL21 * cos(theU2) +
1507 theCoeffs.mL11 * cos(theU1) + theCoeffs.mM1;
1509 theV2 = theCoeffs.mK22 * sin(theU2) +
1510 theCoeffs.mK12 * sin(theU1) +
1511 theCoeffs.mL22 * cos(theU2) +
1512 theCoeffs.mL12 * cos(theU1) + theCoeffs.mM2;
1514 return Standard_True;
1517 //=======================================================================
1518 //function : CylCylComputeParameters
1519 //purpose : Computes U2 (U-parameter of the 2nd cylinder),
1520 // V1 and V2 (V-parameters of the 1st and 2nd cylinder respectively).
1521 //=======================================================================
1522 Standard_Boolean ComputationMethods::CylCylComputeParameters(const Standard_Real theU1par,
1523 const Standard_Integer theWLIndex,
1524 const stCoeffsValue& theCoeffs,
1525 Standard_Real& theU2,
1526 Standard_Real& theV1,
1527 Standard_Real& theV2)
1529 if(!CylCylComputeParameters(theU1par, theWLIndex, theCoeffs, theU2))
1530 return Standard_False;
1532 if(!CylCylComputeParameters(theU1par, theU2, theCoeffs, theV1, theV2))
1533 return Standard_False;
1535 return Standard_True;
1538 //=======================================================================
1539 //function : SearchOnVBounds
1541 //=======================================================================
1542 Standard_Boolean WorkWithBoundaries::
1543 SearchOnVBounds(const SearchBoundType theSBType,
1544 const Standard_Real theVzad,
1545 const Standard_Real theVInit,
1546 const Standard_Real theInitU2,
1547 const Standard_Real theInitMainVar,
1548 Standard_Real& theMainVariableValue) const
1550 const Standard_Integer aNbDim = 3;
1551 const Standard_Real aMaxError = 4.0*M_PI; // two periods
1553 theMainVariableValue = theInitMainVar;
1554 const Standard_Real aTol2 = 1.0e-18;
1555 Standard_Real aMainVarPrev = theInitMainVar, aU2Prev = theInitU2, anOtherVar = theVInit;
1557 //Structure of aMatr:
1558 // C_{1}*U_{1} & C_{2}*U_{2} & C_{3}*V_{*},
1559 //where C_{1}, C_{2} and C_{3} are math_Vector.
1560 math_Matrix aMatr(1, aNbDim, 1, aNbDim);
1562 Standard_Real anError = RealLast();
1563 Standard_Real anErrorPrev = anError;
1564 Standard_Integer aNbIter = 0;
1567 if(++aNbIter > 1000)
1568 return Standard_False;
1570 const Standard_Real aSinU1 = sin(aMainVarPrev),
1571 aCosU1 = cos(aMainVarPrev),
1572 aSinU2 = sin(aU2Prev),
1573 aCosU2 = cos(aU2Prev);
1575 math_Vector aVecFreeMem = (myCoeffs.mVecA2 * aU2Prev +
1576 myCoeffs.mVecB2) * aSinU2 -
1577 (myCoeffs.mVecB2 * aU2Prev -
1578 myCoeffs.mVecA2) * aCosU2 +
1579 (myCoeffs.mVecA1 * aMainVarPrev +
1580 myCoeffs.mVecB1) * aSinU1 -
1581 (myCoeffs.mVecB1 * aMainVarPrev -
1582 myCoeffs.mVecA1) * aCosU1 +
1585 math_Vector aMSum(1, 3);
1590 aMatr.SetCol(3, myCoeffs.mVecC2);
1591 aMSum = myCoeffs.mVecC1 * theVzad;
1592 aVecFreeMem -= aMSum;
1593 aMSum += myCoeffs.mVecC2*anOtherVar;
1597 aMatr.SetCol(3, myCoeffs.mVecC1);
1598 aMSum = myCoeffs.mVecC2 * theVzad;
1599 aVecFreeMem -= aMSum;
1600 aMSum += myCoeffs.mVecC1*anOtherVar;
1604 return Standard_False;
1607 aMatr.SetCol(1, myCoeffs.mVecA1 * aSinU1 - myCoeffs.mVecB1 * aCosU1);
1608 aMatr.SetCol(2, myCoeffs.mVecA2 * aSinU2 - myCoeffs.mVecB2 * aCosU2);
1610 Standard_Real aDetMainSyst = aMatr.Determinant();
1612 if(Abs(aDetMainSyst) < aNulValue)
1614 return Standard_False;
1617 math_Matrix aM1(aMatr), aM2(aMatr), aM3(aMatr);
1618 aM1.SetCol(1, aVecFreeMem);
1619 aM2.SetCol(2, aVecFreeMem);
1620 aM3.SetCol(3, aVecFreeMem);
1622 const Standard_Real aDetMainVar = aM1.Determinant();
1623 const Standard_Real aDetVar1 = aM2.Determinant();
1624 const Standard_Real aDetVar2 = aM3.Determinant();
1626 Standard_Real aDelta = aDetMainVar/aDetMainSyst-aMainVarPrev;
1628 if(Abs(aDelta) > aMaxError)
1629 return Standard_False;
1631 anError = aDelta*aDelta;
1632 aMainVarPrev += aDelta;
1635 aDelta = aDetVar1/aDetMainSyst-aU2Prev;
1637 if(Abs(aDelta) > aMaxError)
1638 return Standard_False;
1640 anError += aDelta*aDelta;
1644 aDelta = aDetVar2/aDetMainSyst-anOtherVar;
1645 anError += aDelta*aDelta;
1646 anOtherVar += aDelta;
1648 if(anError > anErrorPrev)
1649 {//Method diverges. Keep the best result
1650 const Standard_Real aSinU1Last = sin(aMainVarPrev),
1651 aCosU1Last = cos(aMainVarPrev),
1652 aSinU2Last = sin(aU2Prev),
1653 aCosU2Last = cos(aU2Prev);
1654 aMSum -= (myCoeffs.mVecA1*aCosU1Last +
1655 myCoeffs.mVecB1*aSinU1Last +
1656 myCoeffs.mVecA2*aCosU2Last +
1657 myCoeffs.mVecB2*aSinU2Last +
1659 const Standard_Real aSQNorm = aMSum.Norm2();
1660 return (aSQNorm < aTol2);
1664 theMainVariableValue = aMainVarPrev;
1667 anErrorPrev = anError;
1669 while(anError > aTol2);
1671 theMainVariableValue = aMainVarPrev;
1673 return Standard_True;
1676 //=======================================================================
1677 //function : InscribePoint
1678 //purpose : If theFlForce==TRUE theUGiven will be changed forcefully
1679 // even if theUGiven is already inscibed in the boundary
1680 // (if it is possible; i.e. if new theUGiven is inscribed
1681 // in the boundary, too).
1682 //=======================================================================
1683 Standard_Boolean InscribePoint( const Standard_Real theUfTarget,
1684 const Standard_Real theUlTarget,
1685 Standard_Real& theUGiven,
1686 const Standard_Real theTol2D,
1687 const Standard_Real thePeriod,
1688 const Standard_Boolean theFlForce)
1690 if(Precision::IsInfinite(theUGiven))
1692 return Standard_False;
1695 if((theUfTarget - theUGiven <= theTol2D) &&
1696 (theUGiven - theUlTarget <= theTol2D))
1697 {//it has already inscribed
1706 Standard_Real anUtemp = theUGiven + thePeriod;
1707 if((theUfTarget - anUtemp <= theTol2D) &&
1708 (anUtemp - theUlTarget <= theTol2D))
1710 theUGiven = anUtemp;
1711 return Standard_True;
1714 anUtemp = theUGiven - thePeriod;
1715 if((theUfTarget - anUtemp <= theTol2D) &&
1716 (anUtemp - theUlTarget <= theTol2D))
1718 theUGiven = anUtemp;
1722 return Standard_True;
1725 const Standard_Real aUf = theUfTarget - theTol2D;
1726 const Standard_Real aUl = aUf + thePeriod;
1728 theUGiven = ElCLib::InPeriod(theUGiven, aUf, aUl);
1730 return ((theUfTarget - theUGiven <= theTol2D) &&
1731 (theUGiven - theUlTarget <= theTol2D));
1734 //=======================================================================
1735 //function : InscribeInterval
1736 //purpose : Shifts theRange in order to make at least one of its
1737 // boundary in the range [theUfTarget, theUlTarget]
1738 //=======================================================================
1739 static Standard_Boolean InscribeInterval(const Standard_Real theUfTarget,
1740 const Standard_Real theUlTarget,
1741 Bnd_Range &theRange,
1742 const Standard_Real theTol2D,
1743 const Standard_Real thePeriod)
1745 Standard_Real anUpar = 0.0;
1746 if (!theRange.GetMin(anUpar))
1748 return Standard_False;
1751 const Standard_Real aDelta = theRange.Delta();
1752 if(InscribePoint(theUfTarget, theUlTarget, anUpar,
1753 theTol2D, thePeriod, (Abs(theUlTarget-anUpar) < theTol2D)))
1756 theRange.Add(anUpar);
1757 theRange.Add(anUpar + aDelta);
1761 if (!theRange.GetMax (anUpar))
1763 return Standard_False;
1766 if(InscribePoint(theUfTarget, theUlTarget, anUpar,
1767 theTol2D, thePeriod, (Abs(theUfTarget-anUpar) < theTol2D)))
1770 theRange.Add(anUpar);
1771 theRange.Add(anUpar - aDelta);
1775 return Standard_False;
1779 return Standard_True;
1782 //=======================================================================
1783 //function : ExcludeNearElements
1784 //purpose : Checks if theArr contains two almost equal elements.
1785 // If it is true then one of equal elements will be excluded
1787 // Returns TRUE if at least one element of theArr has been changed.
1789 // 1. Every not infinite element of theArr is considered to be
1790 // in [0, T] interval (where T is the period);
1791 // 2. theArr must be sorted in ascending order.
1792 //=======================================================================
1793 static Standard_Boolean ExcludeNearElements(Standard_Real theArr[],
1794 const Standard_Integer theNOfMembers,
1795 const Standard_Real theUSurf1f,
1796 const Standard_Real theUSurf1l,
1797 const Standard_Real theTol)
1799 Standard_Boolean aRetVal = Standard_False;
1800 for(Standard_Integer i = 1; i < theNOfMembers; i++)
1802 Standard_Real &anA = theArr[i],
1807 if(Precision::IsInfinite(anA))
1810 if((anA-anB) < theTol)
1812 if((anB != 0.0) && (anB != theUSurf1f) && (anB != theUSurf1l))
1813 anA = (anA + anB)/2.0;
1817 //Make this element infinite an forget it
1818 //(we will not use it in next iterations).
1819 anB = Precision::Infinite();
1820 aRetVal = Standard_True;
1827 //=======================================================================
1828 //function : AddPointIntoWL
1829 //purpose : Surf1 is a surface, whose U-par is variable.
1830 // If theFlBefore == TRUE then we enable the U1-parameter
1831 // of the added point to be less than U1-parameter of
1832 // previously added point (in general U1-parameter is
1833 // always increased; therefore, this situation is abnormal).
1834 // If theOnlyCheck==TRUE then no point will be added to theLine.
1835 //=======================================================================
1836 static Standard_Boolean AddPointIntoWL( const IntSurf_Quadric& theQuad1,
1837 const IntSurf_Quadric& theQuad2,
1838 const ComputationMethods::stCoeffsValue& theCoeffs,
1839 const Standard_Boolean isTheReverse,
1840 const Standard_Boolean isThePrecise,
1841 const gp_Pnt2d& thePntOnSurf1,
1842 const gp_Pnt2d& thePntOnSurf2,
1843 const Standard_Real theUfSurf1,
1844 const Standard_Real theUlSurf1,
1845 const Standard_Real theUfSurf2,
1846 const Standard_Real theUlSurf2,
1847 const Standard_Real theVfSurf1,
1848 const Standard_Real theVlSurf1,
1849 const Standard_Real theVfSurf2,
1850 const Standard_Real theVlSurf2,
1851 const Standard_Real thePeriodOfSurf1,
1852 const Handle(IntSurf_LineOn2S)& theLine,
1853 const Standard_Integer theWLIndex,
1854 const Standard_Real theTol3D,
1855 const Standard_Real theTol2D,
1856 const Standard_Boolean theFlBefore = Standard_False,
1857 const Standard_Boolean theOnlyCheck = Standard_False)
1859 //Check if the point is in the domain or can be inscribed in the domain after adjusting.
1861 gp_Pnt aPt1(theQuad1.Value(thePntOnSurf1.X(), thePntOnSurf1.Y())),
1862 aPt2(theQuad2.Value(thePntOnSurf2.X(), thePntOnSurf2.Y()));
1864 Standard_Real aU1par = thePntOnSurf1.X();
1866 // aU1par always increases. Therefore, we must reduce its
1867 // value in order to continue creation of WLine.
1868 if(!InscribePoint(theUfSurf1, theUlSurf1, aU1par, theTol2D,
1869 thePeriodOfSurf1, aU1par > 0.5*(theUfSurf1+theUlSurf1)))
1870 return Standard_False;
1872 if ((theLine->NbPoints() > 0) &&
1873 ((theUlSurf1 - theUfSurf1) >= thePeriodOfSurf1) &&
1874 (((aU1par + thePeriodOfSurf1 - theUlSurf1) <= theTol2D) ||
1875 ((aU1par - thePeriodOfSurf1 - theUfSurf1) >= theTol2D)))
1877 // aU1par can be adjusted to both theUlSurf1 and theUfSurf1
1878 // with equal possibilities. This code fragment allows choosing
1879 // correct parameter from these two variants.
1881 Standard_Real aU1 = 0.0, aV1 = 0.0;
1884 theLine->Value(theLine->NbPoints()).ParametersOnS2(aU1, aV1);
1888 theLine->Value(theLine->NbPoints()).ParametersOnS1(aU1, aV1);
1891 const Standard_Real aDelta = aU1 - aU1par;
1892 if (2.0*Abs(aDelta) > thePeriodOfSurf1)
1894 aU1par += Sign(thePeriodOfSurf1, aDelta);
1898 Standard_Real aU2par = thePntOnSurf2.X();
1899 if(!InscribePoint(theUfSurf2, theUlSurf2, aU2par, theTol2D,
1900 thePeriodOfSurf1, Standard_False))
1901 return Standard_False;
1903 Standard_Real aV1par = thePntOnSurf1.Y();
1904 if((aV1par - theVlSurf1 > theTol2D) || (theVfSurf1 - aV1par > theTol2D))
1905 return Standard_False;
1907 Standard_Real aV2par = thePntOnSurf2.Y();
1908 if((aV2par - theVlSurf2 > theTol2D) || (theVfSurf2 - aV2par > theTol2D))
1909 return Standard_False;
1911 //Get intersection point and add it in the WL
1912 IntSurf_PntOn2S aPnt;
1916 aPnt.SetValue((aPt1.XYZ()+aPt2.XYZ())/2.0,
1922 aPnt.SetValue((aPt1.XYZ()+aPt2.XYZ())/2.0,
1927 Standard_Integer aNbPnts = theLine->NbPoints();
1930 Standard_Real aUl = 0.0, aVl = 0.0;
1931 const IntSurf_PntOn2S aPlast = theLine->Value(aNbPnts);
1933 aPlast.ParametersOnS2(aUl, aVl);
1935 aPlast.ParametersOnS1(aUl, aVl);
1937 if(!theFlBefore && (aU1par <= aUl))
1939 //Parameter value must be increased if theFlBefore == FALSE.
1941 aU1par += thePeriodOfSurf1;
1943 //The condition is as same as in
1944 //InscribePoint(...) function
1945 if((theUfSurf1 - aU1par > theTol2D) ||
1946 (aU1par - theUlSurf1 > theTol2D))
1948 //New aU1par is out of target interval.
1949 //Go back to old value.
1951 return Standard_False;
1956 return Standard_True;
1958 //theTol2D is minimal step along parameter changed.
1959 //Therefore, if we apply this minimal step two
1960 //neighbour points will be always "same". Consequently,
1961 //we should reduce tolerance for IsSame checking.
1962 const Standard_Real aDTol = 1.0-Epsilon(1.0);
1963 if(aPnt.IsSame(aPlast, theTol3D*aDTol, theTol2D*aDTol))
1965 theLine->RemovePoint(aNbPnts);
1970 return Standard_True;
1975 return Standard_True;
1977 //Try to precise existing WLine
1978 aNbPnts = theLine->NbPoints();
1981 Standard_Real aU1 = 0.0, aU2 = 0.0, aU3 = 0.0, aV = 0.0;
1984 theLine->Value(aNbPnts).ParametersOnS2(aU3, aV);
1985 theLine->Value(aNbPnts-1).ParametersOnS2(aU2, aV);
1986 theLine->Value(aNbPnts-2).ParametersOnS2(aU1, aV);
1990 theLine->Value(aNbPnts).ParametersOnS1(aU3, aV);
1991 theLine->Value(aNbPnts-1).ParametersOnS1(aU2, aV);
1992 theLine->Value(aNbPnts-2).ParametersOnS1(aU1, aV);
1995 const Standard_Real aStepPrev = aU2-aU1;
1996 const Standard_Real aStep = aU3-aU2;
1998 const Standard_Integer aDeltaStep = RealToInt(aStepPrev/aStep);
2000 if((1 < aDeltaStep) && (aDeltaStep < 2000))
2002 //Add new points in case of non-uniform distribution of existing points
2003 SeekAdditionalPoints( theQuad1, theQuad2, theLine,
2004 theCoeffs, theWLIndex, aDeltaStep, aNbPnts-2,
2005 aNbPnts-1, theTol2D, thePeriodOfSurf1, isTheReverse);
2009 return Standard_True;
2012 //=======================================================================
2013 //function : AddBoundaryPoint
2014 //purpose : Find intersection point on V-boundary.
2015 //=======================================================================
2016 void WorkWithBoundaries::AddBoundaryPoint(const Handle(IntPatch_WLine)& theWL,
2017 const Standard_Real theU1,
2018 const Standard_Real theU1Min,
2019 const Standard_Real theU2,
2020 const Standard_Real theV1,
2021 const Standard_Real theV1Prev,
2022 const Standard_Real theV2,
2023 const Standard_Real theV2Prev,
2024 const Standard_Integer theWLIndex,
2025 const Standard_Boolean theFlForce,
2026 Standard_Boolean& isTheFound1,
2027 Standard_Boolean& isTheFound2) const
2029 Standard_Real aUSurf1f = 0.0, //const
2033 Standard_Real aUSurf2f = 0.0, //const
2038 myUVSurf1.Get(aUSurf1f, aVSurf1f, aUSurf1l, aVSurf1l);
2039 myUVSurf2.Get(aUSurf2f, aVSurf2f, aUSurf2l, aVSurf2l);
2041 const Standard_Integer aSize = 4;
2042 const Standard_Real anArrVzad[aSize] = {aVSurf1f, aVSurf1l, aVSurf2f, aVSurf2l};
2044 StPInfo aUVPoint[aSize];
2046 for(Standard_Integer anIDSurf = 0; anIDSurf < 4; anIDSurf+=2)
2048 const Standard_Real aVf = (anIDSurf == 0) ? theV1 : theV2,
2049 aVl = (anIDSurf == 0) ? theV1Prev : theV2Prev;
2051 const SearchBoundType aTS = (anIDSurf == 0) ? SearchV1 : SearchV2;
2053 for(Standard_Integer anIDBound = 0; anIDBound < 2; anIDBound++)
2055 const Standard_Integer anIndex = anIDSurf+anIDBound;
2057 aUVPoint[anIndex].mySurfID = anIDSurf;
2059 if((Abs(aVf-anArrVzad[anIndex]) > myTol2D) &&
2060 ((aVf-anArrVzad[anIndex])*(aVl-anArrVzad[anIndex]) > 0.0))
2065 //Segment [aVf, aVl] intersects at least one V-boundary (first or last)
2066 // (in general, case is possible, when aVf > aVl).
2068 // Precise intersection point
2069 const Standard_Boolean aRes = SearchOnVBounds(aTS, anArrVzad[anIndex],
2070 (anIDSurf == 0) ? theV2 : theV1,
2072 aUVPoint[anIndex].myU1);
2074 // aUVPoint[anIndex].myU1 is considered to be nearer to theU1 than
2075 // to theU1+/-Period
2076 if (!aRes || (aUVPoint[anIndex].myU1 >= theU1) ||
2077 (aUVPoint[anIndex].myU1 < theU1Min))
2079 //Intersection point is not found or out of the domain
2080 aUVPoint[anIndex].myU1 = RealLast();
2085 //intersection point is found
2087 Standard_Real &aU1 = aUVPoint[anIndex].myU1,
2088 &aU2 = aUVPoint[anIndex].myU2,
2089 &aV1 = aUVPoint[anIndex].myV1,
2090 &aV2 = aUVPoint[anIndex].myV2;
2095 if(!ComputationMethods::
2096 CylCylComputeParameters(aU1, theWLIndex, myCoeffs, aU2, aV1, aV2))
2098 // Found point is wrong
2103 //Point on true V-boundary.
2105 aV1 = anArrVzad[anIndex];
2106 else //if(aTS[anIndex] == SearchV2)
2107 aV2 = anArrVzad[anIndex];
2112 // Sort with acceding U1-parameter.
2113 std::sort(aUVPoint, aUVPoint+aSize);
2115 isTheFound1 = isTheFound2 = Standard_False;
2117 //Adding found points on boundary in the WLine.
2118 for(Standard_Integer i = 0; i < aSize; i++)
2120 if(aUVPoint[i].myU1 == RealLast())
2123 if(!AddPointIntoWL(myQuad1, myQuad2, myCoeffs, myIsReverse, Standard_False,
2124 gp_Pnt2d(aUVPoint[i].myU1, aUVPoint[i].myV1),
2125 gp_Pnt2d(aUVPoint[i].myU2, aUVPoint[i].myV2),
2126 aUSurf1f, aUSurf1l, aUSurf2f, aUSurf2l,
2127 aVSurf1f, aVSurf1l, aVSurf2f, aVSurf2l, myPeriod,
2128 theWL->Curve(), theWLIndex, myTol3D, myTol2D, theFlForce))
2133 if(aUVPoint[i].mySurfID == 0)
2135 isTheFound1 = Standard_True;
2139 isTheFound2 = Standard_True;
2144 //=======================================================================
2145 //function : SeekAdditionalPoints
2146 //purpose : Inserts additional intersection points between neighbor points.
2147 // This action is bone with several iterations. During every iteration,
2148 // new point is inserted in middle of every interval.
2149 // The process will be finished if NbPoints >= theMinNbPoints.
2150 //=======================================================================
2151 static void SeekAdditionalPoints( const IntSurf_Quadric& theQuad1,
2152 const IntSurf_Quadric& theQuad2,
2153 const Handle(IntSurf_LineOn2S)& theLine,
2154 const ComputationMethods::stCoeffsValue& theCoeffs,
2155 const Standard_Integer theWLIndex,
2156 const Standard_Integer theMinNbPoints,
2157 const Standard_Integer theStartPointOnLine,
2158 const Standard_Integer theEndPointOnLine,
2159 const Standard_Real theTol2D,
2160 const Standard_Real thePeriodOfSurf2,
2161 const Standard_Boolean isTheReverse)
2163 if(theLine.IsNull())
2166 Standard_Integer aNbPoints = theEndPointOnLine - theStartPointOnLine + 1;
2167 if(aNbPoints >= theMinNbPoints)
2172 Standard_Real aMinDeltaParam = theTol2D;
2175 Standard_Real u1 = 0.0, v1 = 0.0, u2 = 0.0, v2 = 0.0;
2179 theLine->Value(theStartPointOnLine).ParametersOnS2(u1, v1);
2180 theLine->Value(theEndPointOnLine).ParametersOnS2(u2, v2);
2184 theLine->Value(theStartPointOnLine).ParametersOnS1(u1, v1);
2185 theLine->Value(theEndPointOnLine).ParametersOnS1(u2, v2);
2188 aMinDeltaParam = Max(Abs(u2 - u1)/IntToReal(theMinNbPoints), aMinDeltaParam);
2191 Standard_Integer aLastPointIndex = theEndPointOnLine;
2192 Standard_Real U1prec = 0.0, V1prec = 0.0, U2prec = 0.0, V2prec = 0.0;
2194 Standard_Integer aNbPointsPrev = 0;
2195 while(aNbPoints < theMinNbPoints && (aNbPoints != aNbPointsPrev))
2197 aNbPointsPrev = aNbPoints;
2198 for(Standard_Integer fp = theStartPointOnLine, lp = 0; fp < aLastPointIndex; fp = lp + 1)
2200 Standard_Real U1f = 0.0, V1f = 0.0; //first point in 1st suraface
2201 Standard_Real U1l = 0.0, V1l = 0.0; //last point in 1st suraface
2203 Standard_Real U2f = 0.0, V2f = 0.0; //first point in 2nd suraface
2204 Standard_Real U2l = 0.0, V2l = 0.0; //last point in 2nd suraface
2210 theLine->Value(fp).ParametersOnS2(U1f, V1f);
2211 theLine->Value(lp).ParametersOnS2(U1l, V1l);
2213 theLine->Value(fp).ParametersOnS1(U2f, V2f);
2214 theLine->Value(lp).ParametersOnS1(U2l, V2l);
2218 theLine->Value(fp).ParametersOnS1(U1f, V1f);
2219 theLine->Value(lp).ParametersOnS1(U1l, V1l);
2221 theLine->Value(fp).ParametersOnS2(U2f, V2f);
2222 theLine->Value(lp).ParametersOnS2(U2l, V2l);
2225 if(Abs(U1l - U1f) <= aMinDeltaParam)
2227 //Step is minimal. It is not necessary to divide it.
2231 U1prec = 0.5*(U1f+U1l);
2233 if(!ComputationMethods::
2234 CylCylComputeParameters(U1prec, theWLIndex, theCoeffs, U2prec, V1prec, V2prec))
2240 if(!InscribePoint(U2f, U2l, U2prec, theTol2D, thePeriodOfSurf2, Standard_False))
2245 const gp_Pnt aP1(theQuad1.Value(U1prec, V1prec)), aP2(theQuad2.Value(U2prec, V2prec));
2246 const gp_Pnt aPInt(0.5*(aP1.XYZ() + aP2.XYZ()));
2248 #ifdef INTPATCH_IMPIMPINTERSECTION_DEBUG
2249 std::cout << "|P1Pi| = " << aP1.SquareDistance(aPInt) << "; |P2Pi| = " << aP2.SquareDistance(aPInt) << std::endl;
2252 IntSurf_PntOn2S anIP;
2255 anIP.SetValue(aPInt, U2prec, V2prec, U1prec, V1prec);
2259 anIP.SetValue(aPInt, U1prec, V1prec, U2prec, V2prec);
2262 theLine->InsertBefore(lp, anIP);
2268 if(aNbPoints >= theMinNbPoints)
2275 //=======================================================================
2276 //function : BoundariesComputing
2277 //purpose : Computes true domain of future intersection curve (allows
2278 // avoiding excess iterations)
2279 //=======================================================================
2280 Standard_Boolean WorkWithBoundaries::
2281 BoundariesComputing(const ComputationMethods::stCoeffsValue &theCoeffs,
2282 const Standard_Real thePeriod,
2283 Bnd_Range theURange[])
2285 //All comments to this method is related to the comment
2286 //to ComputationMethods class
2288 //So, we have the equation
2289 // cos(U2-FI2)=B*cos(U1-FI1)+C
2291 // -1 <= B*cos(U1-FI1)+C <= 1
2293 if (theCoeffs.mB > 0.0)
2295 // -(1+C)/B <= cos(U1-FI1) <= (1-C)/B
2297 if (theCoeffs.mB + Abs(theCoeffs.mC) < -1.0)
2299 //(1-C)/B < -1 or -(1+C)/B > 1 ==> No solution
2301 return Standard_False;
2303 else if (theCoeffs.mB + Abs(theCoeffs.mC) <= 1.0)
2305 //(1-C)/B >= 1 and -(1+C)/B <= -1 ==> U=[0;2*PI]+aFI1
2306 theURange[0].Add(theCoeffs.mFI1);
2307 theURange[0].Add(thePeriod + theCoeffs.mFI1);
2309 else if ((1 + theCoeffs.mC <= theCoeffs.mB) &&
2310 (theCoeffs.mB <= 1 - theCoeffs.mC))
2312 //(1-C)/B >= 1 and -(1+C)/B >= -1 ==>
2313 //(U=[0;aDAngle]+aFI1) || (U=[2*PI-aDAngle;2*PI]+aFI1),
2314 //where aDAngle = acos(-(myCoeffs.mC + 1) / myCoeffs.mB)
2316 Standard_Real anArg = -(theCoeffs.mC + 1) / theCoeffs.mB;
2322 const Standard_Real aDAngle = acos(anArg);
2323 theURange[0].Add(theCoeffs.mFI1);
2324 theURange[0].Add(aDAngle + theCoeffs.mFI1);
2325 theURange[1].Add(thePeriod - aDAngle + theCoeffs.mFI1);
2326 theURange[1].Add(thePeriod + theCoeffs.mFI1);
2328 else if ((1 - theCoeffs.mC <= theCoeffs.mB) &&
2329 (theCoeffs.mB <= 1 + theCoeffs.mC))
2331 //(1-C)/B <= 1 and -(1+C)/B <= -1 ==> U=[aDAngle;2*PI-aDAngle]+aFI1
2332 //where aDAngle = acos((1 - myCoeffs.mC) / myCoeffs.mB)
2334 Standard_Real anArg = (1 - theCoeffs.mC) / theCoeffs.mB;
2340 const Standard_Real aDAngle = acos(anArg);
2341 theURange[0].Add(aDAngle + theCoeffs.mFI1);
2342 theURange[0].Add(thePeriod - aDAngle + theCoeffs.mFI1);
2344 else if (theCoeffs.mB - Abs(theCoeffs.mC) >= 1.0)
2346 //(1-C)/B <= 1 and -(1+C)/B >= -1 ==>
2347 //(U=[aDAngle1;aDAngle2]+aFI1) ||
2348 //(U=[2*PI-aDAngle2;2*PI-aDAngle1]+aFI1)
2349 //where aDAngle1 = acos((1 - myCoeffs.mC) / myCoeffs.mB),
2350 // aDAngle2 = acos(-(myCoeffs.mC + 1) / myCoeffs.mB).
2352 Standard_Real anArg1 = (1 - theCoeffs.mC) / theCoeffs.mB,
2353 anArg2 = -(theCoeffs.mC + 1) / theCoeffs.mB;
2364 const Standard_Real aDAngle1 = acos(anArg1), aDAngle2 = acos(anArg2);
2365 //(U=[aDAngle1;aDAngle2]+aFI1) ||
2366 //(U=[2*PI-aDAngle2;2*PI-aDAngle1]+aFI1)
2367 theURange[0].Add(aDAngle1 + theCoeffs.mFI1);
2368 theURange[0].Add(aDAngle2 + theCoeffs.mFI1);
2369 theURange[1].Add(thePeriod - aDAngle2 + theCoeffs.mFI1);
2370 theURange[1].Add(thePeriod - aDAngle1 + theCoeffs.mFI1);
2374 return Standard_False;
2377 else if (theCoeffs.mB < 0.0)
2379 // (1-C)/B <= cos(U1-FI1) <= -(1+C)/B
2381 if (theCoeffs.mB + Abs(theCoeffs.mC) > 1.0)
2383 // -(1+C)/B < -1 or (1-C)/B > 1 ==> No solutions
2384 return Standard_False;
2386 else if (-theCoeffs.mB + Abs(theCoeffs.mC) <= 1.0)
2388 // -(1+C)/B >= 1 and (1-C)/B <= -1 ==> U=[0;2*PI]+aFI1
2389 theURange[0].Add(theCoeffs.mFI1);
2390 theURange[0].Add(thePeriod + theCoeffs.mFI1);
2392 else if ((-theCoeffs.mC - 1 <= theCoeffs.mB) &&
2393 (theCoeffs.mB <= theCoeffs.mC - 1))
2395 // -(1+C)/B >= 1 and (1-C)/B >= -1 ==>
2396 //(U=[0;aDAngle]+aFI1) || (U=[2*PI-aDAngle;2*PI]+aFI1),
2397 //where aDAngle = acos((1 - myCoeffs.mC) / myCoeffs.mB)
2399 Standard_Real anArg = (1 - theCoeffs.mC) / theCoeffs.mB;
2405 const Standard_Real aDAngle = acos(anArg);
2406 theURange[0].Add(theCoeffs.mFI1);
2407 theURange[0].Add(aDAngle + theCoeffs.mFI1);
2408 theURange[1].Add(thePeriod - aDAngle + theCoeffs.mFI1);
2409 theURange[1].Add(thePeriod + theCoeffs.mFI1);
2411 else if ((theCoeffs.mC - 1 <= theCoeffs.mB) &&
2412 (theCoeffs.mB <= -theCoeffs.mB - 1))
2414 // -(1+C)/B <= 1 and (1-C)/B <= -1 ==> U=[aDAngle;2*PI-aDAngle]+aFI1,
2415 //where aDAngle = acos(-(myCoeffs.mC + 1) / myCoeffs.mB).
2417 Standard_Real anArg = -(theCoeffs.mC + 1) / theCoeffs.mB;
2423 const Standard_Real aDAngle = acos(anArg);
2424 theURange[0].Add(aDAngle + theCoeffs.mFI1);
2425 theURange[0].Add(thePeriod - aDAngle + theCoeffs.mFI1);
2427 else if (-theCoeffs.mB - Abs(theCoeffs.mC) >= 1.0)
2429 // -(1+C)/B <= 1 and (1-C)/B >= -1 ==>
2430 //(U=[aDAngle1;aDAngle2]+aFI1) || (U=[2*PI-aDAngle2;2*PI-aDAngle1]+aFI1),
2431 //where aDAngle1 = acos(-(myCoeffs.mC + 1) / myCoeffs.mB),
2432 // aDAngle2 = acos((1 - myCoeffs.mC) / myCoeffs.mB)
2434 Standard_Real anArg1 = -(theCoeffs.mC + 1) / theCoeffs.mB,
2435 anArg2 = (1 - theCoeffs.mC) / theCoeffs.mB;
2446 const Standard_Real aDAngle1 = acos(anArg1), aDAngle2 = acos(anArg2);
2447 theURange[0].Add(aDAngle1 + theCoeffs.mFI1);
2448 theURange[0].Add(aDAngle2 + theCoeffs.mFI1);
2449 theURange[1].Add(thePeriod - aDAngle2 + theCoeffs.mFI1);
2450 theURange[1].Add(thePeriod - aDAngle1 + theCoeffs.mFI1);
2454 return Standard_False;
2459 return Standard_False;
2462 return Standard_True;
2465 //=======================================================================
2466 //function : CriticalPointsComputing
2467 //purpose : theNbCritPointsMax contains true number of critical points.
2468 // It must be initialized correctly before function calling
2469 //=======================================================================
2470 static void CriticalPointsComputing(const ComputationMethods::stCoeffsValue& theCoeffs,
2471 const Standard_Real theUSurf1f,
2472 const Standard_Real theUSurf1l,
2473 const Standard_Real theUSurf2f,
2474 const Standard_Real theUSurf2l,
2475 const Standard_Real thePeriod,
2476 const Standard_Real theTol2D,
2477 Standard_Integer& theNbCritPointsMax,
2478 Standard_Real theU1crit[])
2480 //[0...1] - in these points parameter U1 goes through
2481 // the seam-edge of the first cylinder.
2482 //[2...3] - First and last U1 parameter.
2483 //[4...5] - in these points parameter U2 goes through
2484 // the seam-edge of the second cylinder.
2485 //[6...9] - in these points an intersection line goes through
2486 // U-boundaries of the second surface.
2487 //[10...11] - Boundary of monotonicity interval of U2(U1) function
2488 // (see CylCylMonotonicity() function)
2491 theU1crit[1] = thePeriod;
2492 theU1crit[2] = theUSurf1f;
2493 theU1crit[3] = theUSurf1l;
2495 const Standard_Real aCOS = cos(theCoeffs.mFI2);
2496 const Standard_Real aBSB = Abs(theCoeffs.mB);
2497 if((theCoeffs.mC - aBSB <= aCOS) && (aCOS <= theCoeffs.mC + aBSB))
2499 Standard_Real anArg = (aCOS - theCoeffs.mC) / theCoeffs.mB;
2505 theU1crit[4] = -acos(anArg) + theCoeffs.mFI1;
2506 theU1crit[5] = acos(anArg) + theCoeffs.mFI1;
2509 Standard_Real aSf = cos(theUSurf2f - theCoeffs.mFI2);
2510 Standard_Real aSl = cos(theUSurf2l - theCoeffs.mFI2);
2513 //In accorance with pure mathematic, theU1crit[6] and [8]
2514 //must be -Precision::Infinite() instead of used +Precision::Infinite()
2515 theU1crit[6] = Abs((aSl - theCoeffs.mC) / theCoeffs.mB) < 1.0 ?
2516 -acos((aSl - theCoeffs.mC) / theCoeffs.mB) + theCoeffs.mFI1 :
2517 Precision::Infinite();
2518 theU1crit[7] = Abs((aSf - theCoeffs.mC) / theCoeffs.mB) < 1.0 ?
2519 -acos((aSf - theCoeffs.mC) / theCoeffs.mB) + theCoeffs.mFI1 :
2520 Precision::Infinite();
2521 theU1crit[8] = Abs((aSf - theCoeffs.mC) / theCoeffs.mB) < 1.0 ?
2522 acos((aSf - theCoeffs.mC) / theCoeffs.mB) + theCoeffs.mFI1 :
2523 Precision::Infinite();
2524 theU1crit[9] = Abs((aSl - theCoeffs.mC) / theCoeffs.mB) < 1.0 ?
2525 acos((aSl - theCoeffs.mC) / theCoeffs.mB) + theCoeffs.mFI1 :
2526 Precision::Infinite();
2528 theU1crit[10] = theCoeffs.mFI1;
2529 theU1crit[11] = M_PI+theCoeffs.mFI1;
2531 //preparative treatment of array. This array must have faled to contain negative
2534 for(Standard_Integer i = 0; i < theNbCritPointsMax; i++)
2536 if(Precision::IsInfinite(theU1crit[i]))
2541 theU1crit[i] = fmod(theU1crit[i], thePeriod);
2542 if(theU1crit[i] < 0.0)
2543 theU1crit[i] += thePeriod;
2546 //Here all not infinite elements of theU1crit are in [0, thePeriod) range
2550 std::sort(theU1crit, theU1crit + theNbCritPointsMax);
2552 while(ExcludeNearElements(theU1crit, theNbCritPointsMax,
2553 theUSurf1f, theUSurf1l, theTol2D));
2555 //Here all not infinite elements in theU1crit are different and sorted.
2557 while(theNbCritPointsMax > 0)
2559 Standard_Real &anB = theU1crit[theNbCritPointsMax-1];
2560 if(Precision::IsInfinite(anB))
2562 theNbCritPointsMax--;
2566 //1st not infinte element is found
2568 if(theNbCritPointsMax == 1)
2571 //Here theNbCritPointsMax > 1
2573 Standard_Real &anA = theU1crit[0];
2575 //Compare 1st and last significant elements of theU1crit
2576 //They may still differs by period.
2578 if (Abs(anB - anA - thePeriod) < theTol2D)
2579 {//E.g. anA == 2.0e-17, anB == (thePeriod-1.0e-18)
2580 anA = (anA + anB - thePeriod)/2.0;
2581 anB = Precision::Infinite();
2582 theNbCritPointsMax--;
2585 //Out of "while(theNbCritPointsMax > 0)" cycle.
2589 //Attention! Here theU1crit may be unsorted.
2592 //=======================================================================
2593 //function : BoundaryEstimation
2594 //purpose : Rough estimation of the parameter range.
2595 //=======================================================================
2596 void WorkWithBoundaries::BoundaryEstimation(const gp_Cylinder& theCy1,
2597 const gp_Cylinder& theCy2,
2598 Bnd_Range& theOutBoxS1,
2599 Bnd_Range& theOutBoxS2) const
2601 const gp_Dir &aD1 = theCy1.Axis().Direction(),
2602 &aD2 = theCy2.Axis().Direction();
2603 const Standard_Real aR1 = theCy1.Radius(),
2604 aR2 = theCy2.Radius();
2606 //Let consider a parallelogram. Its edges are parallel to aD1 and aD2.
2607 //Its altitudes are equal to 2*aR1 and 2*aR2 (diameters of the cylinders).
2608 //In fact, this parallelogram is a projection of the cylinders to the plane
2609 //created by the intersected axes aD1 and aD2 (if the axes are skewed then
2610 //one axis can be translated by parallel shifting till intersection).
2612 const Standard_Real aCosA = aD1.Dot(aD2);
2613 const Standard_Real aSqSinA = aD1.XYZ().CrossSquareMagnitude(aD2.XYZ());
2615 //If sine is small then it can be compared with angle.
2616 if (aSqSinA < Precision::Angular()*Precision::Angular())
2619 //Half of delta V. Delta V is a distance between
2620 //projections of two opposite parallelogram vertices
2621 //(joined by the maximal diagonal) to the cylinder axis.
2622 const Standard_Real aSinA = sqrt(aSqSinA);
2623 const Standard_Real anAbsCosA = Abs(aCosA);
2624 const Standard_Real aHDV1 = (aR1 * anAbsCosA + aR2) / aSinA,
2625 aHDV2 = (aR2 * anAbsCosA + aR1) / aSinA;
2627 #ifdef INTPATCH_IMPIMPINTERSECTION_DEBUG
2628 //The code in this block is created for test only.It is stupidly to create
2629 //OCCT-test for the method, which will be changed possibly never.
2630 std::cout << "Reference values: aHDV1 = " << aHDV1 << "; aHDV2 = " << aHDV2 << std::endl;
2633 //V-parameters of intersection point of the axes (in case of skewed axes,
2634 //see comment above).
2635 Standard_Real aV01 = 0.0, aV02 = 0.0;
2636 ExtremaLineLine(theCy1.Axis(), theCy2.Axis(), aCosA, aSqSinA, aV01, aV02);
2638 theOutBoxS1.Add(aV01 - aHDV1);
2639 theOutBoxS1.Add(aV01 + aHDV1);
2641 theOutBoxS2.Add(aV02 - aHDV2);
2642 theOutBoxS2.Add(aV02 + aHDV2);
2644 theOutBoxS1.Enlarge(Precision::Confusion());
2645 theOutBoxS2.Enlarge(Precision::Confusion());
2647 Standard_Real aU1 = 0.0, aV1 = 0.0, aU2 = 0.0, aV2 = 0.0;
2648 myUVSurf1.Get(aU1, aV1, aU2, aV2);
2649 theOutBoxS1.Common(Bnd_Range(aV1, aV2));
2651 myUVSurf2.Get(aU1, aV1, aU2, aV2);
2652 theOutBoxS2.Common(Bnd_Range(aV1, aV2));
2655 //=======================================================================
2656 //function : CyCyNoGeometric
2658 //=======================================================================
2659 static IntPatch_ImpImpIntersection::IntStatus
2660 CyCyNoGeometric(const gp_Cylinder &theCyl1,
2661 const gp_Cylinder &theCyl2,
2662 const WorkWithBoundaries &theBW,
2663 Bnd_Range theRange[],
2664 const Standard_Integer theNbOfRanges /*=2*/,
2665 Standard_Boolean& isTheEmpty,
2666 IntPatch_SequenceOfLine& theSlin,
2667 IntPatch_SequenceOfPoint& theSPnt)
2669 Standard_Real aUSurf1f = 0.0, aUSurf1l = 0.0,
2670 aUSurf2f = 0.0, aUSurf2l = 0.0,
2671 aVSurf1f = 0.0, aVSurf1l = 0.0,
2672 aVSurf2f = 0.0, aVSurf2l = 0.0;
2674 theBW.UVS1().Get(aUSurf1f, aVSurf1f, aUSurf1l, aVSurf1l);
2675 theBW.UVS2().Get(aUSurf2f, aVSurf2f, aUSurf2l, aVSurf2l);
2677 Bnd_Range aRangeS1, aRangeS2;
2678 theBW.BoundaryEstimation(theCyl1, theCyl2, aRangeS1, aRangeS2);
2679 if (aRangeS1.IsVoid() || aRangeS2.IsVoid())
2680 return IntPatch_ImpImpIntersection::IntStatus_OK;
2683 //Quotation of the message from issue #26894 (author MSV):
2684 //"We should return fail status from intersector if the result should be an
2685 //infinite curve of non-analytical type... I propose to define the limit for the
2686 //extent as the radius divided by 1e+2 and multiplied by 1e+7.
2687 //Thus, taking into account the number of valuable digits (15), we provide reliable
2688 //computations with an error not exceeding R/100."
2689 const Standard_Real aF = 1.0e+5;
2690 const Standard_Real aMaxV1Range = aF*theCyl1.Radius(), aMaxV2Range = aF*theCyl2.Radius();
2691 if ((aRangeS1.Delta() > aMaxV1Range) || (aRangeS2.Delta() > aMaxV2Range))
2692 return IntPatch_ImpImpIntersection::IntStatus_InfiniteSectionCurve;
2695 const ComputationMethods::stCoeffsValue &anEquationCoeffs = theBW.SICoeffs();
2696 const IntSurf_Quadric& aQuad1 = theBW.GetQSurface(1);
2697 const IntSurf_Quadric& aQuad2 = theBW.GetQSurface(2);
2698 const Standard_Boolean isReversed = theBW.IsReversed();
2699 const Standard_Real aTol2D = theBW.Get2dTolerance();
2700 const Standard_Real aTol3D = theBW.Get3dTolerance();
2701 const Standard_Real aPeriod = 2.0*M_PI;
2702 const Standard_Integer aNbMaxPoints = 2000;
2703 const Standard_Integer aNbMinPoints = 200;
2704 const Standard_Integer aNbPoints = Min(Max(aNbMinPoints,
2705 RealToInt(20.0*theCyl1.Radius())), aNbMaxPoints);
2706 const Standard_Real aStepMin = aTol2D,
2707 aStepMax = (aUSurf1l - aUSurf1f > M_PI / 100.0) ?
2708 (aUSurf1l - aUSurf1f) / IntToReal(aNbPoints) :
2709 aUSurf1l - aUSurf1f;
2711 //The main idea of the algorithm is to change U1-parameter
2712 //(U-parameter of theCyl1) from aU1f to aU1l with some step
2713 //(step is adaptive) and to obtain set of intersection points.
2715 for (Standard_Integer i = 0; i < theNbOfRanges; i++)
2717 if (theRange[i].IsVoid())
2720 InscribeInterval(aUSurf1f, aUSurf1l, theRange[i], aTol2D, aPeriod);
2723 if (theRange[0].Union(theRange[1]))
2725 // Works only if (theNbOfRanges == 2).
2726 theRange[1].SetVoid();
2729 //Critical points are the value of U1-parameter in the points
2730 //where WL must be decomposed.
2732 //When U1 goes through critical points its value is set up to this
2733 //parameter forcefully and the intersection point is added in the line.
2734 //After that, the WL is broken (next U1 value will be correspond to the new WL).
2736 //See CriticalPointsComputing(...) function to get detail information about this array.
2737 const Standard_Integer aNbCritPointsMax = 12;
2738 Standard_Real anU1crit[aNbCritPointsMax] = { Precision::Infinite(),
2739 Precision::Infinite(),
2740 Precision::Infinite(),
2741 Precision::Infinite(),
2742 Precision::Infinite(),
2743 Precision::Infinite(),
2744 Precision::Infinite(),
2745 Precision::Infinite(),
2746 Precision::Infinite(),
2747 Precision::Infinite(),
2748 Precision::Infinite(),
2749 Precision::Infinite() };
2751 //This list of critical points is not full because it does not contain any points
2752 //which intersection line goes through V-bounds of cylinders in.
2753 //They are computed by numerical methods on - line (during algorithm working).
2754 //The moment is caught, when intersection line goes through V-bounds of any cylinder.
2756 Standard_Integer aNbCritPoints = aNbCritPointsMax;
2757 CriticalPointsComputing(anEquationCoeffs, aUSurf1f, aUSurf1l, aUSurf2f, aUSurf2l,
2758 aPeriod, aTol2D, aNbCritPoints, anU1crit);
2760 //Getting Walking-line
2764 // No points have been added in WL
2765 WLFStatus_Absent = 0,
2766 // WL contains at least one point
2767 WLFStatus_Exist = 1,
2768 // WL has been finished in some critical point
2769 // We should start new line
2770 WLFStatus_Broken = 2
2773 const Standard_Integer aNbWLines = 2;
2774 for (Standard_Integer aCurInterval = 0; aCurInterval < theNbOfRanges; aCurInterval++)
2776 //Process every continuous region
2777 Standard_Boolean isAddedIntoWL[aNbWLines];
2778 for (Standard_Integer i = 0; i < aNbWLines; i++)
2779 isAddedIntoWL[i] = Standard_False;
2781 Standard_Real anUf = 1.0, anUl = 0.0;
2782 if (!theRange[aCurInterval].GetBounds(anUf, anUl))
2785 const Standard_Boolean isDeltaPeriod = IsEqual(anUl - anUf, aPeriod);
2787 //Inscribe and sort critical points
2788 for (Standard_Integer i = 0; i < aNbCritPoints; i++)
2790 InscribePoint(anUf, anUl, anU1crit[i], 0.0, aPeriod, Standard_False);
2793 std::sort(anU1crit, anU1crit + aNbCritPoints);
2797 //Change value of U-parameter on the 1st surface from anUf to anUl
2798 //(anUf will be modified in the cycle body).
2799 //Step is computed adaptively (see comments below).
2801 Standard_Real aU2[aNbWLines], aV1[aNbWLines], aV2[aNbWLines];
2802 WLFStatus aWLFindStatus[aNbWLines];
2803 Standard_Real aV1Prev[aNbWLines], aV2Prev[aNbWLines];
2804 Standard_Real anUexpect[aNbWLines];
2805 Standard_Boolean isAddingWLEnabled[aNbWLines];
2807 Handle(IntSurf_LineOn2S) aL2S[aNbWLines];
2808 Handle(IntPatch_WLine) aWLine[aNbWLines];
2809 for (Standard_Integer i = 0; i < aNbWLines; i++)
2811 aL2S[i] = new IntSurf_LineOn2S();
2812 aWLine[i] = new IntPatch_WLine(aL2S[i], Standard_False);
2813 aWLine[i]->SetCreatingWayInfo(IntPatch_WLine::IntPatch_WLImpImp);
2814 aWLFindStatus[i] = WLFStatus_Absent;
2815 isAddingWLEnabled[i] = Standard_True;
2816 aU2[i] = aV1[i] = aV2[i] = 0.0;
2817 aV1Prev[i] = aV2Prev[i] = 0.0;
2818 anUexpect[i] = anUf;
2821 Standard_Real aCriticalDelta[aNbCritPointsMax] = { 0 };
2822 for (Standard_Integer aCritPID = 0; aCritPID < aNbCritPoints; aCritPID++)
2823 { //We are not interested in elements of aCriticalDelta array
2824 //if their index is greater than or equal to aNbCritPoints
2826 aCriticalDelta[aCritPID] = anUf - anU1crit[aCritPID];
2829 Standard_Real anU1 = anUf, aMinCriticalParam = anUf;
2830 Standard_Boolean isFirst = Standard_True;
2832 while (anU1 <= anUl)
2834 //Change value of U-parameter on the 1st surface from anUf to anUl
2835 //(anUf will be modified in the cycle body). However, this cycle
2836 //can be broken if WL goes though some critical point.
2837 //Step is computed adaptively (see comments below).
2839 for (Standard_Integer i = 0; i < aNbCritPoints; i++)
2841 if ((anU1 - anU1crit[i])*aCriticalDelta[i] < 0.0)
2843 //WL has gone through i-th critical point
2846 for (Standard_Integer j = 0; j < aNbWLines; j++)
2848 aWLFindStatus[j] = WLFStatus_Broken;
2849 anUexpect[j] = anU1;
2856 if (IsEqual(anU1, anUl))
2858 for (Standard_Integer i = 0; i < aNbWLines; i++)
2860 aWLFindStatus[i] = WLFStatus_Broken;
2861 anUexpect[i] = anU1;
2865 //if isAddedIntoWL[i] == TRUE WLine contains only one point
2866 //(which was end point of previous WLine). If we will
2867 //add point found on the current step WLine will contain only
2868 //two points. At that both these points will be equal to the
2869 //points found earlier. Therefore, new WLine will repeat
2870 //already existing WLine. Consequently, it is necessary
2871 //to forbid building new line in this case.
2873 isAddingWLEnabled[i] = (!isAddedIntoWL[i]);
2877 isAddingWLEnabled[i] = ((aTol2D >= (anUexpect[i] - anU1)) ||
2878 (aWLFindStatus[i] == WLFStatus_Absent));
2880 }//for(Standard_Integer i = 0; i < aNbWLines; i++)
2884 for (Standard_Integer i = 0; i < aNbWLines; i++)
2886 isAddingWLEnabled[i] = ((aTol2D >= (anUexpect[i] - anU1)) ||
2887 (aWLFindStatus[i] == WLFStatus_Absent));
2888 }//for(Standard_Integer i = 0; i < aNbWLines; i++)
2891 for (Standard_Integer i = 0; i < aNbWLines; i++)
2893 const Standard_Integer aNbPntsWL = aWLine[i].IsNull() ? 0 :
2894 aWLine[i]->Curve()->NbPoints();
2896 if ((aWLFindStatus[i] == WLFStatus_Broken) ||
2897 (aWLFindStatus[i] == WLFStatus_Absent))
2898 {//Begin and end of WLine must be on boundary point
2899 //or on seam-edge strictly (if it is possible).
2901 Standard_Real aTol = aTol2D;
2902 ComputationMethods::CylCylComputeParameters(anU1, i, anEquationCoeffs,
2904 InscribePoint(aUSurf2f, aUSurf2l, aU2[i], aTol2D, aPeriod, Standard_False);
2906 aTol = Max(aTol, aTol2D);
2908 if (Abs(aU2[i]) <= aTol)
2910 else if (Abs(aU2[i] - aPeriod) <= aTol)
2912 else if (Abs(aU2[i] - aUSurf2f) <= aTol)
2914 else if (Abs(aU2[i] - aUSurf2l) <= aTol)
2919 ComputationMethods::CylCylComputeParameters(anU1, i, anEquationCoeffs, aU2[i]);
2920 InscribePoint(aUSurf2f, aUSurf2l, aU2[i], aTol2D, aPeriod, Standard_False);
2924 {//the line has not contained any points yet
2925 if (((aUSurf2f + aPeriod - aUSurf2l) <= 2.0*aTol2D) &&
2926 ((Abs(aU2[i] - aUSurf2f) < aTol2D) ||
2927 (Abs(aU2[i] - aUSurf2l) < aTol2D)))
2929 //In this case aU2[i] can have two values: current aU2[i] or
2930 //aU2[i]+aPeriod (aU2[i]-aPeriod). It is necessary to choose
2933 Standard_Boolean isIncreasing = Standard_True;
2934 ComputationMethods::CylCylMonotonicity(anU1+aStepMin, i, anEquationCoeffs,
2935 aPeriod, isIncreasing);
2937 //If U2(U1) is increasing and U2 is considered to be equal aUSurf2l
2938 //then after the next step (when U1 will be increased) U2 will be
2939 //increased too. And we will go out of surface boundary.
2940 //Therefore, If U2(U1) is increasing then U2 must be equal aUSurf2f.
2941 //Analogically, if U2(U1) is decreasing.
2954 if (((aUSurf2l - aUSurf2f) >= aPeriod) &&
2955 ((Abs(aU2[i] - aUSurf2f) < aTol2D) ||
2956 (Abs(aU2[i] - aUSurf2l) < aTol2D)))
2958 Standard_Real aU2prev = 0.0, aV2prev = 0.0;
2960 aWLine[i]->Curve()->Value(aNbPntsWL).ParametersOnS1(aU2prev, aV2prev);
2962 aWLine[i]->Curve()->Value(aNbPntsWL).ParametersOnS2(aU2prev, aV2prev);
2964 if (2.0*Abs(aU2prev - aU2[i]) > aPeriod)
2966 if (aU2prev > aU2[i])
2974 ComputationMethods::CylCylComputeParameters(anU1, aU2[i], anEquationCoeffs,
2979 aV1Prev[i] = aV1[i];
2980 aV2Prev[i] = aV2[i];
2982 }//for(Standard_Integer i = 0; i < aNbWLines; i++)
2984 isFirst = Standard_False;
2986 //Looking for points into WLine
2987 Standard_Boolean isBroken = Standard_False;
2988 for (Standard_Integer i = 0; i < aNbWLines; i++)
2990 if (!isAddingWLEnabled[i])
2992 Standard_Boolean isBoundIntersect = Standard_False;
2993 if ((Abs(aV1[i] - aVSurf1f) <= aTol2D) ||
2994 ((aV1[i] - aVSurf1f)*(aV1Prev[i] - aVSurf1f) < 0.0))
2996 isBoundIntersect = Standard_True;
2998 else if ((Abs(aV1[i] - aVSurf1l) <= aTol2D) ||
2999 ((aV1[i] - aVSurf1l)*(aV1Prev[i] - aVSurf1l) < 0.0))
3001 isBoundIntersect = Standard_True;
3003 else if ((Abs(aV2[i] - aVSurf2f) <= aTol2D) ||
3004 ((aV2[i] - aVSurf2f)*(aV2Prev[i] - aVSurf2f) < 0.0))
3006 isBoundIntersect = Standard_True;
3008 else if ((Abs(aV2[i] - aVSurf2l) <= aTol2D) ||
3009 ((aV2[i] - aVSurf2l)*(aV2Prev[i] - aVSurf2l) < 0.0))
3011 isBoundIntersect = Standard_True;
3014 if (aWLFindStatus[i] == WLFStatus_Broken)
3015 isBroken = Standard_True;
3017 if (!isBoundIntersect)
3023 anUexpect[i] = anU1;
3027 // True if the current point already in the domain
3028 const Standard_Boolean isInscribe =
3029 ((aUSurf2f - aU2[i]) <= aTol2D) && ((aU2[i] - aUSurf2l) <= aTol2D) &&
3030 ((aVSurf1f - aV1[i]) <= aTol2D) && ((aV1[i] - aVSurf1l) <= aTol2D) &&
3031 ((aVSurf2f - aV2[i]) <= aTol2D) && ((aV2[i] - aVSurf2l) <= aTol2D);
3033 //isVIntersect == TRUE if intersection line intersects two (!)
3034 //V-bounds of cylinder (1st or 2nd - no matter)
3035 const Standard_Boolean isVIntersect =
3036 (((aVSurf1f - aV1[i])*(aVSurf1f - aV1Prev[i]) < RealSmall()) &&
3037 ((aVSurf1l - aV1[i])*(aVSurf1l - aV1Prev[i]) < RealSmall())) ||
3038 (((aVSurf2f - aV2[i])*(aVSurf2f - aV2Prev[i]) < RealSmall()) &&
3039 ((aVSurf2l - aV2[i])*(aVSurf2l - aV2Prev[i]) < RealSmall()));
3041 //isFound1 == TRUE if intersection line intersects V-bounds
3042 // (First or Last - no matter) of the 1st cylynder
3043 //isFound2 == TRUE if intersection line intersects V-bounds
3044 // (First or Last - no matter) of the 2nd cylynder
3045 Standard_Boolean isFound1 = Standard_False, isFound2 = Standard_False;
3046 Standard_Boolean isForce = Standard_False;
3048 if (aWLFindStatus[i] == WLFStatus_Absent)
3050 if (((aUSurf2l - aUSurf2f) >= aPeriod) && (Abs(anU1 - aUSurf1l) < aTol2D))
3052 isForce = Standard_True;
3056 theBW.AddBoundaryPoint(aWLine[i], anU1, aMinCriticalParam, aU2[i],
3057 aV1[i], aV1Prev[i], aV2[i], aV2Prev[i], i, isForce,
3058 isFound1, isFound2);
3060 const Standard_Boolean isPrevVBound = !isVIntersect &&
3061 ((Abs(aV1Prev[i] - aVSurf1f) <= aTol2D) ||
3062 (Abs(aV1Prev[i] - aVSurf1l) <= aTol2D) ||
3063 (Abs(aV2Prev[i] - aVSurf2f) <= aTol2D) ||
3064 (Abs(aV2Prev[i] - aVSurf2l) <= aTol2D));
3066 aV1Prev[i] = aV1[i];
3067 aV2Prev[i] = aV2[i];
3069 if ((aWLFindStatus[i] == WLFStatus_Exist) && (isFound1 || isFound2) && !isPrevVBound)
3071 aWLFindStatus[i] = WLFStatus_Broken; //start a new line
3073 else if (isInscribe)
3075 if ((aWLFindStatus[i] == WLFStatus_Absent) && (isFound1 || isFound2))
3077 aWLFindStatus[i] = WLFStatus_Exist;
3080 if ((aWLFindStatus[i] != WLFStatus_Broken) ||
3081 (aWLine[i]->NbPnts() >= 1) || IsEqual(anU1, anUl))
3083 if (aWLine[i]->NbPnts() > 0)
3085 Standard_Real aU2p = 0.0, aV2p = 0.0;
3087 aWLine[i]->Point(aWLine[i]->NbPnts()).ParametersOnS1(aU2p, aV2p);
3089 aWLine[i]->Point(aWLine[i]->NbPnts()).ParametersOnS2(aU2p, aV2p);
3091 const Standard_Real aDelta = aU2[i] - aU2p;
3093 if (2.0 * Abs(aDelta) > aPeriod)
3106 if(AddPointIntoWL(aQuad1, aQuad2, anEquationCoeffs, isReversed, Standard_True,
3107 gp_Pnt2d(anU1, aV1[i]), gp_Pnt2d(aU2[i], aV2[i]),
3108 aUSurf1f, aUSurf1l, aUSurf2f, aUSurf2l,
3109 aVSurf1f, aVSurf1l, aVSurf2f, aVSurf2l, aPeriod,
3110 aWLine[i]->Curve(), i, aTol3D, aTol2D, isForce))
3112 if (aWLFindStatus[i] == WLFStatus_Absent)
3114 aWLFindStatus[i] = WLFStatus_Exist;
3117 else if (!isFound1 && !isFound2)
3118 {//We do not add any point while doing this iteration
3119 if (aWLFindStatus[i] == WLFStatus_Exist)
3121 aWLFindStatus[i] = WLFStatus_Broken;
3127 {//We do not add any point while doing this iteration
3128 if (aWLFindStatus[i] == WLFStatus_Exist)
3130 aWLFindStatus[i] = WLFStatus_Broken;
3134 if (aWLFindStatus[i] == WLFStatus_Broken)
3135 isBroken = Standard_True;
3136 }//for(Standard_Integer i = 0; i < aNbWLines; i++)
3139 {//current lines are filled. Go to the next lines
3142 Standard_Boolean isAdded = Standard_True;
3144 for (Standard_Integer i = 0; i < aNbWLines; i++)
3146 if (isAddingWLEnabled[i])
3151 isAdded = Standard_False;
3153 Standard_Boolean isFound1 = Standard_False, isFound2 = Standard_False;
3155 theBW.AddBoundaryPoint(aWLine[i], anU1, aMinCriticalParam, aU2[i],
3156 aV1[i], aV1Prev[i], aV2[i], aV2Prev[i], i,
3157 Standard_False, isFound1, isFound2);
3159 if (isFound1 || isFound2)
3161 isAdded = Standard_True;
3164 if (aWLine[i]->NbPnts() > 0)
3166 Standard_Real aU2p = 0.0, aV2p = 0.0;
3168 aWLine[i]->Point(aWLine[i]->NbPnts()).ParametersOnS1(aU2p, aV2p);
3170 aWLine[i]->Point(aWLine[i]->NbPnts()).ParametersOnS2(aU2p, aV2p);
3172 const Standard_Real aDelta = aU2[i] - aU2p;
3174 if (2 * Abs(aDelta) > aPeriod)
3187 if(AddPointIntoWL(aQuad1, aQuad2, anEquationCoeffs, isReversed,
3188 Standard_True, gp_Pnt2d(anU1, aV1[i]),
3189 gp_Pnt2d(aU2[i], aV2[i]), aUSurf1f, aUSurf1l,
3190 aUSurf2f, aUSurf2l, aVSurf1f, aVSurf1l,
3191 aVSurf2f, aVSurf2l, aPeriod, aWLine[i]->Curve(),
3192 i, aTol3D, aTol2D, Standard_False))
3194 isAdded = Standard_True;
3200 //Before breaking WL, we must complete it correctly
3201 //(e.g. to prolong to the surface boundary).
3202 //Therefore, we take the point last added in some WL
3203 //(have maximal U1-parameter) and try to add it in
3205 Standard_Real anUmaxAdded = RealFirst();
3208 Standard_Boolean isChanged = Standard_False;
3209 for (Standard_Integer i = 0; i < aNbWLines; i++)
3211 if ((aWLFindStatus[i] == WLFStatus_Absent) || (aWLine[i]->NbPnts() == 0))
3214 Standard_Real aU1c = 0.0, aV1c = 0.0;
3216 aWLine[i]->Curve()->Value(aWLine[i]->NbPnts()).ParametersOnS2(aU1c, aV1c);
3218 aWLine[i]->Curve()->Value(aWLine[i]->NbPnts()).ParametersOnS1(aU1c, aV1c);
3220 anUmaxAdded = Max(anUmaxAdded, aU1c);
3221 isChanged = Standard_True;
3225 { //If anUmaxAdded were not changed in previous cycle then
3226 //we would break existing WLines.
3231 for (Standard_Integer i = 0; i < aNbWLines; i++)
3233 if (isAddingWLEnabled[i])
3238 ComputationMethods::CylCylComputeParameters(anUmaxAdded, i, anEquationCoeffs,
3239 aU2[i], aV1[i], aV2[i]);
3241 AddPointIntoWL(aQuad1, aQuad2, anEquationCoeffs, isReversed,
3242 Standard_True, gp_Pnt2d(anUmaxAdded, aV1[i]),
3243 gp_Pnt2d(aU2[i], aV2[i]), aUSurf1f, aUSurf1l,
3244 aUSurf2f, aUSurf2l, aVSurf1f, aVSurf1l,
3245 aVSurf2f, aVSurf2l, aPeriod, aWLine[i]->Curve(),
3246 i, aTol3D, aTol2D, Standard_False);
3256 //Step of aU1-parameter is computed adaptively. The algorithm
3257 //aims to provide given aDeltaV1 and aDeltaV2 values (if it is
3258 //possible because the intersection line can go along V-isoline)
3259 //in every iteration. It allows avoiding "flying" intersection
3260 //points too far each from other (see issue #24915).
3262 const Standard_Real aDeltaV1 = aRangeS1.Delta() / IntToReal(aNbPoints),
3263 aDeltaV2 = aRangeS2.Delta() / IntToReal(aNbPoints);
3265 math_Matrix aMatr(1, 3, 1, 5);
3267 Standard_Real aMinUexp = RealLast();
3269 for (Standard_Integer i = 0; i < aNbWLines; i++)
3271 if (aTol2D < (anUexpect[i] - anU1))
3276 if (aWLFindStatus[i] == WLFStatus_Absent)
3278 anUexpect[i] += aStepMax;
3279 aMinUexp = Min(aMinUexp, anUexpect[i]);
3283 Standard_Real aStepTmp = aStepMax;
3285 const Standard_Real aSinU1 = sin(anU1),
3287 aSinU2 = sin(aU2[i]),
3288 aCosU2 = cos(aU2[i]);
3290 aMatr.SetCol(1, anEquationCoeffs.mVecC1);
3291 aMatr.SetCol(2, anEquationCoeffs.mVecC2);
3292 aMatr.SetCol(3, anEquationCoeffs.mVecA1*aSinU1 - anEquationCoeffs.mVecB1*aCosU1);
3293 aMatr.SetCol(4, anEquationCoeffs.mVecA2*aSinU2 - anEquationCoeffs.mVecB2*aCosU2);
3294 aMatr.SetCol(5, anEquationCoeffs.mVecA1*aCosU1 + anEquationCoeffs.mVecB1*aSinU1 +
3295 anEquationCoeffs.mVecA2*aCosU2 + anEquationCoeffs.mVecB2*aSinU2 +
3296 anEquationCoeffs.mVecD);
3298 //The main idea is in solving of linearized system (2)
3299 //(see description to ComputationMethods class) in order to find new U1-value
3300 //to provide new value V1 or V2, which differs from current one by aDeltaV1 or
3301 //aDeltaV2 respectively.
3303 //While linearizing, following Taylor formulas are used:
3304 // cos(x0+dx) = cos(x0) - sin(x0)*dx
3305 // sin(x0+dx) = sin(x0) + cos(x0)*dx
3307 //Consequently cos(U1), cos(U2), sin(U1) and sin(U2) in the system (2)
3308 //must be substituted by corresponding values.
3311 //The solution is approximate. More over, all requirements to the
3312 //linearization must be satisfied in order to obtain quality result.
3314 if (!StepComputing(aMatr, aV1[i], aV2[i], aDeltaV1, aDeltaV2, aStepTmp))
3316 //To avoid cycling-up
3317 anUexpect[i] += aStepMax;
3318 aMinUexp = Min(aMinUexp, anUexpect[i]);
3323 if (aStepTmp < aStepMin)
3324 aStepTmp = aStepMin;
3326 if (aStepTmp > aStepMax)
3327 aStepTmp = aStepMax;
3329 anUexpect[i] = anU1 + aStepTmp;
3330 aMinUexp = Min(aMinUexp, anUexpect[i]);
3336 if (Precision::PConfusion() >= (anUl - anU1))
3341 for (Standard_Integer i = 0; i < aNbWLines; i++)
3343 if (aWLine[i]->NbPnts() != 1)
3344 isAddedIntoWL[i] = Standard_False;
3347 {//strictly equal. Tolerance is considered above.
3348 anUexpect[i] = anUl;
3353 for (Standard_Integer i = 0; i < aNbWLines; i++)
3355 if ((aWLine[i]->NbPnts() == 1) && (!isAddedIntoWL[i]))
3357 isTheEmpty = Standard_False;
3358 Standard_Real u1, v1, u2, v2;
3359 aWLine[i]->Point(1).Parameters(u1, v1, u2, v2);
3361 aP.SetParameter(u1);
3362 aP.SetParameters(u1, v1, u2, v2);
3363 aP.SetTolerance(aTol3D);
3364 aP.SetValue(aWLine[i]->Point(1).Value());
3366 //Check whether the added point exists.
3367 //It is enough to check the last point.
3368 if (theSPnt.IsEmpty() ||
3369 !theSPnt.Last().PntOn2S().IsSame(aP.PntOn2S(), Precision::Confusion()))
3374 else if (aWLine[i]->NbPnts() > 1)
3376 Standard_Boolean isGood = Standard_True;
3378 if (aWLine[i]->NbPnts() == 2)
3380 const IntSurf_PntOn2S& aPf = aWLine[i]->Point(1);
3381 const IntSurf_PntOn2S& aPl = aWLine[i]->Point(2);
3383 if (aPf.IsSame(aPl, Precision::Confusion()))
3384 isGood = Standard_False;
3386 else if (aWLine[i]->NbPnts() > 2)
3388 // Sometimes points of the WLine are distributed
3389 // linearly and uniformly. However, such position
3390 // of the points does not always describe the real intersection
3391 // curve. I.e. real tangents at the ends of the intersection
3392 // curve can significantly deviate from this "line" direction.
3393 // Here we are processing this case by inserting additional points
3394 // to the beginning/end of the WLine to make it more precise.
3395 // See description to the issue #30082.
3397 const Standard_Real aSqTol3D = aTol3D*aTol3D;
3398 for (Standard_Integer j = 0; j < 2; j++)
3400 // If j == 0 ==> add point at begin of WLine.
3401 // If j == 1 ==> add point at end of WLine.
3405 if (aWLine[i]->NbPnts() >= aNbMaxPoints)
3410 // Take 1st and 2nd point to compute the "line" direction.
3411 // For our convenience, we make 2nd point be the ends of the WLine
3412 // because it will be used for computation of the normals
3414 const Standard_Integer anIdx1 = j ? aWLine[i]->NbPnts() - 1 : 2;
3415 const Standard_Integer anIdx2 = j ? aWLine[i]->NbPnts() : 1;
3417 const gp_Pnt &aP1 = aWLine[i]->Point(anIdx1).Value();
3418 const gp_Pnt &aP2 = aWLine[i]->Point(anIdx2).Value();
3420 const gp_Vec aDir(aP1, aP2);
3422 if (aDir.SquareMagnitude() < aSqTol3D)
3427 // Compute tangent in first/last point of the WLine.
3428 // We do not take into account the flag "isReversed"
3429 // because strict direction of the tangent is not
3430 // important here (we are interested in the tangent
3431 // line itself and nothing to fear if its direction
3433 const gp_Vec aN1 = aQuad1.Normale(aP2);
3434 const gp_Vec aN2 = aQuad2.Normale(aP2);
3435 const gp_Vec aTg(aN1.Crossed(aN2));
3437 if (aTg.SquareMagnitude() < Precision::SquareConfusion())
3443 // Check of the bending
3444 Standard_Real anAngle = aDir.Angle(aTg);
3446 if (anAngle > M_PI_2)
3449 if (Abs(anAngle) > 0.25) // ~ 14deg.
3451 const Standard_Integer aNbPntsPrev = aWLine[i]->NbPnts();
3452 SeekAdditionalPoints(aQuad1, aQuad2, aWLine[i]->Curve(),
3453 anEquationCoeffs, i, 3, anIdx1, anIdx2,
3454 aTol2D, aPeriod, isReversed);
3456 if (aWLine[i]->NbPnts() == aNbPntsPrev)
3458 // No points have been added. ==> Exit from a loop.
3464 // Good result has been achieved. ==> Exit from a loop.
3473 isTheEmpty = Standard_False;
3474 isAddedIntoWL[i] = Standard_True;
3475 SeekAdditionalPoints(aQuad1, aQuad2, aWLine[i]->Curve(),
3476 anEquationCoeffs, i, aNbPoints, 1,
3477 aWLine[i]->NbPnts(), aTol2D, aPeriod,
3480 aWLine[i]->ComputeVertexParameters(aTol3D);
3481 theSlin.Append(aWLine[i]);
3486 isAddedIntoWL[i] = Standard_False;
3489 #ifdef INTPATCH_IMPIMPINTERSECTION_DEBUG
3490 //aWLine[i]->Dump();
3497 //Delete the points in theSPnt, which
3498 //lie at least in one of the line in theSlin.
3499 for (Standard_Integer aNbPnt = 1; aNbPnt <= theSPnt.Length(); aNbPnt++)
3501 for (Standard_Integer aNbLin = 1; aNbLin <= theSlin.Length(); aNbLin++)
3503 Handle(IntPatch_WLine) aWLine1(Handle(IntPatch_WLine)::
3504 DownCast(theSlin.Value(aNbLin)));
3506 const IntSurf_PntOn2S& aPntFWL1 = aWLine1->Point(1);
3507 const IntSurf_PntOn2S& aPntLWL1 = aWLine1->Point(aWLine1->NbPnts());
3509 const IntSurf_PntOn2S aPntCur = theSPnt.Value(aNbPnt).PntOn2S();
3510 if (aPntCur.IsSame(aPntFWL1, aTol3D) ||
3511 aPntCur.IsSame(aPntLWL1, aTol3D))
3513 theSPnt.Remove(aNbPnt);
3520 //Try to add new points in the neighborhood of existing point
3521 for (Standard_Integer aNbPnt = 1; aNbPnt <= theSPnt.Length(); aNbPnt++)
3523 // Standard algorithm (implemented above) could not find any
3524 // continuous curve in neighborhood of aPnt2S (e.g. because
3525 // this curve is too small; see tests\bugs\modalg_5\bug25292_35 and _36).
3526 // Here, we will try to find several new points nearer to aPnt2S.
3528 // The algorithm below tries to find two points in every
3529 // intervals [u1 - aStepMax, u1] and [u1, u1 + aStepMax]
3530 // and every new point will be in maximal distance from
3531 // u1. If these two points exist they will be joined
3532 // by the intersection curve.
3534 const IntPatch_Point& aPnt2S = theSPnt.Value(aNbPnt);
3536 Standard_Real u1, v1, u2, v2;
3537 aPnt2S.Parameters(u1, v1, u2, v2);
3539 Handle(IntSurf_LineOn2S) aL2S = new IntSurf_LineOn2S();
3540 Handle(IntPatch_WLine) aWLine = new IntPatch_WLine(aL2S, Standard_False);
3541 aWLine->SetCreatingWayInfo(IntPatch_WLine::IntPatch_WLImpImp);
3543 //Define the index of WLine, which lies the point aPnt2S in.
3544 Standard_Integer anIndex = 0;
3546 Standard_Real anUf = 0.0, anUl = 0.0, aCurU2 = 0.0;
3549 anUf = Max(u2 - aStepMax, aUSurf1f);
3550 anUl = Min(u2 + aStepMax, aUSurf1l);
3555 anUf = Max(u1 - aStepMax, aUSurf1f);
3556 anUl = Min(u1 + aStepMax, aUSurf1l);
3560 const Standard_Real anUinf = anUf, anUsup = anUl, anUmid = 0.5*(anUf + anUl);
3563 //Find the value of anIndex variable.
3564 Standard_Real aDelta = RealLast();
3565 for (Standard_Integer i = 0; i < aNbWLines; i++)
3567 Standard_Real anU2t = 0.0;
3568 if (!ComputationMethods::CylCylComputeParameters(anUmid, i, anEquationCoeffs, anU2t))
3571 Standard_Real aDU2 = fmod(Abs(anU2t - aCurU2), aPeriod);
3572 aDU2 = Min(aDU2, Abs(aDU2 - aPeriod));
3581 // Bisection method is used in order to find every new point.
3582 // I.e. if we need to find intersection point in the interval [anUinf, anUmid]
3583 // we check the point anUC = 0.5*(anUinf+anUmid). If it is an intersection point
3584 // we try to find another point in the interval [anUinf, anUC] (because we find the point in
3585 // maximal distance from anUmid). If it is not then we try to find another point in the
3586 // interval [anUC, anUmid]. Next iterations will be made analogically.
3587 // When we find intersection point in the interval [anUmid, anUsup] we try to find
3588 // another point in the interval [anUC, anUsup] if anUC is intersection point and
3589 // in the interval [anUmid, anUC], otherwise.
3591 Standard_Real anAddedPar[2] = {isReversed ? u2 : u1, isReversed ? u2 : u1};
3593 for (Standard_Integer aParID = 0; aParID < 2; aParID++)
3600 else // if(aParID == 1)
3606 Standard_Real &aPar1 = (aParID == 0) ? anUf : anUl,
3607 &aPar2 = (aParID == 0) ? anUl : anUf;
3609 while (Abs(aPar2 - aPar1) > aStepMin)
3611 Standard_Real anUC = 0.5*(anUf + anUl);
3612 Standard_Real aU2 = 0.0, aV1 = 0.0, aV2 = 0.0;
3613 Standard_Boolean isDone = ComputationMethods::
3614 CylCylComputeParameters(anUC, anIndex, anEquationCoeffs, aU2, aV1, aV2);
3618 if (Abs(aV1 - aVSurf1f) <= aTol2D)
3621 if (Abs(aV1 - aVSurf1l) <= aTol2D)
3624 if (Abs(aV2 - aVSurf2f) <= aTol2D)
3627 if (Abs(aV2 - aVSurf2l) <= aTol2D)
3630 isDone = AddPointIntoWL(aQuad1, aQuad2, anEquationCoeffs, isReversed,
3631 Standard_True, gp_Pnt2d(anUC, aV1), gp_Pnt2d(aU2, aV2),
3632 aUSurf1f, aUSurf1l, aUSurf2f, aUSurf2l,
3633 aVSurf1f, aVSurf1l, aVSurf2f, aVSurf2l,
3634 aPeriod, aWLine->Curve(), anIndex, aTol3D,
3635 aTol2D, Standard_False, Standard_True);
3640 anAddedPar[0] = Min(anAddedPar[0], anUC);
3641 anAddedPar[1] = Max(anAddedPar[1], anUC);
3651 //Fill aWLine by additional points
3652 if (anAddedPar[1] - anAddedPar[0] > aStepMin)
3654 for (Standard_Integer aParID = 0; aParID < 2; aParID++)
3656 Standard_Real aU2 = 0.0, aV1 = 0.0, aV2 = 0.0;
3657 ComputationMethods::CylCylComputeParameters(anAddedPar[aParID], anIndex,
3658 anEquationCoeffs, aU2, aV1, aV2);
3660 AddPointIntoWL(aQuad1, aQuad2, anEquationCoeffs, isReversed, Standard_True,
3661 gp_Pnt2d(anAddedPar[aParID], aV1), gp_Pnt2d(aU2, aV2),
3662 aUSurf1f, aUSurf1l, aUSurf2f, aUSurf2l,
3663 aVSurf1f, aVSurf1l, aVSurf2f, aVSurf2l, aPeriod, aWLine->Curve(),
3664 anIndex, aTol3D, aTol2D, Standard_False, Standard_False);
3667 SeekAdditionalPoints(aQuad1, aQuad2, aWLine->Curve(),
3668 anEquationCoeffs, anIndex, aNbMinPoints,
3669 1, aWLine->NbPnts(), aTol2D, aPeriod,
3672 aWLine->ComputeVertexParameters(aTol3D);
3673 theSlin.Append(aWLine);
3675 theSPnt.Remove(aNbPnt);
3680 return IntPatch_ImpImpIntersection::IntStatus_OK;
3683 //=======================================================================
3684 //function : IntCyCy
3686 //=======================================================================
3687 IntPatch_ImpImpIntersection::IntStatus IntCyCy(const IntSurf_Quadric& theQuad1,
3688 const IntSurf_Quadric& theQuad2,
3689 const Standard_Real theTol3D,
3690 const Standard_Real theTol2D,
3691 const Bnd_Box2d& theUVSurf1,
3692 const Bnd_Box2d& theUVSurf2,
3693 Standard_Boolean& isTheEmpty,
3694 Standard_Boolean& isTheSameSurface,
3695 Standard_Boolean& isTheMultiplePoint,
3696 IntPatch_SequenceOfLine& theSlin,
3697 IntPatch_SequenceOfPoint& theSPnt)
3699 isTheEmpty = Standard_True;
3700 isTheSameSurface = Standard_False;
3701 isTheMultiplePoint = Standard_False;
3705 const gp_Cylinder aCyl1 = theQuad1.Cylinder(),
3706 aCyl2 = theQuad2.Cylinder();
3708 IntAna_QuadQuadGeo anInter(aCyl1,aCyl2,theTol3D);
3710 if (!anInter.IsDone())
3712 return IntPatch_ImpImpIntersection::IntStatus_Fail;
3715 if(anInter.TypeInter() != IntAna_NoGeometricSolution)
3717 if (CyCyAnalyticalIntersect(theQuad1, theQuad2, anInter,
3718 theTol3D, isTheEmpty,
3719 isTheSameSurface, isTheMultiplePoint,
3722 return IntPatch_ImpImpIntersection::IntStatus_OK;
3726 //Here, intersection line is not an analytical curve(line, circle, ellipsis etc.)
3728 Standard_Real aUSBou[2][2], aVSBou[2][2]; //const
3730 theUVSurf1.Get(aUSBou[0][0], aVSBou[0][0], aUSBou[0][1], aVSBou[0][1]);
3731 theUVSurf2.Get(aUSBou[1][0], aVSBou[1][0], aUSBou[1][1], aVSBou[1][1]);
3733 const Standard_Real aPeriod = 2.0*M_PI;
3734 const Standard_Integer aNbWLines = 2;
3736 const ComputationMethods::stCoeffsValue anEquationCoeffs1(aCyl1, aCyl2);
3737 const ComputationMethods::stCoeffsValue anEquationCoeffs2(aCyl2, aCyl1);
3740 //Intersection result can include two non-connected regions
3741 //(see WorkWithBoundaries::BoundariesComputing(...) method).
3742 const Standard_Integer aNbOfBoundaries = 2;
3743 Bnd_Range anURange[2][aNbOfBoundaries]; //const
3745 if (!WorkWithBoundaries::BoundariesComputing(anEquationCoeffs1, aPeriod, anURange[0]))
3746 return IntPatch_ImpImpIntersection::IntStatus_OK;
3748 if (!WorkWithBoundaries::BoundariesComputing(anEquationCoeffs2, aPeriod, anURange[1]))
3749 return IntPatch_ImpImpIntersection::IntStatus_OK;
3751 //anURange[*] can be in different periodic regions in
3752 //compare with First-Last surface. E.g. the surface
3753 //is full cylinder [0, 2*PI] but anURange is [5, 7].
3754 //Trivial common range computation returns [5, 2*PI] and
3755 //its summary length is 2*PI-5 == 1.28... only. That is wrong.
3756 //This problem can be solved by the following
3758 // 1. split anURange[*] by the surface boundary;
3759 // 2. shift every new range in order to inscribe it
3760 // in [Ufirst, Ulast] of cylinder;
3761 // 3. consider only common ranges between [Ufirst, Ulast]
3764 // In above example, we obtain following:
3765 // 1. two ranges: [5, 2*PI] and [2*PI, 7];
3766 // 2. after shifting: [5, 2*PI] and [0, 7-2*PI];
3767 // 3. Common ranges: ([5, 2*PI] and [0, 2*PI]) == [5, 2*PI],
3768 // ([0, 7-2*PI] and [0, 2*PI]) == [0, 7-2*PI];
3769 // 4. Their summary length is (2*PI-5)+(7-2*PI-0)==7-5==2 ==> GOOD.
3771 Standard_Real aSumRange[2] = { 0.0, 0.0 };
3772 Handle(NCollection_IncAllocator) anAlloc = new NCollection_IncAllocator;
3773 for (Standard_Integer aCID = 0; aCID < 2; aCID++)
3776 NCollection_List<Bnd_Range> aListOfRng(anAlloc);
3778 aListOfRng.Append(anURange[aCID][0]);
3779 aListOfRng.Append(anURange[aCID][1]);
3781 const Standard_Real aSplitArr[3] = {aUSBou[aCID][0], aUSBou[aCID][1], 0.0};
3783 NCollection_List<Bnd_Range>::Iterator anITrRng;
3784 for (Standard_Integer aSInd = 0; aSInd < 3; aSInd++)
3786 NCollection_List<Bnd_Range> aLstTemp(aListOfRng);
3788 for (anITrRng.Init(aLstTemp); anITrRng.More(); anITrRng.Next())
3790 Bnd_Range& aRng = anITrRng.Value();
3791 aRng.Split(aSplitArr[aSInd], aListOfRng, aPeriod);
3795 anITrRng.Init(aListOfRng);
3796 for (; anITrRng.More(); anITrRng.Next())
3798 Bnd_Range& aCurrRange = anITrRng.Value();
3801 aBoundR.Add(aUSBou[aCID][0]);
3802 aBoundR.Add(aUSBou[aCID][1]);
3804 if (!InscribeInterval(aUSBou[aCID][0], aUSBou[aCID][1],
3805 aCurrRange, theTol2D, aPeriod))
3807 //If aCurrRange does not have common block with
3808 //[Ufirst, Ulast] of cylinder then we will try
3809 //to inscribe [Ufirst, Ulast] in the boundaries of aCurrRange.
3810 Standard_Real aF = 1.0, aL = 0.0;
3811 if (!aCurrRange.GetBounds(aF, aL))
3814 if ((aL < aUSBou[aCID][0]))
3816 aCurrRange.Shift(aPeriod);
3818 else if (aF > aUSBou[aCID][1])
3820 aCurrRange.Shift(-aPeriod);
3824 aBoundR.Common(aCurrRange);
3826 const Standard_Real aDelta = aBoundR.Delta();
3830 aSumRange[aCID] += aDelta;
3835 //The bigger range the bigger number of points in Walking-line (WLine)
3836 //we will be able to add and consequently we will obtain more
3837 //precise intersection line.
3838 //Every point of WLine is determined as function from U1-parameter,
3839 //where U1 is U-parameter on 1st quadric.
3840 //Therefore, we should use quadric with bigger range as 1st parameter
3841 //in IntCyCy() function.
3842 //On the other hand, there is no point in reversing in case of
3843 //analytical intersection (when result is line, ellipse, point...).
3844 //This result is independent of the arguments order.
3845 const Standard_Boolean isToReverse = (aSumRange[1] > aSumRange[0]);
3849 const WorkWithBoundaries aBoundWork(theQuad2, theQuad1, anEquationCoeffs2,
3850 theUVSurf2, theUVSurf1, aNbWLines,
3851 aPeriod, theTol3D, theTol2D, Standard_True);
3853 return CyCyNoGeometric(aCyl2, aCyl1, aBoundWork, anURange[1], aNbOfBoundaries,
3854 isTheEmpty, theSlin, theSPnt);
3858 const WorkWithBoundaries aBoundWork(theQuad1, theQuad2, anEquationCoeffs1,
3859 theUVSurf1, theUVSurf2, aNbWLines,
3860 aPeriod, theTol3D, theTol2D, Standard_False);
3862 return CyCyNoGeometric(aCyl1, aCyl2, aBoundWork, anURange[0], aNbOfBoundaries,
3863 isTheEmpty, theSlin, theSPnt);
3867 //=======================================================================
3868 //function : IntCySp
3870 //=======================================================================
3871 Standard_Boolean IntCySp(const IntSurf_Quadric& Quad1,
3872 const IntSurf_Quadric& Quad2,
3873 const Standard_Real Tol,
3874 const Standard_Boolean Reversed,
3875 Standard_Boolean& Empty,
3876 Standard_Boolean& Multpoint,
3877 IntPatch_SequenceOfLine& slin,
3878 IntPatch_SequenceOfPoint& spnt)
3883 IntSurf_TypeTrans trans1,trans2;
3884 IntAna_ResultType typint;
3885 IntPatch_Point ptsol;
3892 Cy = Quad1.Cylinder();
3893 Sp = Quad2.Sphere();
3896 Cy = Quad2.Cylinder();
3897 Sp = Quad1.Sphere();
3899 IntAna_QuadQuadGeo inter(Cy,Sp,Tol);
3901 if (!inter.IsDone()) {return Standard_False;}
3903 typint = inter.TypeInter();
3904 Standard_Integer NbSol = inter.NbSolutions();
3905 Empty = Standard_False;
3911 Empty = Standard_True;
3917 gp_Pnt psol(inter.Point(1));
3918 Standard_Real U1,V1,U2,V2;
3919 Quad1.Parameters(psol,U1,V1);
3920 Quad2.Parameters(psol,U2,V2);
3921 ptsol.SetValue(psol,Tol,Standard_True);
3922 ptsol.SetParameters(U1,V1,U2,V2);
3929 cirsol = inter.Circle(1);
3932 ElCLib::D1(0.,cirsol,ptref,Tgt);
3935 gp_Vec TestCurvature(ptref,Sp.Location());
3936 gp_Vec Normsp,Normcyl;
3938 Normcyl = Quad1.Normale(ptref);
3939 Normsp = Quad2.Normale(ptref);
3942 Normcyl = Quad2.Normale(ptref);
3943 Normsp = Quad1.Normale(ptref);
3946 IntSurf_Situation situcyl;
3947 IntSurf_Situation situsp;
3949 if (Normcyl.Dot(TestCurvature) > 0.) {
3950 situsp = IntSurf_Outside;
3951 if (Normsp.Dot(Normcyl) > 0.) {
3952 situcyl = IntSurf_Inside;
3955 situcyl = IntSurf_Outside;
3959 situsp = IntSurf_Inside;
3960 if (Normsp.Dot(Normcyl) > 0.) {
3961 situcyl = IntSurf_Outside;
3964 situcyl = IntSurf_Inside;
3967 Handle(IntPatch_GLine) glig;
3969 glig = new IntPatch_GLine(cirsol, Standard_True, situcyl, situsp);
3972 glig = new IntPatch_GLine(cirsol, Standard_True, situsp, situcyl);
3977 if (Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref)) > 0.0) {
3978 trans1 = IntSurf_Out;
3979 trans2 = IntSurf_In;
3982 trans1 = IntSurf_In;
3983 trans2 = IntSurf_Out;
3985 Handle(IntPatch_GLine) glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
3988 cirsol = inter.Circle(2);
3989 ElCLib::D1(0.,cirsol,ptref,Tgt);
3990 Standard_Real qwe = Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref));
3991 if(qwe> 0.0000001) {
3992 trans1 = IntSurf_Out;
3993 trans2 = IntSurf_In;
3995 else if(qwe<-0.0000001) {
3996 trans1 = IntSurf_In;
3997 trans2 = IntSurf_Out;
4000 trans1=trans2=IntSurf_Undecided;
4002 glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
4008 case IntAna_NoGeometricSolution:
4011 Standard_Real U1,V1,U2,V2;
4012 IntAna_IntQuadQuad anaint(Cy,Sp,Tol);
4013 if (!anaint.IsDone()) {
4014 return Standard_False;
4017 if (anaint.NbPnt()==0 && anaint.NbCurve()==0) {
4018 Empty = Standard_True;
4022 NbSol = anaint.NbPnt();
4023 for (i = 1; i <= NbSol; i++) {
4024 psol = anaint.Point(i);
4025 Quad1.Parameters(psol,U1,V1);
4026 Quad2.Parameters(psol,U2,V2);
4027 ptsol.SetValue(psol,Tol,Standard_True);
4028 ptsol.SetParameters(U1,V1,U2,V2);
4032 gp_Pnt ptvalid,ptf,ptl;
4034 Standard_Real first,last,para;
4035 IntAna_Curve curvsol;
4036 Standard_Boolean tgfound;
4037 Standard_Integer kount;
4039 NbSol = anaint.NbCurve();
4040 for (i = 1; i <= NbSol; i++) {
4041 curvsol = anaint.Curve(i);
4042 curvsol.Domain(first,last);
4043 ptf = curvsol.Value(first);
4044 ptl = curvsol.Value(last);
4048 tgfound = Standard_False;
4051 para = (1.123*first + para)/2.123;
4052 tgfound = curvsol.D1u(para,ptvalid,tgvalid);
4055 tgfound = kount > 5;
4058 Handle(IntPatch_ALine) alig;
4060 Standard_Real qwe = tgvalid.DotCross(Quad2.Normale(ptvalid),
4061 Quad1.Normale(ptvalid));
4062 if(qwe> 0.00000001) {
4063 trans1 = IntSurf_Out;
4064 trans2 = IntSurf_In;
4066 else if(qwe<-0.00000001) {
4067 trans1 = IntSurf_In;
4068 trans2 = IntSurf_Out;
4071 trans1=trans2=IntSurf_Undecided;
4073 alig = new IntPatch_ALine(curvsol,Standard_False,trans1,trans2);
4076 alig = new IntPatch_ALine(curvsol,Standard_False);
4078 Standard_Boolean TempFalse1a = Standard_False;
4079 Standard_Boolean TempFalse2a = Standard_False;
4081 //-- ptf et ptl : points debut et fin de alig
4083 ProcessBounds(alig,slin,Quad1,Quad2,TempFalse1a,ptf,first,
4084 TempFalse2a,ptl,last,Multpoint,Tol);
4086 } //-- boucle sur les lignes
4087 } //-- solution avec au moins une lihne
4093 return Standard_False;
4096 return Standard_True;
4098 //=======================================================================
4099 //function : IntCyCo
4101 //=======================================================================
4102 Standard_Boolean IntCyCo(const IntSurf_Quadric& Quad1,
4103 const IntSurf_Quadric& Quad2,
4104 const Standard_Real Tol,
4105 const Standard_Boolean Reversed,
4106 Standard_Boolean& Empty,
4107 Standard_Boolean& Multpoint,
4108 IntPatch_SequenceOfLine& slin,
4109 IntPatch_SequenceOfPoint& spnt)
4112 IntPatch_Point ptsol;
4116 IntSurf_TypeTrans trans1,trans2;
4117 IntAna_ResultType typint;
4124 Cy = Quad1.Cylinder();
4128 Cy = Quad2.Cylinder();
4131 IntAna_QuadQuadGeo inter(Cy,Co,Tol);
4133 if (!inter.IsDone()) {return Standard_False;}
4135 typint = inter.TypeInter();
4136 Standard_Integer NbSol = inter.NbSolutions();
4137 Empty = Standard_False;
4141 case IntAna_Empty : {
4142 Empty = Standard_True;
4146 case IntAna_Point :{
4147 gp_Pnt psol(inter.Point(1));
4148 Standard_Real U1,V1,U2,V2;
4149 Quad1.Parameters(psol,U1,V1);
4150 Quad1.Parameters(psol,U2,V2);
4151 ptsol.SetValue(psol,Tol,Standard_True);
4152 ptsol.SetParameters(U1,V1,U2,V2);
4157 case IntAna_Circle: {
4163 for(j=1; j<=2; ++j) {
4164 cirsol = inter.Circle(j);
4165 ElCLib::D1(0.,cirsol,ptref,Tgt);
4166 qwe = Tgt.DotCross(Quad2.Normale(ptref),Quad1.Normale(ptref));
4167 if(qwe> 0.00000001) {
4168 trans1 = IntSurf_Out;
4169 trans2 = IntSurf_In;
4171 else if(qwe<-0.00000001) {
4172 trans1 = IntSurf_In;
4173 trans2 = IntSurf_Out;
4176 trans1=trans2=IntSurf_Undecided;
4178 Handle(IntPatch_GLine) glig = new IntPatch_GLine(cirsol,Standard_False,trans1,trans2);
4184 case IntAna_NoGeometricSolution: {
4186 Standard_Real U1,V1,U2,V2;
4187 IntAna_IntQuadQuad anaint(Cy,Co,Tol);
4188 if (!anaint.IsDone()) {
4189 return Standard_False;
4192 if (anaint.NbPnt() == 0 && anaint.NbCurve() == 0) {
4193 Empty = Standard_True;
4196 NbSol = anaint.NbPnt();
4197 for (i = 1; i <= NbSol; i++) {
4198 psol = anaint.Point(i);
4199 Quad1.Parameters(psol,U1,V1);
4200 Quad2.Parameters(psol,U2,V2);
4201 ptsol.SetValue(psol,Tol,Standard_True);
4202 ptsol.SetParameters(U1,V1,U2,V2);
4206 gp_Pnt ptvalid, ptf, ptl;
4209 Standard_Real first,last,para;
4210 Standard_Boolean tgfound,firstp,lastp,kept;
4211 Standard_Integer kount;
4214 //IntAna_Curve curvsol;
4216 IntAna_ListOfCurve aLC;
4217 IntAna_ListIteratorOfListOfCurve aIt;
4220 NbSol = anaint.NbCurve();
4221 for (i = 1; i <= NbSol; ++i) {
4222 kept = Standard_False;
4223 //curvsol = anaint.Curve(i);
4226 ExploreCurve(Co, aC, 10.*Tol, aLC);
4228 aIt.Initialize(aLC);
4229 for (; aIt.More(); aIt.Next()) {
4230 IntAna_Curve& curvsol=aIt.Value();
4232 curvsol.Domain(first, last);
4233 firstp = !curvsol.IsFirstOpen();
4234 lastp = !curvsol.IsLastOpen();
4236 ptf = curvsol.Value(first);
4239 ptl = curvsol.Value(last);
4243 tgfound = Standard_False;
4246 para = (1.123*first + para)/2.123;
4247 tgfound = curvsol.D1u(para,ptvalid,tgvalid);
4250 tgfound = kount > 5;
4253 Handle(IntPatch_ALine) alig;
4255 Standard_Real qwe = tgvalid.DotCross(Quad2.Normale(ptvalid),
4256 Quad1.Normale(ptvalid));
4257 if(qwe> 0.00000001) {
4258 trans1 = IntSurf_Out;
4259 trans2 = IntSurf_In;
4261 else if(qwe<-0.00000001) {
4262 trans1 = IntSurf_In;
4263 trans2 = IntSurf_Out;
4266 trans1=trans2=IntSurf_Undecided;
4268 alig = new IntPatch_ALine(curvsol,Standard_False,trans1,trans2);
4269 kept = Standard_True;
4272 ptvalid = curvsol.Value(para);
4273 alig = new IntPatch_ALine(curvsol,Standard_False);
4274 kept = Standard_True;
4275 //-- std::cout << "Transition indeterminee" << std::endl;
4278 Standard_Boolean Nfirstp = !firstp;
4279 Standard_Boolean Nlastp = !lastp;
4280 ProcessBounds(alig,slin,Quad1,Quad2,Nfirstp,ptf,first,
4281 Nlastp,ptl,last,Multpoint,Tol);
4284 } // for (; aIt.More(); aIt.Next())
4285 } // for (i = 1; i <= NbSol; ++i)
4291 return Standard_False;
4293 } // switch (typint)
4295 return Standard_True;
4297 //=======================================================================
4298 //function : ExploreCurve
4299 //purpose : Splits aC on several curves in the cone apex points.
4300 //=======================================================================
4301 Standard_Boolean ExploreCurve(const gp_Cone& theCo,
4302 IntAna_Curve& theCrv,
4303 const Standard_Real theTol,
4304 IntAna_ListOfCurve& theLC)
4306 const Standard_Real aSqTol = theTol*theTol;
4307 const gp_Pnt aPapx(theCo.Apex());
4309 Standard_Real aT1, aT2;
4310 theCrv.Domain(aT1, aT2);
4314 TColStd_ListOfReal aLParams;
4315 theCrv.FindParameter(aPapx, aLParams);
4316 if (aLParams.IsEmpty())
4318 theLC.Append(theCrv);
4319 return Standard_False;
4322 for (TColStd_ListIteratorOfListOfReal anItr(aLParams); anItr.More(); anItr.Next())
4324 Standard_Real aPrm = anItr.Value();
4326 if ((aPrm - aT1) < Precision::PConfusion())
4329 Standard_Boolean isLast = Standard_False;
4330 if ((aT2 - aPrm) < Precision::PConfusion())
4333 isLast = Standard_True;
4336 const gp_Pnt aP = theCrv.Value(aPrm);
4337 const Standard_Real aSqD = aP.SquareDistance(aPapx);
4340 IntAna_Curve aC1 = theCrv;
4341 aC1.SetDomain(aT1, aPrm);
4350 if (theLC.IsEmpty())
4352 theLC.Append(theCrv);
4353 return Standard_False;
4356 if ((aT2 - aT1) > Precision::PConfusion())
4358 IntAna_Curve aC1 = theCrv;
4359 aC1.SetDomain(aT1, aT2);
4363 return Standard_True;