1// Created on: 1995-07-18
2// Created by: Modelistation
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
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.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#include <StdFail_NotDone.hxx>
18#include <math_FunctionSetRoot.hxx>
19#include <math_Vector.hxx>
20
21//=============================================================================
22Extrema_GenLocateExtCC::Extrema_GenLocateExtCC (const Curve1& C1,
23					  const Curve2& C2,
24					  const Standard_Real U0, const Standard_Real V0,
25					  const Standard_Real TolU, const Standard_Real TolV)
26/*-----------------------------------------------------------------------------
27Fonction:
28  Recherche du couple de valeurs de parametre (U,V) tel que:
29  - dist(C1(u),C2(v)) passe par un extremum,
30  - (U,V) soit la solution la plus proche de (U0,V0).
31
32Methode:
33  Si (u,v) est solution, alors:
34   { F1(u,v)=(C1(u)-C2(v)).dC1/du(u) = 0.
35   { F2(u,v)=(C1(u)-C2(v)).dC2/dv(v) = 0.
36  Le probleme consiste a rechercher, dans les intervalles de definition
37  des courbes, la racine du systeme la plus proche de (U0,V0).
38  On utilise la classe math_FunctionSetRoot avec les arguments de construction
39  suivants:
40  - F: Extrema_FuncExtCC cree a partir de C1 et C2,
41  - math_Vector(U0,V0),
42  - math_Vector(TolU,TolV),
43  - math_Vector(Uinf,Usup),
44  - math_Vector(Vinf,Vsup),
45  - 100. .
46-----------------------------------------------------------------------------*/
47{
48  myDone = Standard_False;
49  mySqDist = RealLast();
50
51  Standard_Real Uinf = Tool1::FirstParameter(C1);
52  Standard_Real Usup = Tool1::LastParameter(C1);
53  Standard_Real Uu;
54  if (Uinf>Usup) {
55     Uu=Uinf;
56     Uinf=Usup;
57     Usup =Uu;
58  }
59
60  Standard_Real Vinf = Tool2::FirstParameter(C2);
61  Standard_Real Vsup = Tool2::LastParameter(C2);
62  if (Vinf>Vsup) {
63     Uu=Vinf;
64     Vinf=Vsup;
65     Vsup =Uu;
66  }
67
68  Extrema_CCLocF F (C1,C2);
69  math_Vector Tol(1, 2);
70  Tol(1) = TolU;
71  Tol(2) = TolV;
72  Standard_Real Tolf = 1.e-10;
73
74  math_Vector Start(1,2);
75  math_Vector Uuinf(1,2);
76  math_Vector Uusup(1,2);
77
78  Start(1) = U0;
79  Start(2) = V0;
80
81  Uuinf(1)=Uinf;
82  Uuinf(2)=Vinf;
83  Uusup(1)=Usup;
84  Uusup(2)=Vsup;
85
86  math_FunctionSetRoot S(F, Tol);
87  S.Perform(F, Start, Uuinf, Uusup);
88
89  if (S.IsDone() && F.NbExt() > 0) {
90    mySqDist = F.SquareDistance(1);
91    F.Points(1,myPoint1,myPoint2);
92    Start(1)=myPoint1.Parameter();
93    Start(2)=myPoint2.Parameter();
94    math_Vector Ff(1,2);
95    F.Value(Start,Ff);
96//    cout << "Ff(1) = "<<Ff(1)<<endl;
97//    cout << "Ff(2) = "<<Ff(2)<<endl;
98    if ((Ff(1)<Tolf) && (Ff(2)<Tolf) ) myDone = Standard_True;
99  }
100}
101//=============================================================================
102
103Standard_Boolean Extrema_GenLocateExtCC::IsDone () const { return myDone; }
104//=============================================================================
105
106Standard_Real Extrema_GenLocateExtCC::SquareDistance() const
107{
108  if (!IsDone()) { throw StdFail_NotDone(); }
109  return mySqDist;
110}
111//=============================================================================
112
113void Extrema_GenLocateExtCC::Point (POnC& P1, POnC& P2)
114     const
115{
116  if (!IsDone()) { throw StdFail_NotDone(); }
117  P1 = myPoint1;
118  P2 = myPoint2;
119}
120//=============================================================================
121