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_Surface.hxx>
19 #include <Extrema_FuncExtSS.hxx>
20 #include <Extrema_POnSurf.hxx>
22 #include <math_Matrix.hxx>
23 #include <Standard_OutOfRange.hxx>
24 #include <Standard_TypeMismatch.hxx>
26 /*----------------------------------------------------------------------------
27 Si on note Du1s et Dv1s, les derivees en u1 et v1, les 2 fonctions a annuler sont:
28 Si on note Du2s et Dv2s, les derivees en u2 et v2, les 2 fonctions a annuler sont:
29 { F1(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Du1s1(u1,v1) }
30 { F2(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Dv1s1(u1,v1) }
31 { F3(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Du2s2(u2,v2) }
32 { F4(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Dv2s2(u2,v2) }
33 { du1f1(u1,v1,u2,v2) = Du1s1(u1,v1).Du1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1u1s1(u1,v1)
34 = ||Du1s1(u1,v1)||**2 +(S1(u1,v1)-S2(u2,v2)).Du1u1s1(u1,v1) }
35 { dv1f1(u1,v1,u2,v2) = Dv1s1(u1,v1).Du1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1v1s1(u1,v1) }
36 { du2f1(u1,v1,u2,v2) = -Du2s2(u2,v2).Du1s1(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v2)).Dv2v2s2(u2,v2) }
53 ----------------------------------------------------------------------------*/
54 //=======================================================================
55 //function : Extrema_FuncExtSS
57 //=======================================================================
58 Extrema_FuncExtSS::Extrema_FuncExtSS ()
60 myS1init = Standard_False;
61 myS2init = Standard_False;
64 //=======================================================================
65 //function : Extrema_FuncExtSS
67 //=======================================================================
69 Extrema_FuncExtSS::Extrema_FuncExtSS (const Adaptor3d_Surface& S1,
70 const Adaptor3d_Surface& S2)
72 myS1 = (Adaptor3d_SurfacePtr)&S1;
73 myS2 = (Adaptor3d_SurfacePtr)&S2;
74 myS1init = Standard_True;
75 myS2init = Standard_True;
78 //=======================================================================
79 //function : Initialize
81 //=======================================================================
83 void Extrema_FuncExtSS::Initialize(const Adaptor3d_Surface& S1,
84 const Adaptor3d_Surface& S2)
86 myS1 = (Adaptor3d_SurfacePtr)&S1;
87 myS2 = (Adaptor3d_SurfacePtr)&S2;
88 myS1init = Standard_True;
89 myS2init = Standard_True;
97 //=======================================================================
98 //function : NbVariables
100 //=======================================================================
102 Standard_Integer Extrema_FuncExtSS::NbVariables () const { return 4;}
105 //=======================================================================
106 //function : NbEquations
108 //=======================================================================
110 Standard_Integer Extrema_FuncExtSS::NbEquations () const { return 4;}
113 //=======================================================================
116 //=======================================================================
118 Standard_Boolean Extrema_FuncExtSS::Value (const math_Vector& UV,
121 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
128 myS1->D1(myU1,myV1,myP1,Du1s1,Dv1s1);
129 myS2->D1(myU2,myV2,myP2,Du2s2,Dv2s2);
131 gp_Vec P1P2 (myP2,myP1);
133 F(1) = P1P2.Dot(Du1s1);
134 F(2) = P1P2.Dot(Dv1s1);
135 F(3) = P1P2.Dot(Du2s2);
136 F(4) = P1P2.Dot(Dv2s2);
138 return Standard_True;
141 //=======================================================================
142 //function : Derivatives
144 //=======================================================================
146 Standard_Boolean Extrema_FuncExtSS::Derivatives (const math_Vector& UV,
150 return Values(UV,F,Df);
153 //=======================================================================
156 //=======================================================================
158 Standard_Boolean Extrema_FuncExtSS::Values (const math_Vector& UV,
162 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
167 gp_Vec Du1s1, Dv1s1, Du1u1s1, Dv1v1s1, Du1v1s1;
168 gp_Vec Du2s2, Dv2s2, Du2u2s2, Dv2v2s2, Du2v2s2;
169 myS1->D2(myU1,myV1,myP1,Du1s1,Dv1s1,Du1u1s1,Dv1v1s1,Du1v1s1);
170 myS2->D2(myU2,myV2,myP2,Du2s2,Dv2s2,Du2u2s2,Dv2v2s2,Du2v2s2);
172 gp_Vec P1P2 (myP2,myP1);
174 F(1) = P1P2.Dot(Du1s1);
175 F(2) = P1P2.Dot(Dv1s1);
176 F(3) = P1P2.Dot(Du2s2);
177 F(4) = P1P2.Dot(Dv2s2);
179 Df(1,1) = Du1s1.SquareMagnitude() + P1P2.Dot(Du1u1s1);
180 Df(1,2) = Dv1s1.Dot(Du1s1) + P1P2.Dot(Du1v1s1);
181 Df(1,3) = -Du2s2.Dot(Du1s1);
182 Df(1,4) = -Dv2s2.Dot(Du1s1);
184 Df(2,1) = Df(1, 2); // Du1s1.Dot(Dv1s1) + P1P2.Dot(Du1v1s1);
185 Df(2,2) = Dv1s1.SquareMagnitude() + P1P2.Dot(Dv1v1s1);
186 Df(2,3) = -Du2s2.Dot(Dv1s1);
187 Df(2,4) = -Dv2s2.Dot(Dv1s1);
189 Df(3,1) = -Df(1,3); // Du1s1.Dot(Du2s2);
190 Df(3,2) = -Df(2,3); // Dv1s1.Dot(Du2s2);
191 Df(3,3) = -Du2s2.SquareMagnitude() + P1P2.Dot(Du2u2s2);
192 Df(3,4) = -Dv2s2.Dot(Du2s2) + P1P2.Dot(Du2v2s2);
194 Df(4,1) = -Df(1,4); // Du1s1.Dot(Dv2s2);
195 Df(4,2) = -Df(2,4); // Dv1s1.Dot(Dv2s2);
196 Df(4,3) = Df(3,4); // -Du2s2.Dot(Dv2s2) + P1P2.Dot(Du2v2s2);
197 Df(4,4) = -Dv2s2.SquareMagnitude() + P1P2.Dot(Dv2v2s2);
199 return Standard_True;
202 //=======================================================================
203 //function : GetStateNumber
205 //=======================================================================
207 Standard_Integer Extrema_FuncExtSS::GetStateNumber ()
209 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
211 math_Vector Sol(1, 4), UVSol(1, 4);
212 UVSol(1) = myU1; UVSol(2) = myV1; UVSol(3) = myU2; UVSol(4) = myV2;
214 cout <<"F(1)= "<<Sol(1)<<" F(2)= "<<Sol(2)<<" F(3)= "<<Sol(3)<<" F(4)= "<<Sol(4)<<endl;
217 mySqDist.Append(myP1.SquareDistance(myP2));
218 myPoint1.Append(Extrema_POnSurf(myU1,myV1,myP1));
219 myPoint2.Append(Extrema_POnSurf(myU2,myV2,myP2));
223 //=======================================================================
226 //=======================================================================
228 Standard_Integer Extrema_FuncExtSS::NbExt () const
230 return mySqDist.Length();
233 //=======================================================================
234 //function : SquareDistance
236 //=======================================================================
238 Standard_Real Extrema_FuncExtSS::SquareDistance (const Standard_Integer N) const
240 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
241 return mySqDist.Value(N);
244 //=======================================================================
245 //function : PointOnS1
247 //=======================================================================
249 const Extrema_POnSurf& Extrema_FuncExtSS::PointOnS1 (const Standard_Integer N) const
251 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
252 return myPoint1.Value(N);
254 //=======================================================================
255 //function : PointOnS2
257 //=======================================================================
259 const Extrema_POnSurf& Extrema_FuncExtSS::PointOnS2 (const Standard_Integer N) const
261 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
262 return myPoint2.Value(N);