b311480e |
1 | // Created on: 1996-01-09 |
2 | // Created by: Laurent PAINNOT |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <Adaptor3d_Surface.hxx> |
19 | #include <Extrema_FuncExtSS.hxx> |
20 | #include <Extrema_POnSurf.hxx> |
21 | #include <gp_Vec.hxx> |
22 | #include <math_Matrix.hxx> |
23 | #include <Standard_OutOfRange.hxx> |
24 | #include <Standard_TypeMismatch.hxx> |
7fd59977 |
25 | |
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: |
7fd59977 |
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) } |
7fd59977 |
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(u1,v1) } |
37 | { dv2f1(u1,v1,u2,v2) = -Dv2s2(u2,v2).Du1s1(u1,v1) } |
7fd59977 |
38 | { du1f2(u1,v1,u2,v2) = Du1s1(u1,v1).Dv1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1v1s1(u1,v1) } |
39 | { dv1f2(u1,v1,u2,v2) = Dv1s1(u1,v1).Dv1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Dv1v1s1(u1,v1) |
40 | = ||Dv1s1(u1,v1)||**2 +(S1(u1,v1)-S2(u2,v2)).Dv1v1s1(u1,v1) } |
41 | { du2f2(u1,v1,u2,v2) = -Du2s2(u2,v2).Dv1s1(u1,v1) } |
42 | { dv2f2(u1,v1,u2,v2) = -Dv2s2(u2,v2).Dv1s1(u1,v1) } |
7fd59977 |
43 | { du1f3(u1,v1,u2,v2) = Du1s1(u1,v1).Du2s2(u2,v2) } |
44 | { dv1f3(u1,v1,u2,v2) = Dv1s1(u1,v1).Du2s2(u2,v2) } |
45 | { du2f3(u1,v1,u2,v2) = -Du2s2(u2,v2).Du2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Du2u2s2(u2,v2) |
46 | = -||Du2s2(u2,v2)||**2 +(S1(u1,v1)-S2(u2,v2)).Du2u2s2(u2,v2) } |
47 | { dv2f3(u1,v1,u2,v2) = -Dv2s2(u2,v2).Du2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Dv2u2s2(u2,v2) } |
7fd59977 |
48 | { du1f4(u1,v1,u2,v2) = Du1s1(u1,v1).Dv2s2(u2,v2) } |
49 | { dv1f4(u1,v1,u2,v2) = Dv1s1(u1,v1).Dv2s2(u2,v2) } |
50 | { du2f4(u1,v1,u2,v2) = -Du2s2(u2,v2).Dv2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Du2v2s2(u2,v2) } |
51 | { dv2f4(u1,v1,u2,v2) = -Dv2s2(u2,v2).Dv2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Dv2v2s2(u2,v2) |
52 | = -||Dv2s2(u2,v2)||**2 +(S1(u1,v1)-S2(u2,v2)).Dv2v2s2(u2,v2) } |
7fd59977 |
53 | ----------------------------------------------------------------------------*/ |
7fd59977 |
54 | //======================================================================= |
55 | //function : Extrema_FuncExtSS |
56 | //purpose : |
57 | //======================================================================= |
7fd59977 |
58 | Extrema_FuncExtSS::Extrema_FuncExtSS () |
d533dafb |
59 | : myS1(NULL), |
60 | myS2(NULL), |
61 | myU1(0.0), |
62 | myV1(0.0), |
63 | myU2(0.0), |
64 | myV2(0.0) |
7fd59977 |
65 | { |
66 | myS1init = Standard_False; |
67 | myS2init = Standard_False; |
68 | } |
69 | |
70 | //======================================================================= |
71 | //function : Extrema_FuncExtSS |
72 | //purpose : |
73 | //======================================================================= |
74 | |
75 | Extrema_FuncExtSS::Extrema_FuncExtSS (const Adaptor3d_Surface& S1, |
76 | const Adaptor3d_Surface& S2) |
d533dafb |
77 | : myU1(0.0), |
78 | myV1(0.0), |
79 | myU2(0.0), |
80 | myV2(0.0) |
7fd59977 |
81 | { |
82 | myS1 = (Adaptor3d_SurfacePtr)&S1; |
83 | myS2 = (Adaptor3d_SurfacePtr)&S2; |
84 | myS1init = Standard_True; |
85 | myS2init = Standard_True; |
86 | } |
87 | |
88 | //======================================================================= |
89 | //function : Initialize |
90 | //purpose : |
91 | //======================================================================= |
92 | |
93 | void Extrema_FuncExtSS::Initialize(const Adaptor3d_Surface& S1, |
94 | const Adaptor3d_Surface& S2) |
95 | { |
96 | myS1 = (Adaptor3d_SurfacePtr)&S1; |
97 | myS2 = (Adaptor3d_SurfacePtr)&S2; |
98 | myS1init = Standard_True; |
99 | myS2init = Standard_True; |
100 | myPoint1.Clear(); |
101 | myPoint2.Clear(); |
102 | mySqDist.Clear(); |
103 | } |
104 | |
105 | |
106 | |
107 | //======================================================================= |
108 | //function : NbVariables |
109 | //purpose : |
110 | //======================================================================= |
111 | |
112 | Standard_Integer Extrema_FuncExtSS::NbVariables () const { return 4;} |
113 | |
114 | |
115 | //======================================================================= |
116 | //function : NbEquations |
117 | //purpose : |
118 | //======================================================================= |
119 | |
120 | Standard_Integer Extrema_FuncExtSS::NbEquations () const { return 4;} |
121 | |
122 | |
123 | //======================================================================= |
124 | //function : Value |
125 | //purpose : |
126 | //======================================================================= |
127 | |
128 | Standard_Boolean Extrema_FuncExtSS::Value (const math_Vector& UV, |
129 | math_Vector& F) |
130 | { |
9775fa61 |
131 | if (!myS1init || !myS2init) throw Standard_TypeMismatch(); |
7fd59977 |
132 | myU1 = UV(1); |
133 | myV1 = UV(2); |
134 | myU2 = UV(3); |
135 | myV2 = UV(4); |
136 | gp_Vec Du1s1, Dv1s1; |
137 | gp_Vec Du2s2, Dv2s2; |
138 | myS1->D1(myU1,myV1,myP1,Du1s1,Dv1s1); |
139 | myS2->D1(myU2,myV2,myP2,Du2s2,Dv2s2); |
140 | |
141 | gp_Vec P1P2 (myP2,myP1); |
142 | |
143 | F(1) = P1P2.Dot(Du1s1); |
144 | F(2) = P1P2.Dot(Dv1s1); |
145 | F(3) = P1P2.Dot(Du2s2); |
146 | F(4) = P1P2.Dot(Dv2s2); |
147 | |
148 | return Standard_True; |
149 | } |
150 | |
151 | //======================================================================= |
152 | //function : Derivatives |
153 | //purpose : |
154 | //======================================================================= |
155 | |
156 | Standard_Boolean Extrema_FuncExtSS::Derivatives (const math_Vector& UV, |
157 | math_Matrix& Df) |
158 | { |
159 | math_Vector F(1,4); |
160 | return Values(UV,F,Df); |
161 | } |
162 | |
163 | //======================================================================= |
164 | //function : Values |
165 | //purpose : |
166 | //======================================================================= |
167 | |
168 | Standard_Boolean Extrema_FuncExtSS::Values (const math_Vector& UV, |
169 | math_Vector& F, |
170 | math_Matrix& Df) |
171 | { |
9775fa61 |
172 | if (!myS1init || !myS2init) throw Standard_TypeMismatch(); |
7fd59977 |
173 | myU1 = UV(1); |
174 | myV1 = UV(2); |
175 | myU2 = UV(3); |
176 | myV2 = UV(4); |
177 | gp_Vec Du1s1, Dv1s1, Du1u1s1, Dv1v1s1, Du1v1s1; |
178 | gp_Vec Du2s2, Dv2s2, Du2u2s2, Dv2v2s2, Du2v2s2; |
179 | myS1->D2(myU1,myV1,myP1,Du1s1,Dv1s1,Du1u1s1,Dv1v1s1,Du1v1s1); |
180 | myS2->D2(myU2,myV2,myP2,Du2s2,Dv2s2,Du2u2s2,Dv2v2s2,Du2v2s2); |
181 | |
182 | gp_Vec P1P2 (myP2,myP1); |
183 | |
184 | F(1) = P1P2.Dot(Du1s1); |
185 | F(2) = P1P2.Dot(Dv1s1); |
186 | F(3) = P1P2.Dot(Du2s2); |
187 | F(4) = P1P2.Dot(Dv2s2); |
188 | |
189 | Df(1,1) = Du1s1.SquareMagnitude() + P1P2.Dot(Du1u1s1); |
190 | Df(1,2) = Dv1s1.Dot(Du1s1) + P1P2.Dot(Du1v1s1); |
191 | Df(1,3) = -Du2s2.Dot(Du1s1); |
192 | Df(1,4) = -Dv2s2.Dot(Du1s1); |
193 | |
194 | Df(2,1) = Df(1, 2); // Du1s1.Dot(Dv1s1) + P1P2.Dot(Du1v1s1); |
195 | Df(2,2) = Dv1s1.SquareMagnitude() + P1P2.Dot(Dv1v1s1); |
196 | Df(2,3) = -Du2s2.Dot(Dv1s1); |
197 | Df(2,4) = -Dv2s2.Dot(Dv1s1); |
198 | |
199 | Df(3,1) = -Df(1,3); // Du1s1.Dot(Du2s2); |
200 | Df(3,2) = -Df(2,3); // Dv1s1.Dot(Du2s2); |
201 | Df(3,3) = -Du2s2.SquareMagnitude() + P1P2.Dot(Du2u2s2); |
202 | Df(3,4) = -Dv2s2.Dot(Du2s2) + P1P2.Dot(Du2v2s2); |
203 | |
204 | Df(4,1) = -Df(1,4); // Du1s1.Dot(Dv2s2); |
205 | Df(4,2) = -Df(2,4); // Dv1s1.Dot(Dv2s2); |
206 | Df(4,3) = Df(3,4); // -Du2s2.Dot(Dv2s2) + P1P2.Dot(Du2v2s2); |
207 | Df(4,4) = -Dv2s2.SquareMagnitude() + P1P2.Dot(Dv2v2s2); |
208 | |
209 | return Standard_True; |
210 | } |
211 | |
212 | //======================================================================= |
213 | //function : GetStateNumber |
214 | //purpose : |
215 | //======================================================================= |
216 | |
217 | Standard_Integer Extrema_FuncExtSS::GetStateNumber () |
218 | { |
9775fa61 |
219 | if (!myS1init || !myS2init) throw Standard_TypeMismatch(); |
7fd59977 |
220 | #if 0 |
221 | math_Vector Sol(1, 4), UVSol(1, 4); |
222 | UVSol(1) = myU1; UVSol(2) = myV1; UVSol(3) = myU2; UVSol(4) = myV2; |
223 | Value(UVSol, Sol); |
04232180 |
224 | std::cout <<"F(1)= "<<Sol(1)<<" F(2)= "<<Sol(2)<<" F(3)= "<<Sol(3)<<" F(4)= "<<Sol(4)<<std::endl; |
7fd59977 |
225 | #endif |
226 | |
227 | mySqDist.Append(myP1.SquareDistance(myP2)); |
228 | myPoint1.Append(Extrema_POnSurf(myU1,myV1,myP1)); |
229 | myPoint2.Append(Extrema_POnSurf(myU2,myV2,myP2)); |
230 | return 0; |
231 | } |
232 | |
233 | //======================================================================= |
234 | //function : NbExt |
235 | //purpose : |
236 | //======================================================================= |
237 | |
238 | Standard_Integer Extrema_FuncExtSS::NbExt () const |
239 | { |
240 | return mySqDist.Length(); |
241 | } |
242 | |
243 | //======================================================================= |
244 | //function : SquareDistance |
245 | //purpose : |
246 | //======================================================================= |
247 | |
248 | Standard_Real Extrema_FuncExtSS::SquareDistance (const Standard_Integer N) const |
249 | { |
9775fa61 |
250 | if (!myS1init || !myS2init) throw Standard_TypeMismatch(); |
7fd59977 |
251 | return mySqDist.Value(N); |
252 | } |
253 | |
254 | //======================================================================= |
255 | //function : PointOnS1 |
256 | //purpose : |
257 | //======================================================================= |
258 | |
5d99f2c8 |
259 | const Extrema_POnSurf& Extrema_FuncExtSS::PointOnS1 (const Standard_Integer N) const |
7fd59977 |
260 | { |
9775fa61 |
261 | if (!myS1init || !myS2init) throw Standard_TypeMismatch(); |
7fd59977 |
262 | return myPoint1.Value(N); |
263 | } |
264 | //======================================================================= |
265 | //function : PointOnS2 |
266 | //purpose : |
267 | //======================================================================= |
268 | |
5d99f2c8 |
269 | const Extrema_POnSurf& Extrema_FuncExtSS::PointOnS2 (const Standard_Integer N) const |
7fd59977 |
270 | { |
9775fa61 |
271 | if (!myS1init || !myS2init) throw Standard_TypeMismatch(); |
7fd59977 |
272 | return myPoint2.Value(N); |
273 | } |
274 | |
275 | |