7fd59977 |
1 | // File: Extrema_FuncExtCS.cxx |
2 | // Created: Tue Jan 9 10:13:04 1996 |
3 | // Author: Laurent PAINNOT |
4 | // <lpa@nonox> |
5 | |
6 | |
7 | #include <Extrema_FuncExtCS.ixx> |
8 | #include <gp_Vec.hxx> |
9 | #include <Standard_TypeMismatch.hxx> |
10 | |
11 | /*----------------------------------------------------------------------------- |
12 | Fonction permettant de rechercher une distance extremale entre une courbe C |
13 | et une surface S. |
14 | Cette classe herite de math_FunctionWithDerivative et est utilisee par |
15 | les algorithmes math_FunctionRoot et math_FunctionRoots. |
16 | |
17 | { F1(t,u,v) = (C(t)-S(u,v)).Dtc(t) } |
18 | { F2(t,u,v) = (C(t)-S(u,v)).Dus(u,v) } |
19 | { F3(t,u,v) = (C(t)-S(u,v)).Dvs(u,v) } |
20 | |
21 | { Dtf1(t,u,v) = Dtc(t).Dtc(t)+(C(t)-S(u,v)).Dttc(t) |
22 | = ||Dtc(t)||**2+(C(t)-S(u,v)).Dttc(t) } |
23 | { Duf1(t,u,v) = -Dus(u,v).Dtc(t) } |
24 | { Dvf1(t,u,v) = -Dvs(u,v).Dtc(t) } |
25 | |
26 | { Dtf2(t,u,v) = Dtc(t).Dus(u,v) } |
27 | { Duf2(t,u,v) = -Dus(u,v).Dus(u,v)+(C(t)-S(u,v)).Duus(u,v) |
28 | = -||Dus(u,v)||**2+(C(t)-S(u,v)).Duus(u,v) } |
29 | { Dvf2(t,u,v) = -Dvs(u,v).Dus(u,v)+(C(t)-S(u,v)).Duvs(u,v) } |
30 | |
31 | { Dtf3(t,u,v) = Dtc(t).Dvs(u,v) } |
32 | { Duf3(t,u,v) = -Dus(u,v).Dvs(u,v)+(C(t)-S(u,v)).Duvs(u,v) } |
33 | { Dvf3(t,u,v) = -Dvs(u,v).Dvs(u,v)+(C(t)-S(u,v)).Dvvs(u,v) } |
34 | |
35 | ----------------------------------------------------------------------------*/ |
36 | |
37 | |
38 | |
39 | //======================================================================= |
40 | //function : Extrema_FuncExtCS |
41 | //purpose : |
42 | //======================================================================= |
43 | |
44 | Extrema_FuncExtCS::Extrema_FuncExtCS() |
45 | { |
46 | myCinit = Standard_False; |
47 | mySinit = Standard_False; |
48 | } |
49 | |
50 | //======================================================================= |
51 | //function : Extrema_FuncExtCS |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | Extrema_FuncExtCS::Extrema_FuncExtCS(const Adaptor3d_Curve& C, |
56 | const Adaptor3d_Surface& S) |
57 | { |
58 | Initialize(C, S); |
59 | } |
60 | |
61 | //======================================================================= |
62 | //function : Initialize |
63 | //purpose : |
64 | //======================================================================= |
65 | |
66 | void Extrema_FuncExtCS::Initialize(const Adaptor3d_Curve& C, |
67 | const Adaptor3d_Surface& S) |
68 | { |
69 | myC = (Adaptor3d_CurvePtr)&C; |
70 | myS = (Adaptor3d_SurfacePtr)&S; |
71 | myCinit = Standard_True; |
72 | mySinit = Standard_True; |
73 | myPoint1.Clear(); |
74 | myPoint2.Clear(); |
75 | mySqDist.Clear(); |
76 | } |
77 | |
78 | //======================================================================= |
79 | //function : NbVariables |
80 | //purpose : |
81 | //======================================================================= |
82 | |
83 | Standard_Integer Extrema_FuncExtCS::NbVariables() const |
84 | { |
85 | return (3); |
86 | } |
87 | |
88 | //======================================================================= |
89 | //function : NbEquations |
90 | //purpose : |
91 | //======================================================================= |
92 | |
93 | Standard_Integer Extrema_FuncExtCS::NbEquations() const |
94 | { |
95 | return (3); |
96 | } |
97 | |
98 | //======================================================================= |
99 | //function : Value |
100 | //purpose : |
101 | //======================================================================= |
102 | |
103 | Standard_Boolean Extrema_FuncExtCS::Value(const math_Vector& UV, |
104 | math_Vector& F) |
105 | { |
106 | if (!myCinit || !mySinit) Standard_TypeMismatch::Raise(); |
107 | |
108 | myt = UV(1); |
109 | myU = UV(2); |
110 | myV = UV(3); |
111 | |
112 | // gp_Vec Dtc, Dttc; |
113 | gp_Vec Dtc; |
114 | /// gp_Vec Dus, Dvs, Duvs, Duus, Dvvs; |
115 | gp_Vec Dus, Dvs; |
116 | myC->D1(myt, myP1, Dtc); |
117 | myS->D1(myU,myV,myP2,Dus,Dvs); |
118 | |
119 | gp_Vec P1P2 (myP2,myP1); |
120 | |
121 | F(1) = P1P2.Dot(Dtc); |
122 | F(2) = P1P2.Dot(Dus); |
123 | F(3) = P1P2.Dot(Dvs); |
124 | |
125 | return Standard_True; |
126 | } |
127 | |
128 | //======================================================================= |
129 | //function : Derivatives |
130 | //purpose : |
131 | //======================================================================= |
132 | |
133 | Standard_Boolean Extrema_FuncExtCS::Derivatives(const math_Vector& UV, |
134 | math_Matrix& DF) |
135 | { |
136 | math_Vector F(1,3); |
137 | return Values(UV,F,DF); |
138 | } |
139 | |
140 | //======================================================================= |
141 | //function : Values |
142 | //purpose : |
143 | //======================================================================= |
144 | |
145 | Standard_Boolean Extrema_FuncExtCS::Values(const math_Vector& UV, |
146 | math_Vector& F, |
147 | math_Matrix& Df) |
148 | { |
149 | if (!myCinit || !mySinit) Standard_TypeMismatch::Raise(); |
150 | |
151 | myt = UV(1); |
152 | myU = UV(2); |
153 | myV = UV(3); |
154 | |
155 | gp_Vec Dtc, Dttc; |
156 | gp_Vec Dus, Dvs, Duvs, Duus, Dvvs; |
157 | myC->D2(myt, myP1, Dtc, Dttc); |
158 | myS->D2(myU,myV,myP2,Dus,Dvs,Duus,Dvvs,Duvs); |
159 | |
160 | gp_Vec P1P2 (myP2,myP1); |
161 | |
162 | F(1) = P1P2.Dot(Dtc); |
163 | F(2) = P1P2.Dot(Dus); |
164 | F(3) = P1P2.Dot(Dvs); |
165 | |
166 | Df(1,1) = Dtc.SquareMagnitude() + P1P2.Dot(Dttc); |
167 | Df(1,2) = -Dus.Dot(Dtc); |
168 | Df(1,3) = -Dvs.Dot(Dtc); |
169 | |
170 | Df(2,1) = -Df(1, 2); // Dtc.Dot(Dus); |
171 | Df(2,2) = -Dus.SquareMagnitude()+P1P2.Dot(Duus); |
172 | Df(2,3) = -Dvs.Dot(Dus)+P1P2.Dot(Duvs); |
173 | |
174 | Df(3,1) = -Df(1,3); // Dtc.Dot(Dvs); |
175 | Df(3,2) = Df(2,3); // -Dus.Dot(Dvs)+P1P2.Dot(Duvs); |
176 | Df(3,3) = -Dvs.SquareMagnitude()+P1P2.Dot(Dvvs); |
177 | |
178 | return Standard_True; |
179 | |
180 | } |
181 | |
182 | //======================================================================= |
183 | //function : GetStateNumber |
184 | //purpose : |
185 | //======================================================================= |
186 | |
187 | Standard_Integer Extrema_FuncExtCS::GetStateNumber() |
188 | { |
189 | if (!myCinit || !mySinit) Standard_TypeMismatch::Raise(); |
190 | #if 0 |
191 | math_Vector Sol(1, 3), UVSol(1, 3); |
192 | UVSol(1) = myt; UVSol(2) = myU; UVSol(3) = myV; |
193 | Value(UVSol, Sol); |
194 | cout <<"F(1)= "<<Sol(1)<<" F(2)= "<<Sol(2)<<" F(3)= "<<Sol(3)<<endl; |
195 | #endif |
196 | |
197 | mySqDist.Append(myP1.SquareDistance(myP2)); |
198 | myPoint1.Append(Extrema_POnCurv(myt,myP1)); |
199 | myPoint2.Append(Extrema_POnSurf(myU,myV,myP2)); |
200 | return 0; |
201 | } |
202 | |
203 | //======================================================================= |
204 | //function : NbExt |
205 | //purpose : |
206 | //======================================================================= |
207 | |
208 | Standard_Integer Extrema_FuncExtCS::NbExt() const |
209 | { |
210 | return mySqDist.Length(); |
211 | } |
212 | |
213 | //======================================================================= |
214 | //function : SquareDistance |
215 | //purpose : |
216 | //======================================================================= |
217 | |
218 | Standard_Real Extrema_FuncExtCS::SquareDistance(const Standard_Integer N) const |
219 | { |
220 | if (!myCinit || !mySinit) Standard_TypeMismatch::Raise(); |
221 | return mySqDist.Value(N); |
222 | } |
223 | |
224 | //======================================================================= |
225 | //function : PointOnCurve |
226 | //purpose : |
227 | //======================================================================= |
228 | |
229 | const Extrema_POnCurv& Extrema_FuncExtCS::PointOnCurve(const Standard_Integer N) const |
230 | { |
231 | if (!myCinit || !mySinit) Standard_TypeMismatch::Raise(); |
232 | return myPoint1.Value(N); |
233 | } |
234 | |
235 | //======================================================================= |
236 | //function : PointOnSurface |
237 | //purpose : |
238 | //======================================================================= |
239 | |
240 | const Extrema_POnSurf& Extrema_FuncExtCS::PointOnSurface(const Standard_Integer N) const |
241 | { |
242 | if (!myCinit || !mySinit) Standard_TypeMismatch::Raise(); |
243 | return myPoint2.Value(N); |
244 | } |
245 | |
246 | //======================================================================= |
247 | //function : Bidon1 |
248 | //purpose : |
249 | //======================================================================= |
250 | |
251 | Adaptor3d_SurfacePtr Extrema_FuncExtCS::Bidon1() const |
252 | { |
253 | return (Adaptor3d_SurfacePtr)0L; |
254 | } |
255 | |
256 | //======================================================================= |
257 | //function : Bidon2 |
258 | //purpose : |
259 | //======================================================================= |
260 | |
261 | Adaptor3d_CurvePtr Extrema_FuncExtCS::Bidon2() const |
262 | { |
263 | return (Adaptor3d_CurvePtr)0L; |
264 | } |
265 | |