1 // Created on: 1996-01-09
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
23 #include <Extrema_FuncExtSS.ixx>
24 #include <Standard_TypeMismatch.hxx>
28 /*----------------------------------------------------------------------------
29 Si on note Du1s et Dv1s, les derivees en u1 et v1, les 2 fonctions a annuler sont:
30 Si on note Du2s et Dv2s, les derivees en u2 et v2, les 2 fonctions a annuler sont:
32 { F1(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Du1s1(u1,v1) }
33 { F2(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Dv1s1(u1,v1) }
34 { F3(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Du2s2(u2,v2) }
35 { F4(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Dv2s2(u2,v2) }
37 { du1f1(u1,v1,u2,v2) = Du1s1(u1,v1).Du1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1u1s1(u1,v1)
38 = ||Du1s1(u1,v1)||**2 +(S1(u1,v1)-S2(u2,v2)).Du1u1s1(u1,v1) }
39 { dv1f1(u1,v1,u2,v2) = Dv1s1(u1,v1).Du1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1v1s1(u1,v1) }
40 { du2f1(u1,v1,u2,v2) = -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(S1(u1,v1)-S2(u2,v2)).Dv2v2s2(u2,v2) }
61 ----------------------------------------------------------------------------*/
64 //=======================================================================
65 //function : Extrema_FuncExtSS
67 //=======================================================================
69 Extrema_FuncExtSS::Extrema_FuncExtSS ()
71 myS1init = Standard_False;
72 myS2init = Standard_False;
75 //=======================================================================
76 //function : Extrema_FuncExtSS
78 //=======================================================================
80 Extrema_FuncExtSS::Extrema_FuncExtSS (const Adaptor3d_Surface& S1,
81 const Adaptor3d_Surface& S2)
83 myS1 = (Adaptor3d_SurfacePtr)&S1;
84 myS2 = (Adaptor3d_SurfacePtr)&S2;
85 myS1init = Standard_True;
86 myS2init = Standard_True;
89 //=======================================================================
90 //function : Initialize
92 //=======================================================================
94 void Extrema_FuncExtSS::Initialize(const Adaptor3d_Surface& S1,
95 const Adaptor3d_Surface& S2)
97 myS1 = (Adaptor3d_SurfacePtr)&S1;
98 myS2 = (Adaptor3d_SurfacePtr)&S2;
99 myS1init = Standard_True;
100 myS2init = Standard_True;
108 //=======================================================================
109 //function : NbVariables
111 //=======================================================================
113 Standard_Integer Extrema_FuncExtSS::NbVariables () const { return 4;}
116 //=======================================================================
117 //function : NbEquations
119 //=======================================================================
121 Standard_Integer Extrema_FuncExtSS::NbEquations () const { return 4;}
124 //=======================================================================
127 //=======================================================================
129 Standard_Boolean Extrema_FuncExtSS::Value (const math_Vector& UV,
132 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
139 myS1->D1(myU1,myV1,myP1,Du1s1,Dv1s1);
140 myS2->D1(myU2,myV2,myP2,Du2s2,Dv2s2);
142 gp_Vec P1P2 (myP2,myP1);
144 F(1) = P1P2.Dot(Du1s1);
145 F(2) = P1P2.Dot(Dv1s1);
146 F(3) = P1P2.Dot(Du2s2);
147 F(4) = P1P2.Dot(Dv2s2);
149 return Standard_True;
152 //=======================================================================
153 //function : Derivatives
155 //=======================================================================
157 Standard_Boolean Extrema_FuncExtSS::Derivatives (const math_Vector& UV,
161 return Values(UV,F,Df);
164 //=======================================================================
167 //=======================================================================
169 Standard_Boolean Extrema_FuncExtSS::Values (const math_Vector& UV,
173 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
178 gp_Vec Du1s1, Dv1s1, Du1u1s1, Dv1v1s1, Du1v1s1;
179 gp_Vec Du2s2, Dv2s2, Du2u2s2, Dv2v2s2, Du2v2s2;
180 myS1->D2(myU1,myV1,myP1,Du1s1,Dv1s1,Du1u1s1,Dv1v1s1,Du1v1s1);
181 myS2->D2(myU2,myV2,myP2,Du2s2,Dv2s2,Du2u2s2,Dv2v2s2,Du2v2s2);
183 gp_Vec P1P2 (myP2,myP1);
185 F(1) = P1P2.Dot(Du1s1);
186 F(2) = P1P2.Dot(Dv1s1);
187 F(3) = P1P2.Dot(Du2s2);
188 F(4) = P1P2.Dot(Dv2s2);
190 Df(1,1) = Du1s1.SquareMagnitude() + P1P2.Dot(Du1u1s1);
191 Df(1,2) = Dv1s1.Dot(Du1s1) + P1P2.Dot(Du1v1s1);
192 Df(1,3) = -Du2s2.Dot(Du1s1);
193 Df(1,4) = -Dv2s2.Dot(Du1s1);
195 Df(2,1) = Df(1, 2); // Du1s1.Dot(Dv1s1) + P1P2.Dot(Du1v1s1);
196 Df(2,2) = Dv1s1.SquareMagnitude() + P1P2.Dot(Dv1v1s1);
197 Df(2,3) = -Du2s2.Dot(Dv1s1);
198 Df(2,4) = -Dv2s2.Dot(Dv1s1);
200 Df(3,1) = -Df(1,3); // Du1s1.Dot(Du2s2);
201 Df(3,2) = -Df(2,3); // Dv1s1.Dot(Du2s2);
202 Df(3,3) = -Du2s2.SquareMagnitude() + P1P2.Dot(Du2u2s2);
203 Df(3,4) = -Dv2s2.Dot(Du2s2) + P1P2.Dot(Du2v2s2);
205 Df(4,1) = -Df(1,4); // Du1s1.Dot(Dv2s2);
206 Df(4,2) = -Df(2,4); // Dv1s1.Dot(Dv2s2);
207 Df(4,3) = Df(3,4); // -Du2s2.Dot(Dv2s2) + P1P2.Dot(Du2v2s2);
208 Df(4,4) = -Dv2s2.SquareMagnitude() + P1P2.Dot(Dv2v2s2);
210 return Standard_True;
213 //=======================================================================
214 //function : GetStateNumber
216 //=======================================================================
218 Standard_Integer Extrema_FuncExtSS::GetStateNumber ()
220 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
222 math_Vector Sol(1, 4), UVSol(1, 4);
223 UVSol(1) = myU1; UVSol(2) = myV1; UVSol(3) = myU2; UVSol(4) = myV2;
225 cout <<"F(1)= "<<Sol(1)<<" F(2)= "<<Sol(2)<<" F(3)= "<<Sol(3)<<" F(4)= "<<Sol(4)<<endl;
228 mySqDist.Append(myP1.SquareDistance(myP2));
229 myPoint1.Append(Extrema_POnSurf(myU1,myV1,myP1));
230 myPoint2.Append(Extrema_POnSurf(myU2,myV2,myP2));
234 //=======================================================================
237 //=======================================================================
239 Standard_Integer Extrema_FuncExtSS::NbExt () const
241 return mySqDist.Length();
244 //=======================================================================
245 //function : SquareDistance
247 //=======================================================================
249 Standard_Real Extrema_FuncExtSS::SquareDistance (const Standard_Integer N) const
251 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
252 return mySqDist.Value(N);
255 //=======================================================================
256 //function : PointOnS1
258 //=======================================================================
260 Extrema_POnSurf Extrema_FuncExtSS::PointOnS1 (const Standard_Integer N) const
262 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
263 return myPoint1.Value(N);
265 //=======================================================================
266 //function : PointOnS2
268 //=======================================================================
270 Extrema_POnSurf Extrema_FuncExtSS::PointOnS2 (const Standard_Integer N) const
272 if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
273 return myPoint2.Value(N);