0024138: Exception during projection of the point on the face
[occt.git] / src / Extrema / Extrema_GenLocateExtCC.gxx
1 // Created on: 1995-07-18
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <StdFail_NotDone.hxx>
23 #include <math_FunctionSetRoot.hxx>
24 #include <math_Vector.hxx>
25
26 //=============================================================================
27 Extrema_GenLocateExtCC::Extrema_GenLocateExtCC (const Curve1& C1,
28                                           const Curve2& C2,
29                                           const Standard_Real U0, const Standard_Real V0,
30                                           const Standard_Real TolU, const Standard_Real TolV)
31 /*-----------------------------------------------------------------------------
32 Fonction:
33   Recherche du couple de valeurs de parametre (U,V) tel que:
34   - dist(C1(u),C2(v)) passe par un extremum,
35   - (U,V) soit la solution la plus proche de (U0,V0).
36
37 Methode:
38   Si (u,v) est solution, alors:
39    { F1(u,v)=(C1(u)-C2(v)).dC1/du(u) = 0.
40    { F2(u,v)=(C1(u)-C2(v)).dC2/dv(v) = 0.
41   Le probleme consiste a rechercher, dans les intervalles de definition
42   des courbes, la racine du systeme la plus proche de (U0,V0).
43   On utilise la classe math_FunctionSetRoot avec les arguments de construction
44   suivants:
45   - F: Extrema_FuncExtCC cree a partir de C1 et C2,
46   - math_Vector(U0,V0),
47   - math_Vector(TolU,TolV),
48   - math_Vector(Uinf,Usup),
49   - math_Vector(Vinf,Vsup),
50   - 100. .
51 -----------------------------------------------------------------------------*/
52 {
53   myDone = Standard_False;
54
55   Standard_Real Uinf = Tool1::FirstParameter(C1);
56   Standard_Real Usup = Tool1::LastParameter(C1);
57   Standard_Real Uu;
58   if (Uinf>Usup) {
59      Uu=Uinf;
60      Uinf=Usup;
61      Usup =Uu;
62   }
63
64   Standard_Real Vinf = Tool2::FirstParameter(C2);
65   Standard_Real Vsup = Tool2::LastParameter(C2);
66   if (Vinf>Vsup) {
67      Uu=Vinf;
68      Vinf=Vsup;
69      Vsup =Uu;
70   }
71
72   Extrema_CCLocF F (C1,C2);
73   math_Vector Tol(1, 2);
74   Tol(1) = TolU;
75   Tol(2) = TolV;
76   Standard_Real Tolf = 1.e-10;
77
78   math_Vector Start(1,2);
79   math_Vector Uuinf(1,2);
80   math_Vector Uusup(1,2);
81
82   Start(1) = U0;
83   Start(2) = V0;
84
85   Uuinf(1)=Uinf;
86   Uuinf(2)=Vinf;
87   Uusup(1)=Usup;
88   Uusup(2)=Vsup;
89
90   math_FunctionSetRoot S (F,Start,Tol,Uuinf,Uusup);
91   if (S.IsDone() && F.NbExt() > 0) { 
92     mySqDist = F.SquareDistance(1);
93     F.Points(1,myPoint1,myPoint2);
94     Start(1)=myPoint1.Parameter();
95     Start(2)=myPoint2.Parameter();
96     math_Vector Ff(1,2);
97     F.Value(Start,Ff);
98 //    cout << "Ff(1) = "<<Ff(1)<<endl;
99 //    cout << "Ff(2) = "<<Ff(2)<<endl;
100     if ((Ff(1)<Tolf) && (Ff(2)<Tolf) ) myDone = Standard_True;
101   }
102 }
103 //=============================================================================
104
105 Standard_Boolean Extrema_GenLocateExtCC::IsDone () const { return myDone; }
106 //=============================================================================
107
108 Standard_Real Extrema_GenLocateExtCC::SquareDistance() const
109 {
110   if (!IsDone()) { StdFail_NotDone::Raise(); }
111   return mySqDist;
112 }
113 //=============================================================================
114
115 void Extrema_GenLocateExtCC::Point (POnC& P1, POnC& P2)
116      const
117 {
118   if (!IsDone()) { StdFail_NotDone::Raise(); }
119   P1 = myPoint1;
120   P2 = myPoint2;
121 }
122 //=============================================================================