1 // Created on: 1996-06-04
2 // Created by: Stagiaire Xuan Trang PHAMPHU
3 // Copyright (c) 1996-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 <Adaptor3d_HCurve.hxx>
19 #include <Adaptor3d_HSurface.hxx>
20 #include <BlendFunc.hxx>
21 #include <BlendFunc_Corde.hxx>
26 #include <gp_Vec2d.hxx>
27 #include <math_Gauss.hxx>
28 #include <math_Matrix.hxx>
29 #include <Standard_DomainError.hxx>
30 #include <Standard_NotImplemented.hxx>
32 //=======================================================================
33 //function : BlendFunc_Corde
35 //=======================================================================
36 BlendFunc_Corde::BlendFunc_Corde(const Handle(Adaptor3d_HSurface)& S,
37 const Handle(Adaptor3d_HCurve)& CG)
43 istangent(Standard_False)
47 //=======================================================================
50 //=======================================================================
52 void BlendFunc_Corde::SetDist(const Standard_Real Dist)
57 //=======================================================================
60 //=======================================================================
62 void BlendFunc_Corde::SetParam(const Standard_Real Param)
64 guide->D2(Param,ptgui,d1gui,d2gui);
65 normtg = d1gui.Magnitude();
66 nplan = d1gui.Normalized();
67 theD = - (nplan.XYZ().Dot(ptgui.XYZ()));
70 //=======================================================================
72 //purpose : returns F(U,V)
73 //=======================================================================
75 Standard_Boolean BlendFunc_Corde::Value(const math_Vector& X, math_Vector& F)
78 surf->D1(X(1),X(2),pts,d1u,d1v);
80 F(1) = nplan.XYZ().Dot(pts.XYZ()) + theD;
81 const gp_Vec vref(ptgui,pts);
82 F(2) = vref.SquareMagnitude() - dis*dis;
87 //=======================================================================
88 //function : Derivatives
89 //purpose : D = grad F(U,V)
90 //=======================================================================
92 Standard_Boolean BlendFunc_Corde::Derivatives(const math_Vector& X, math_Matrix& D)
95 surf->D1(X(1),X(2),pts,d1u,d1v);
97 D(1,1) = nplan.Dot(d1u);
98 D(1,2) = nplan.Dot(d1v);
99 D(2,1) = 2.*gp_Vec(ptgui,pts).Dot(d1u);
100 D(2,2) = 2.*gp_Vec(ptgui,pts).Dot(d1v);
102 return Standard_True;
105 //=======================================================================
106 //function : PointOnS
108 //=======================================================================
110 const gp_Pnt& BlendFunc_Corde::PointOnS () const
116 //=======================================================================
117 //function : PointOnGuide
119 //=======================================================================
121 const gp_Pnt& BlendFunc_Corde::PointOnGuide () const
127 //=======================================================================
130 //=======================================================================
132 const gp_Vec& BlendFunc_Corde::NPlan () const
138 //=======================================================================
139 //function : IsTangencyPoint
141 //=======================================================================
143 Standard_Boolean BlendFunc_Corde::IsTangencyPoint () const
149 //=======================================================================
150 //function : TangentOnS
152 //=======================================================================
154 const gp_Vec& BlendFunc_Corde::TangentOnS () const
157 throw Standard_DomainError("BlendFunc_Corde::TangentOnS");
162 //=======================================================================
163 //function : Tangent2dOnS
165 //=======================================================================
167 const gp_Vec2d& BlendFunc_Corde::Tangent2dOnS () const
170 throw Standard_DomainError("BlendFunc_Corde::Tangent2dOnS");
175 //=======================================================================
176 //function : DerFguide
178 //=======================================================================
180 void BlendFunc_Corde::DerFguide (const math_Vector& Sol, gp_Vec2d& DerF)
183 surf->D1(Sol(1),Sol(2),pts,d1u,d1v);
186 dnplan.SetLinearForm(1./normtg,d2gui,-1./normtg*(nplan.Dot(d2gui)),nplan);
188 const gp_Vec temp(pts.XYZ()-ptgui.XYZ());
190 DerF.SetX( dnplan.Dot(temp)-nplan.Dot(d1gui) );
191 DerF.SetY( -2.*d1gui.Dot(temp) );
194 //=======================================================================
195 //function : IsSolution
197 //=======================================================================
199 Standard_Boolean BlendFunc_Corde::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
201 math_Vector secmember(1,2),valsol(1,2);
202 math_Matrix gradsol(1,2,1,2);
204 gp_Vec dnplan,temp,d1u,d1v;
207 Derivatives(Sol,gradsol);
208 if (Abs(valsol(1)) <= Tol &&
209 Abs(valsol(2)) <= Tol*Tol) {
211 surf->D1(Sol(1),Sol(2),pts,d1u,d1v);
212 dnplan.SetLinearForm(1./normtg,d2gui,
213 -1./normtg*(nplan.Dot(d2gui)),nplan);
215 temp.SetXYZ(pts.XYZ()-ptgui.XYZ());
217 secmember(1) = nplan.Dot(d1gui) - dnplan.Dot(temp);
218 secmember(2) = 2.*d1gui.Dot(temp);
220 // gradsol*der = secmember
221 // with der(1) = dU/dW, der(2) = dU/dW, W is the guide parameter
223 math_Gauss Resol(gradsol);
224 if (Resol.IsDone()) {
225 Resol.Solve(secmember);
226 tgs.SetLinearForm(secmember(1),d1u,secmember(2),d1v);
227 tg2d.SetCoord(secmember(1),secmember(2));
228 istangent = Standard_False;
231 istangent = Standard_True;
233 return Standard_True;
236 return Standard_False;