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