b311480e |
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 |
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 | |
7fd59977 |
21 | |
22 | |
23 | #include <Extrema_FuncExtSS.ixx> |
24 | #include <Standard_TypeMismatch.hxx> |
25 | #include <gp_Vec.hxx> |
26 | |
27 | |
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: |
31 | |
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) } |
36 | |
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) = -Du2s2(u2,v2).Du1s1(u1,v1) } |
41 | { dv2f1(u1,v1,u2,v2) = -Dv2s2(u2,v2).Du1s1(u1,v1) } |
42 | |
43 | { du1f2(u1,v1,u2,v2) = Du1s1(u1,v1).Dv1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1v1s1(u1,v1) } |
44 | { dv1f2(u1,v1,u2,v2) = Dv1s1(u1,v1).Dv1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Dv1v1s1(u1,v1) |
45 | = ||Dv1s1(u1,v1)||**2 +(S1(u1,v1)-S2(u2,v2)).Dv1v1s1(u1,v1) } |
46 | { du2f2(u1,v1,u2,v2) = -Du2s2(u2,v2).Dv1s1(u1,v1) } |
47 | { dv2f2(u1,v1,u2,v2) = -Dv2s2(u2,v2).Dv1s1(u1,v1) } |
48 | |
49 | { du1f3(u1,v1,u2,v2) = Du1s1(u1,v1).Du2s2(u2,v2) } |
50 | { dv1f3(u1,v1,u2,v2) = Dv1s1(u1,v1).Du2s2(u2,v2) } |
51 | { du2f3(u1,v1,u2,v2) = -Du2s2(u2,v2).Du2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Du2u2s2(u2,v2) |
52 | = -||Du2s2(u2,v2)||**2 +(S1(u1,v1)-S2(u2,v2)).Du2u2s2(u2,v2) } |
53 | { dv2f3(u1,v1,u2,v2) = -Dv2s2(u2,v2).Du2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Dv2u2s2(u2,v2) } |
54 | |
55 | { du1f4(u1,v1,u2,v2) = Du1s1(u1,v1).Dv2s2(u2,v2) } |
56 | { dv1f4(u1,v1,u2,v2) = Dv1s1(u1,v1).Dv2s2(u2,v2) } |
57 | { du2f4(u1,v1,u2,v2) = -Du2s2(u2,v2).Dv2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Du2v2s2(u2,v2) } |
58 | { dv2f4(u1,v1,u2,v2) = -Dv2s2(u2,v2).Dv2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Dv2v2s2(u2,v2) |
59 | = -||Dv2s2(u2,v2)||**2 +(S1(u1,v1)-S2(u2,v2)).Dv2v2s2(u2,v2) } |
60 | |
61 | ----------------------------------------------------------------------------*/ |
62 | |
63 | |
64 | //======================================================================= |
65 | //function : Extrema_FuncExtSS |
66 | //purpose : |
67 | //======================================================================= |
68 | |
69 | Extrema_FuncExtSS::Extrema_FuncExtSS () |
70 | { |
71 | myS1init = Standard_False; |
72 | myS2init = Standard_False; |
73 | } |
74 | |
75 | //======================================================================= |
76 | //function : Extrema_FuncExtSS |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | Extrema_FuncExtSS::Extrema_FuncExtSS (const Adaptor3d_Surface& S1, |
81 | const Adaptor3d_Surface& S2) |
82 | { |
83 | myS1 = (Adaptor3d_SurfacePtr)&S1; |
84 | myS2 = (Adaptor3d_SurfacePtr)&S2; |
85 | myS1init = Standard_True; |
86 | myS2init = Standard_True; |
87 | } |
88 | |
89 | //======================================================================= |
90 | //function : Initialize |
91 | //purpose : |
92 | //======================================================================= |
93 | |
94 | void Extrema_FuncExtSS::Initialize(const Adaptor3d_Surface& S1, |
95 | const Adaptor3d_Surface& S2) |
96 | { |
97 | myS1 = (Adaptor3d_SurfacePtr)&S1; |
98 | myS2 = (Adaptor3d_SurfacePtr)&S2; |
99 | myS1init = Standard_True; |
100 | myS2init = Standard_True; |
101 | myPoint1.Clear(); |
102 | myPoint2.Clear(); |
103 | mySqDist.Clear(); |
104 | } |
105 | |
106 | |
107 | |
108 | //======================================================================= |
109 | //function : NbVariables |
110 | //purpose : |
111 | //======================================================================= |
112 | |
113 | Standard_Integer Extrema_FuncExtSS::NbVariables () const { return 4;} |
114 | |
115 | |
116 | //======================================================================= |
117 | //function : NbEquations |
118 | //purpose : |
119 | //======================================================================= |
120 | |
121 | Standard_Integer Extrema_FuncExtSS::NbEquations () const { return 4;} |
122 | |
123 | |
124 | //======================================================================= |
125 | //function : Value |
126 | //purpose : |
127 | //======================================================================= |
128 | |
129 | Standard_Boolean Extrema_FuncExtSS::Value (const math_Vector& UV, |
130 | math_Vector& F) |
131 | { |
132 | if (!myS1init || !myS2init) Standard_TypeMismatch::Raise(); |
133 | myU1 = UV(1); |
134 | myV1 = UV(2); |
135 | myU2 = UV(3); |
136 | myV2 = UV(4); |
137 | gp_Vec Du1s1, Dv1s1; |
138 | gp_Vec Du2s2, Dv2s2; |
139 | myS1->D1(myU1,myV1,myP1,Du1s1,Dv1s1); |
140 | myS2->D1(myU2,myV2,myP2,Du2s2,Dv2s2); |
141 | |
142 | gp_Vec P1P2 (myP2,myP1); |
143 | |
144 | F(1) = P1P2.Dot(Du1s1); |
145 | F(2) = P1P2.Dot(Dv1s1); |
146 | F(3) = P1P2.Dot(Du2s2); |
147 | F(4) = P1P2.Dot(Dv2s2); |
148 | |
149 | return Standard_True; |
150 | } |
151 | |
152 | //======================================================================= |
153 | //function : Derivatives |
154 | //purpose : |
155 | //======================================================================= |
156 | |
157 | Standard_Boolean Extrema_FuncExtSS::Derivatives (const math_Vector& UV, |
158 | math_Matrix& Df) |
159 | { |
160 | math_Vector F(1,4); |
161 | return Values(UV,F,Df); |
162 | } |
163 | |
164 | //======================================================================= |
165 | //function : Values |
166 | //purpose : |
167 | //======================================================================= |
168 | |
169 | Standard_Boolean Extrema_FuncExtSS::Values (const math_Vector& UV, |
170 | math_Vector& F, |
171 | math_Matrix& Df) |
172 | { |
173 | if (!myS1init || !myS2init) Standard_TypeMismatch::Raise(); |
174 | myU1 = UV(1); |
175 | myV1 = UV(2); |
176 | myU2 = UV(3); |
177 | myV2 = UV(4); |
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); |
182 | |
183 | gp_Vec P1P2 (myP2,myP1); |
184 | |
185 | F(1) = P1P2.Dot(Du1s1); |
186 | F(2) = P1P2.Dot(Dv1s1); |
187 | F(3) = P1P2.Dot(Du2s2); |
188 | F(4) = P1P2.Dot(Dv2s2); |
189 | |
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); |
194 | |
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); |
199 | |
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); |
204 | |
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); |
209 | |
210 | return Standard_True; |
211 | } |
212 | |
213 | //======================================================================= |
214 | //function : GetStateNumber |
215 | //purpose : |
216 | //======================================================================= |
217 | |
218 | Standard_Integer Extrema_FuncExtSS::GetStateNumber () |
219 | { |
220 | if (!myS1init || !myS2init) Standard_TypeMismatch::Raise(); |
221 | #if 0 |
222 | math_Vector Sol(1, 4), UVSol(1, 4); |
223 | UVSol(1) = myU1; UVSol(2) = myV1; UVSol(3) = myU2; UVSol(4) = myV2; |
224 | Value(UVSol, Sol); |
225 | cout <<"F(1)= "<<Sol(1)<<" F(2)= "<<Sol(2)<<" F(3)= "<<Sol(3)<<" F(4)= "<<Sol(4)<<endl; |
226 | #endif |
227 | |
228 | mySqDist.Append(myP1.SquareDistance(myP2)); |
229 | myPoint1.Append(Extrema_POnSurf(myU1,myV1,myP1)); |
230 | myPoint2.Append(Extrema_POnSurf(myU2,myV2,myP2)); |
231 | return 0; |
232 | } |
233 | |
234 | //======================================================================= |
235 | //function : NbExt |
236 | //purpose : |
237 | //======================================================================= |
238 | |
239 | Standard_Integer Extrema_FuncExtSS::NbExt () const |
240 | { |
241 | return mySqDist.Length(); |
242 | } |
243 | |
244 | //======================================================================= |
245 | //function : SquareDistance |
246 | //purpose : |
247 | //======================================================================= |
248 | |
249 | Standard_Real Extrema_FuncExtSS::SquareDistance (const Standard_Integer N) const |
250 | { |
251 | if (!myS1init || !myS2init) Standard_TypeMismatch::Raise(); |
252 | return mySqDist.Value(N); |
253 | } |
254 | |
255 | //======================================================================= |
256 | //function : PointOnS1 |
257 | //purpose : |
258 | //======================================================================= |
259 | |
5d99f2c8 |
260 | const Extrema_POnSurf& Extrema_FuncExtSS::PointOnS1 (const Standard_Integer N) const |
7fd59977 |
261 | { |
262 | if (!myS1init || !myS2init) Standard_TypeMismatch::Raise(); |
263 | return myPoint1.Value(N); |
264 | } |
265 | //======================================================================= |
266 | //function : PointOnS2 |
267 | //purpose : |
268 | //======================================================================= |
269 | |
5d99f2c8 |
270 | const Extrema_POnSurf& Extrema_FuncExtSS::PointOnS2 (const Standard_Integer N) const |
7fd59977 |
271 | { |
272 | if (!myS1init || !myS2init) Standard_TypeMismatch::Raise(); |
273 | return myPoint2.Value(N); |
274 | } |
275 | |
276 | |