1 // Created on: 1998-06-04
2 // Created by: Philippe NOUAILLE
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor2d_HCurve2d.hxx>
19 #include <Adaptor3d_HCurve.hxx>
20 #include <Adaptor3d_HSurface.hxx>
21 #include <BlendFunc.hxx>
22 #include <BlendFunc_ChAsymInv.hxx>
23 #include <math_Matrix.hxx>
24 #include <Precision.hxx>
26 //=======================================================================
27 //function : BlendFunc_ChAsymInv
29 //=======================================================================
30 BlendFunc_ChAsymInv::BlendFunc_ChAsymInv(const Handle(Adaptor3d_HSurface)& S1,
31 const Handle(Adaptor3d_HSurface)& S2,
32 const Handle(Adaptor3d_HCurve)& C) :
33 surf1(S1),surf2(S2),curv(C),
40 //=======================================================================
43 //=======================================================================
45 void BlendFunc_ChAsymInv::Set(const Standard_Real Dist1,
46 const Standard_Real Angle,
47 const Standard_Integer Choix)
55 //=======================================================================
56 //function : NbEquations
58 //=======================================================================
60 Standard_Integer BlendFunc_ChAsymInv::NbEquations () const
65 //=======================================================================
66 //function : GetTolerance
68 //=======================================================================
70 void BlendFunc_ChAsymInv::Set(const Standard_Boolean OnFirst,
71 const Handle(Adaptor2d_HCurve2d)& C)
77 //=======================================================================
78 //function : GetTolerance
80 //=======================================================================
82 void BlendFunc_ChAsymInv::GetTolerance(math_Vector& Tolerance, const Standard_Real Tol) const
84 Tolerance(1) = csurf->Resolution(Tol);
85 Tolerance(2) = curv->Resolution(Tol);
87 Tolerance(3) = surf2->UResolution(Tol);
88 Tolerance(4) = surf2->VResolution(Tol);
91 Tolerance(3) = surf1->UResolution(Tol);
92 Tolerance(4) = surf1->VResolution(Tol);
97 //=======================================================================
98 //function : GetBounds
100 //=======================================================================
102 void BlendFunc_ChAsymInv::GetBounds(math_Vector& InfBound, math_Vector& SupBound) const
104 InfBound(1) = csurf->FirstParameter();
105 InfBound(2) = curv->FirstParameter();
106 SupBound(1) = csurf->LastParameter();
107 SupBound(2) = curv->LastParameter();
110 InfBound(3) = surf2->FirstUParameter();
111 InfBound(4) = surf2->FirstVParameter();
112 SupBound(3) = surf2->LastUParameter();
113 SupBound(4) = surf2->LastVParameter();
114 if(!Precision::IsInfinite(InfBound(3)) &&
115 !Precision::IsInfinite(SupBound(3))) {
116 const Standard_Real range = (SupBound(3) - InfBound(3));
117 InfBound(3) -= range;
118 SupBound(3) += range;
120 if(!Precision::IsInfinite(InfBound(4)) &&
121 !Precision::IsInfinite(SupBound(4))) {
122 const Standard_Real range = (SupBound(4) - InfBound(4));
123 InfBound(4) -= range;
124 SupBound(4) += range;
128 InfBound(3) = surf1->FirstUParameter();
129 InfBound(4) = surf1->FirstVParameter();
130 SupBound(3) = surf1->LastUParameter();
131 SupBound(4) = surf1->LastVParameter();
132 if(!Precision::IsInfinite(InfBound(3)) &&
133 !Precision::IsInfinite(SupBound(3))) {
134 const Standard_Real range = (SupBound(3) - InfBound(3));
135 InfBound(3) -= range;
136 SupBound(3) += range;
138 if(!Precision::IsInfinite(InfBound(4)) &&
139 !Precision::IsInfinite(SupBound(4))) {
140 const Standard_Real range = (SupBound(4) - InfBound(4));
141 InfBound(4) -= range;
142 SupBound(4) += range;
147 //=======================================================================
148 //function : IsSolution
150 //=======================================================================
152 Standard_Boolean BlendFunc_ChAsymInv::IsSolution(const math_Vector& Sol,
153 const Standard_Real Tol)
155 math_Vector valsol(1, 4);
156 gp_Pnt pts1, pts2, ptgui;
157 gp_Vec nplan, d1gui, Nsurf1, tsurf1;
160 curv->D1(Sol(2), ptgui, d1gui);
161 nplan = d1gui.Normalized();
163 gp_Pnt2d pt2d(csurf->Value(Sol(1)));
166 surf1->D1(pt2d.X(), pt2d.Y(), pts1, d1u1, d1v1);
167 pts2 = surf2->Value(Sol(3), Sol(4));
170 surf1->D1(Sol(3), Sol(4), pts1, d1u1, d1v1);
171 pts2 = surf2->Value(pt2d.X(), pt2d.Y());
174 Nsurf1 = d1u1.Crossed(d1v1);
175 tsurf1 = Nsurf1.Crossed(nplan);
177 gp_Vec s1s2(pts1, pts2);
178 Standard_Real PScaInv = 1. / tsurf1.Dot(s1s2), temp;// ,F4;
179 Standard_Real Nordu1 = d1u1.Magnitude(),
180 Nordv1 = d1v1.Magnitude();
182 temp = 2. * (Nordu1 + Nordv1) * s1s2.Magnitude() + 2. * Nordu1 * Nordv1;
186 if (Abs(valsol(1)) < Tol &&
187 Abs(valsol(2)) < Tol &&
188 Abs(valsol(3)) < 2. * dist1 * Tol &&
189 Abs(valsol(4)) < Tol * (1. + tgang) * Abs(PScaInv) * temp) {
191 return Standard_True;
194 return Standard_False;
199 //=======================================================================
200 //function : ComputeValues
202 //=======================================================================
203 Standard_Boolean BlendFunc_ChAsymInv::ComputeValues(const math_Vector& X,
204 const Standard_Integer DegF,
205 const Standard_Integer DegL)
207 if (DegF > DegL) return Standard_False;
209 gp_Vec nplan, dnplan, d1gui, d2gui, d1u1, d1v1, d2u1, d2v1, d2uv1, d1u2, d1v2;
210 gp_Vec Nsurf1, tsurf1;
211 gp_Pnt pts1, pts2, ptgui;
212 Standard_Real PScaInv, F4;
213 Standard_Real Normg = 0.;
217 if ( (DegF == 0) && (DegL == 0) ) {
218 curv->D1(X(2), ptgui, d1gui);
219 nplan = d1gui.Normalized();
221 if (choix%2 != 0) nplan.Reverse();
222 pt2d = csurf->Value(X(1));
225 surf1->D1(pt2d.X(), pt2d.Y(), pts1, d1u1, d1v1);
226 pts2 = surf2->Value(X(3), X(4));
229 surf1->D1(X(3), X(4), pts1, d1u1, d1v1);
230 pts2 = surf2->Value(pt2d.X(), pt2d.Y());
234 curv->D2(X(2), ptgui, d1gui, d2gui);
235 nplan = d1gui.Normalized();
236 Normg = d1gui.Magnitude();
237 dnplan = (d2gui - nplan.Dot(d2gui) * nplan) / Normg;
245 csurf->D1(X(1), pt2d, v2d);
248 surf1->D2(pt2d.X(), pt2d.Y(), pts1, d1u1, d1v1, d2u1, d2v1, d2uv1);
249 surf2->D1(X(3), X(4), pts2, d1u2, d1v2);
252 surf1->D2(X(3), X(4), pts1, d1u1, d1v1, d2u1, d2v1, d2uv1);
253 surf2->D1(pt2d.X(), pt2d.Y(), pts2, d1u2, d1v2);
257 gp_Vec nps1(ptgui, pts1), s1s2(pts1, pts2);
258 Nsurf1 = d1u1.Crossed(d1v1);
259 tsurf1 = Nsurf1.Crossed(nplan);
260 PScaInv = 1. / s1s2.Dot(tsurf1);
261 F4 = nplan.Dot(tsurf1.Crossed(s1s2)) * PScaInv;
265 Dist = ptgui.XYZ().Dot(nplan.XYZ());
266 FX(1) = pts1.XYZ().Dot(nplan.XYZ()) - Dist;
267 FX(2) = pts2.XYZ().Dot(nplan.XYZ()) - Dist;
268 FX(3) = dist1 * dist1 - nps1.SquareMagnitude();
274 gp_Vec dwtsurf1, tempVec;
276 gp_Vec nps2(ptgui, pts2);
279 gp_Vec dw1du1, dw1dv1, dw1csurf, dw1pts1;
280 dw1pts1 = v2d.X() * d1u1 + v2d.Y() * d1v1;
281 dw1du1 = v2d.X() * d2u1 + v2d.Y() * d2uv1;
282 dw1dv1 = v2d.X() * d2uv1 + v2d.Y() * d2v1;
283 dw1csurf = (dw1du1.Crossed(d1v1) + d1u1.Crossed(dw1dv1)).Crossed(nplan);
284 dwtsurf1 = Nsurf1.Crossed(dnplan);
286 DX(1, 1) = nplan.Dot(dw1pts1);
287 DX(1, 2) = dnplan.Dot(nps1) - Normg;
292 DX(2, 2) = dnplan.Dot(nps2) - Normg;
293 DX(2, 3) = nplan.Dot(d1u2);
294 DX(2, 4) = nplan.Dot(d1v2);
297 DX(3, 1) = -dw1pts1.Dot(tempVec);
298 DX(3, 2) = d1gui.Dot(tempVec);
302 temp = F4 * (dw1csurf.Dot(s1s2) - tsurf1.Dot(dw1pts1));
303 temp += nplan.Dot(tsurf1.Crossed(dw1pts1) - dw1csurf.Crossed(s1s2));
304 DX(4, 1) = PScaInv * temp;
306 temp = F4 * dwtsurf1.Dot(s1s2);
307 temp -= dnplan.Dot(tempVec) + nplan.Dot(dwtsurf1.Crossed(s1s2));
308 DX(4, 2) = PScaInv * temp;
309 temp = F4 * tsurf1.Dot(d1u2) - nplan.Dot(tsurf1.Crossed(d1u2));
310 DX(4, 3) = PScaInv * temp;
312 temp = F4 * tsurf1.Dot(d1v2) - nplan.Dot(tsurf1.Crossed(d1v2));
313 DX(4, 4) = PScaInv * temp;
316 gp_Vec d1utsurf1, d1vtsurf1, dw2pts2;
317 d1utsurf1 = (d2u1.Crossed(d1v1) + d1u1.Crossed(d2uv1)).Crossed(nplan);
318 d1vtsurf1 = (d2uv1.Crossed(d1v1) + d1u1.Crossed(d2v1)).Crossed(nplan);
319 dw2pts2 = v2d.X() * d1u2 + v2d.Y() * d1v2;
320 dwtsurf1 = Nsurf1.Crossed(dnplan);
323 DX(1, 2) = dnplan.Dot(nps1) - Normg;
324 DX(1, 3) = nplan.Dot(d1u1);
325 DX(1, 4) = nplan.Dot(d1v1);
327 DX(2, 1) = nplan.Dot(dw2pts2);
328 DX(2, 2) = dnplan.Dot(nps2) - Normg;
334 DX(3, 2) = d1gui.Dot(tempVec);
337 DX(3, 3) = d1u1.Dot(tempVec);
338 DX(3, 4) = d1v1.Dot(tempVec);
340 temp = F4 * tsurf1.Dot(dw2pts2) - nplan.Dot(tsurf1.Crossed(dw2pts2));
341 DX(4, 1) = PScaInv * temp;
343 temp = F4 * dwtsurf1.Dot(s1s2);
344 temp -= dnplan.Dot(tempVec) + nplan.Dot(dwtsurf1.Crossed(s1s2));
345 DX(4, 2) = PScaInv * temp;
347 temp = F4 * (d1utsurf1.Dot(s1s2) - tsurf1.Dot(d1u1));
348 temp += nplan.Dot(tsurf1.Crossed(d1u1) - d1utsurf1.Crossed(s1s2));
349 DX(4, 3) = PScaInv * temp;
351 temp = F4 * (d1vtsurf1.Dot(s1s2) - tsurf1.Dot(d1v1));
352 temp += nplan.Dot(tsurf1.Crossed(d1v1) - d1vtsurf1.Crossed(s1s2));
353 DX(4, 4) = PScaInv * temp;
357 return Standard_True;
361 //=======================================================================
364 //=======================================================================
366 Standard_Boolean BlendFunc_ChAsymInv::Value(const math_Vector& X, math_Vector& F)
368 const Standard_Boolean Error = ComputeValues(X, 0, 0);
374 //=======================================================================
375 //function : Derivatives
377 //=======================================================================
379 Standard_Boolean BlendFunc_ChAsymInv::Derivatives(const math_Vector& X, math_Matrix& D)
381 const Standard_Boolean Error = ComputeValues(X, 1, 1);
386 //=======================================================================
389 //=======================================================================
391 Standard_Boolean BlendFunc_ChAsymInv::Values(const math_Vector& X,
395 const Standard_Boolean Error = ComputeValues(X, 0, 1);
400 cout<<" test ChAsymInv"<<endl;
401 cout<<"calcul exact <--> approche"<<endl;
405 X1 = X; X1(1) += 1.e-10;
407 cout<<"D(1,1) : "<<D(1,1)<<" "<<(F1(1) - F(1)) * 1.e10<<endl;
408 cout<<"D(2,1) : "<<D(2,1)<<" "<<(F1(2) - F(2)) * 1.e10<<endl;
409 cout<<"D(3,1) : "<<D(3,1)<<" "<<(F1(3) - F(3)) * 1.e10<<endl;
410 cout<<"D(4,1) : "<<D(4,1)<<" "<<(F1(4) - F(4)) * 1.e10<<endl;
411 X1 = X; X1(2) += 1.e-10;
413 cout<<"D(1,2) : "<<D(1,2)<<" "<<(F1(1) - F(1)) * 1.e10<<endl;
414 cout<<"D(2,2) : "<<D(2,2)<<" "<<(F1(2) - F(2)) * 1.e10<<endl;
415 cout<<"D(3,2) : "<<D(3,2)<<" "<<(F1(3) - F(3)) * 1.e10<<endl;
416 cout<<"D(4,2) : "<<D(4,2)<<" "<<(F1(4) - F(4)) * 1.e10<<endl;
417 X1 = X; X1(3) += 1.e-10;
419 cout<<"D(1,3) : "<<D(1,3)<<" "<<(F1(1) - F(1)) * 1.e10<<endl;
420 cout<<"D(2,3) : "<<D(2,3)<<" "<<(F1(2) - F(2)) * 1.e10<<endl;
421 cout<<"D(3,3) : "<<D(3,3)<<" "<<(F1(3) - F(3)) * 1.e10<<endl;
422 cout<<"D(4,3) : "<<D(4,3)<<" "<<(F1(4) - F(4)) * 1.e10<<endl;
423 X1 = X; X1(4) += 1.e-10;
425 cout<<"D(1,4) : "<<D(1,4)<<" "<<(F1(1) - F(1)) * 1.e10<<endl;
426 cout<<"D(2,4) : "<<D(2,4)<<" "<<(F1(2) - F(2)) * 1.e10<<endl;
427 cout<<"D(3,4) : "<<D(3,4)<<" "<<(F1(3) - F(3)) * 1.e10<<endl;
428 cout<<"D(4,4) : "<<D(4,4)<<" "<<(F1(4) - F(4)) * 1.e10<<endl;*/