Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Extrema / Extrema_GenLocateExtCC.gxx
1 // File:        Extrema_GenLocateExtCC.gxx
2 // Created:     Tue Jul 18 17:43:58 1995
3 // Author:      Modelistation
4 //              <model@metrox>
5
6 #include <StdFail_NotDone.hxx>
7 #include <math_FunctionSetRoot.hxx>
8 #include <math_Vector.hxx>
9
10 //=============================================================================
11 Extrema_GenLocateExtCC::Extrema_GenLocateExtCC (const Curve1& C1,
12                                           const Curve2& C2,
13                                           const Standard_Real U0, const Standard_Real V0,
14                                           const Standard_Real TolU, const Standard_Real TolV)
15 /*-----------------------------------------------------------------------------
16 Fonction:
17   Recherche du couple de valeurs de parametre (U,V) tel que:
18   - dist(C1(u),C2(v)) passe par un extremum,
19   - (U,V) soit la solution la plus proche de (U0,V0).
20
21 Methode:
22   Si (u,v) est solution, alors:
23    { F1(u,v)=(C1(u)-C2(v)).dC1/du(u) = 0.
24    { F2(u,v)=(C1(u)-C2(v)).dC2/dv(v) = 0.
25   Le probleme consiste a rechercher, dans les intervalles de definition
26   des courbes, la racine du systeme la plus proche de (U0,V0).
27   On utilise la classe math_FunctionSetRoot avec les arguments de construction
28   suivants:
29   - F: Extrema_FuncExtCC cree a partir de C1 et C2,
30   - math_Vector(U0,V0),
31   - math_Vector(TolU,TolV),
32   - math_Vector(Uinf,Usup),
33   - math_Vector(Vinf,Vsup),
34   - 100. .
35 -----------------------------------------------------------------------------*/
36 {
37   myDone = Standard_False;
38
39   Standard_Real Uinf = Tool1::FirstParameter(C1);
40   Standard_Real Usup = Tool1::LastParameter(C1);
41   Standard_Real Uu;
42   if (Uinf>Usup) {
43      Uu=Uinf;
44      Uinf=Usup;
45      Usup =Uu;
46   }
47
48   Standard_Real Vinf = Tool2::FirstParameter(C2);
49   Standard_Real Vsup = Tool2::LastParameter(C2);
50   if (Vinf>Vsup) {
51      Uu=Vinf;
52      Vinf=Vsup;
53      Vsup =Uu;
54   }
55
56   Extrema_CCLocF F (C1,C2);
57   math_Vector Tol(1, 2);
58   Tol(1) = TolU;
59   Tol(2) = TolV;
60   Standard_Real Tolf = 1.e-10;
61
62   math_Vector Start(1,2);
63   math_Vector Uuinf(1,2);
64   math_Vector Uusup(1,2);
65
66   Start(1) = U0;
67   Start(2) = V0;
68
69   Uuinf(1)=Uinf;
70   Uuinf(2)=Vinf;
71   Uusup(1)=Usup;
72   Uusup(2)=Vsup;
73
74   math_FunctionSetRoot S (F,Start,Tol,Uuinf,Uusup);
75   if (S.IsDone() && F.NbExt() > 0) { 
76     mySqDist = F.SquareDistance(1);
77     F.Points(1,myPoint1,myPoint2);
78     Start(1)=myPoint1.Parameter();
79     Start(2)=myPoint2.Parameter();
80     math_Vector Ff(1,2);
81     F.Value(Start,Ff);
82 //    cout << "Ff(1) = "<<Ff(1)<<endl;
83 //    cout << "Ff(2) = "<<Ff(2)<<endl;
84     if ((Ff(1)<Tolf) && (Ff(2)<Tolf) ) myDone = Standard_True;
85   }
86 }
87 //=============================================================================
88
89 Standard_Boolean Extrema_GenLocateExtCC::IsDone () const { return myDone; }
90 //=============================================================================
91
92 Standard_Real Extrema_GenLocateExtCC::SquareDistance() const
93 {
94   if (!IsDone()) { StdFail_NotDone::Raise(); }
95   return mySqDist;
96 }
97 //=============================================================================
98
99 void Extrema_GenLocateExtCC::Point (POnC& P1, POnC& P2)
100      const
101 {
102   if (!IsDone()) { StdFail_NotDone::Raise(); }
103   P1 = myPoint1;
104   P2 = myPoint2;
105 }
106 //=============================================================================