1 // Created on: 1996-01-09
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1996-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 <Adaptor3d_Curve.hxx>
19 #include <Adaptor3d_Surface.hxx>
20 #include <Extrema_FuncExtCS.hxx>
21 #include <Extrema_POnCurv.hxx>
22 #include <Extrema_POnSurf.hxx>
24 #include <math_Matrix.hxx>
25 #include <Precision.hxx>
26 #include <Standard_OutOfRange.hxx>
27 #include <Standard_TypeMismatch.hxx>
29 /*-----------------------------------------------------------------------------
30 Fonction permettant de rechercher une distance extremale entre une courbe C
32 Cette classe herite de math_FunctionWithDerivative et est utilisee par
33 les algorithmes math_FunctionRoot et math_FunctionRoots.
34 { F1(t,u,v) = (C(t)-S(u,v)).Dtc(t) }
35 { F2(t,u,v) = (C(t)-S(u,v)).Dus(u,v) }
36 { F3(t,u,v) = (C(t)-S(u,v)).Dvs(u,v) }
37 { Dtf1(t,u,v) = Dtc(t).Dtc(t)+(C(t)-S(u,v)).Dttc(t)
38 = ||Dtc(t)||**2+(C(t)-S(u,v)).Dttc(t) }
39 { Duf1(t,u,v) = -Dus(u,v).Dtc(t) }
40 { Dvf1(t,u,v) = -Dvs(u,v).Dtc(t) }
41 { Dtf2(t,u,v) = Dtc(t).Dus(u,v) }
42 { Duf2(t,u,v) = -Dus(u,v).Dus(u,v)+(C(t)-S(u,v)).Duus(u,v)
43 = -||Dus(u,v)||**2+(C(t)-S(u,v)).Duus(u,v) }
44 { Dvf2(t,u,v) = -Dvs(u,v).Dus(u,v)+(C(t)-S(u,v)).Duvs(u,v) }
45 { Dtf3(t,u,v) = Dtc(t).Dvs(u,v) }
46 { Duf3(t,u,v) = -Dus(u,v).Dvs(u,v)+(C(t)-S(u,v)).Duvs(u,v) }
47 { Dvf3(t,u,v) = -Dvs(u,v).Dvs(u,v)+(C(t)-S(u,v)).Dvvs(u,v) }
48 ----------------------------------------------------------------------------*/
49 //=======================================================================
50 //function : Extrema_FuncExtCS
52 //=======================================================================
53 Extrema_FuncExtCS::Extrema_FuncExtCS()
55 myCinit = Standard_False;
56 mySinit = Standard_False;
59 //=======================================================================
60 //function : Extrema_FuncExtCS
62 //=======================================================================
64 Extrema_FuncExtCS::Extrema_FuncExtCS(const Adaptor3d_Curve& C,
65 const Adaptor3d_Surface& S)
70 //=======================================================================
71 //function : Initialize
73 //=======================================================================
75 void Extrema_FuncExtCS::Initialize(const Adaptor3d_Curve& C,
76 const Adaptor3d_Surface& S)
78 myC = (Adaptor3d_CurvePtr)&C;
79 myS = (Adaptor3d_SurfacePtr)&S;
80 myCinit = Standard_True;
81 mySinit = Standard_True;
87 //=======================================================================
88 //function : NbVariables
90 //=======================================================================
92 Standard_Integer Extrema_FuncExtCS::NbVariables() const
97 //=======================================================================
98 //function : NbEquations
100 //=======================================================================
102 Standard_Integer Extrema_FuncExtCS::NbEquations() const
107 //=======================================================================
110 //=======================================================================
112 Standard_Boolean Extrema_FuncExtCS::Value(const math_Vector& UV,
115 if (!myCinit || !mySinit) throw Standard_TypeMismatch();
123 /// gp_Vec Dus, Dvs, Duvs, Duus, Dvvs;
125 myC->D1(myt, myP1, Dtc);
126 myS->D1(myU,myV,myP2,Dus,Dvs);
128 gp_Vec P1P2 (myP2,myP1);
130 F(1) = P1P2.Dot(Dtc);
131 F(2) = P1P2.Dot(Dus);
132 F(3) = P1P2.Dot(Dvs);
134 return Standard_True;
137 //=======================================================================
138 //function : Derivatives
140 //=======================================================================
142 Standard_Boolean Extrema_FuncExtCS::Derivatives(const math_Vector& UV,
146 return Values(UV,F,DF);
149 //=======================================================================
152 //=======================================================================
154 Standard_Boolean Extrema_FuncExtCS::Values(const math_Vector& UV,
158 if (!myCinit || !mySinit) throw Standard_TypeMismatch();
165 gp_Vec Dus, Dvs, Duvs, Duus, Dvvs;
166 myC->D2(myt, myP1, Dtc, Dttc);
167 myS->D2(myU,myV,myP2,Dus,Dvs,Duus,Dvvs,Duvs);
169 gp_Vec P1P2 (myP2,myP1);
171 F(1) = P1P2.Dot(Dtc);
172 F(2) = P1P2.Dot(Dus);
173 F(3) = P1P2.Dot(Dvs);
175 Df(1,1) = Dtc.SquareMagnitude() + P1P2.Dot(Dttc);
176 Df(1,2) = -Dus.Dot(Dtc);
177 Df(1,3) = -Dvs.Dot(Dtc);
179 Df(2,1) = -Df(1, 2); // Dtc.Dot(Dus);
180 Df(2,2) = -Dus.SquareMagnitude()+P1P2.Dot(Duus);
181 Df(2,3) = -Dvs.Dot(Dus)+P1P2.Dot(Duvs);
183 Df(3,1) = -Df(1,3); // Dtc.Dot(Dvs);
184 Df(3,2) = Df(2,3); // -Dus.Dot(Dvs)+P1P2.Dot(Duvs);
185 Df(3,3) = -Dvs.SquareMagnitude()+P1P2.Dot(Dvvs);
187 return Standard_True;
191 //=======================================================================
192 //function : GetStateNumber
194 //=======================================================================
196 Standard_Integer Extrema_FuncExtCS::GetStateNumber()
198 if (!myCinit || !mySinit) throw Standard_TypeMismatch();
200 math_Vector Sol(1, 3), UVSol(1, 3);
201 UVSol(1) = myt; UVSol(2) = myU; UVSol(3) = myV;
203 cout <<"F(1)= "<<Sol(1)<<" F(2)= "<<Sol(2)<<" F(3)= "<<Sol(3)<<endl;
205 //comparison of solution with previous solutions
206 Standard_Real tol2d = Precision::PConfusion() * Precision::PConfusion();
207 Standard_Integer i = 1, nbSol = mySqDist.Length();
208 for( ; i <= nbSol; i++)
210 Standard_Real aT = myPoint1(i).Parameter();
211 if( (myt - aT) * (myt - aT) <= tol2d )
216 mySqDist.Append(myP1.SquareDistance(myP2));
217 myPoint1.Append(Extrema_POnCurv(myt,myP1));
218 myPoint2.Append(Extrema_POnSurf(myU,myV,myP2));
222 //=======================================================================
225 //=======================================================================
227 Standard_Integer Extrema_FuncExtCS::NbExt() const
229 return mySqDist.Length();
232 //=======================================================================
233 //function : SquareDistance
235 //=======================================================================
237 Standard_Real Extrema_FuncExtCS::SquareDistance(const Standard_Integer N) const
239 if (!myCinit || !mySinit) throw Standard_TypeMismatch();
240 return mySqDist.Value(N);
243 //=======================================================================
244 //function : PointOnCurve
246 //=======================================================================
248 const Extrema_POnCurv& Extrema_FuncExtCS::PointOnCurve(const Standard_Integer N) const
250 if (!myCinit || !mySinit) throw Standard_TypeMismatch();
251 return myPoint1.Value(N);
254 //=======================================================================
255 //function : PointOnSurface
257 //=======================================================================
259 const Extrema_POnSurf& Extrema_FuncExtCS::PointOnSurface(const Standard_Integer N) const
261 if (!myCinit || !mySinit) throw Standard_TypeMismatch();
262 return myPoint2.Value(N);
265 //=======================================================================
268 //=======================================================================
270 Adaptor3d_SurfacePtr Extrema_FuncExtCS::Bidon1() const
272 return (Adaptor3d_SurfacePtr)0L;
275 //=======================================================================
278 //=======================================================================
280 Adaptor3d_CurvePtr Extrema_FuncExtCS::Bidon2() const
282 return (Adaptor3d_CurvePtr)0L;