017760d0c3f610cf4d9859643a60c725b3ae5029
[occt.git] / src / BlendFunc / BlendFunc_Corde.cxx
1 // File:      BlendFunc_Corde.cxx
2 // Created:   Tue Jun  4 18:12:59 1996
3 // Author:    Stagiaire Xuan Trang PHAMPHU
4 // Copyright: OPEN CASCADE 1996
5
6 #include <BlendFunc_Corde.ixx>
7
8 #include <math_Gauss.hxx>
9
10 #include <ElCLib.hxx>
11 #include <gp.hxx>
12 #include <BlendFunc.hxx>
13 #include <Standard_DomainError.hxx>
14 #include <Standard_NotImplemented.hxx>
15
16
17 //=======================================================================
18 //function : BlendFunc_Corde
19 //purpose  : 
20 //=======================================================================
21
22 BlendFunc_Corde::BlendFunc_Corde(const Handle(Adaptor3d_HSurface)&   S,
23                                  const Handle(Adaptor3d_HCurve)&     CG) :
24     surf(S),guide(CG)
25 {
26 }
27
28 //=======================================================================
29 //function : SetDist
30 //purpose  : 
31 //=======================================================================
32
33 void BlendFunc_Corde::SetDist(const Standard_Real Dist)
34 {
35   dis = Dist;
36 }
37
38 //=======================================================================
39 //function : SetParam
40 //purpose  : 
41 //=======================================================================
42
43 void BlendFunc_Corde::SetParam(const Standard_Real Param)
44 {
45   guide->D2(Param,ptgui,d1gui,d2gui);
46   normtg = d1gui.Magnitude();
47   nplan  = d1gui.Normalized();
48   theD = - (nplan.XYZ().Dot(ptgui.XYZ()));
49 }
50
51 //=======================================================================
52 //function : Value
53 //purpose  : returns F(U,V)
54 //=======================================================================
55
56 Standard_Boolean BlendFunc_Corde::Value(const math_Vector& X, math_Vector& F)
57 {
58   gp_Vec d1u,d1v;
59   surf->D1(X(1),X(2),pts,d1u,d1v);
60
61   F(1) = nplan.XYZ().Dot(pts.XYZ()) + theD;
62   const gp_Vec vref(ptgui,pts);
63   F(2) = vref.SquareMagnitude() - dis*dis; 
64
65   return Standard_True;
66 }
67
68 //=======================================================================
69 //function : Derivatives
70 //purpose  : D = grad F(U,V)
71 //=======================================================================
72
73 Standard_Boolean BlendFunc_Corde::Derivatives(const math_Vector& X, math_Matrix& D)
74 {
75   gp_Vec d1u,d1v;
76   surf->D1(X(1),X(2),pts,d1u,d1v);  
77
78   D(1,1) = nplan.Dot(d1u);
79   D(1,2) = nplan.Dot(d1v); 
80   D(2,1) = 2.*gp_Vec(ptgui,pts).Dot(d1u);
81   D(2,2) = 2.*gp_Vec(ptgui,pts).Dot(d1v);
82
83   return Standard_True;
84 }
85
86 //=======================================================================
87 //function : PointOnS
88 //purpose  : 
89 //=======================================================================
90
91 const gp_Pnt& BlendFunc_Corde::PointOnS () const
92 {
93   return pts;
94 }
95
96
97 //=======================================================================
98 //function : PointOnGuide
99 //purpose  : 
100 //=======================================================================
101
102 const gp_Pnt& BlendFunc_Corde::PointOnGuide () const
103 {
104   return ptgui;
105 }
106
107
108 //=======================================================================
109 //function : Nplan
110 //purpose  : 
111 //=======================================================================
112
113 const gp_Vec& BlendFunc_Corde::NPlan () const
114 {
115   return nplan;
116 }
117
118
119 //=======================================================================
120 //function : IsTangencyPoint
121 //purpose  : 
122 //=======================================================================
123
124 Standard_Boolean BlendFunc_Corde::IsTangencyPoint () const
125 {
126   return istangent;
127 }
128
129
130 //=======================================================================
131 //function : TangentOnS
132 //purpose  : 
133 //=======================================================================
134
135 const gp_Vec& BlendFunc_Corde::TangentOnS () const
136 {
137   if (istangent)
138     Standard_DomainError::Raise("BlendFunc_Corde::TangentOnS");
139   return tgs;
140 }
141
142
143 //=======================================================================
144 //function : Tangent2dOnS
145 //purpose  : 
146 //=======================================================================
147
148 const gp_Vec2d& BlendFunc_Corde::Tangent2dOnS () const
149 {
150   if (istangent) 
151     Standard_DomainError::Raise("BlendFunc_Corde::Tangent2dOnS");
152   return tg2d;
153 }
154
155
156 //=======================================================================
157 //function : DerFguide
158 //purpose  : dF/dw
159 //=======================================================================
160
161 void BlendFunc_Corde::DerFguide (const math_Vector& Sol, gp_Vec2d& DerF)
162 {
163   gp_Vec d1u,d1v;
164   surf->D1(Sol(1),Sol(2),pts,d1u,d1v);
165
166   gp_Vec dnplan;
167   dnplan.SetLinearForm(1./normtg,d2gui,-1./normtg*(nplan.Dot(d2gui)),nplan);
168
169   const gp_Vec temp(pts.XYZ()-ptgui.XYZ());
170
171   DerF.SetX( dnplan.Dot(temp)-nplan.Dot(d1gui) );
172   DerF.SetY( -2.*d1gui.Dot(temp) );
173 }
174
175 //=======================================================================
176 //function : IsSolution
177 //purpose  :
178 //=======================================================================
179
180 Standard_Boolean BlendFunc_Corde::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
181 {
182   math_Vector secmember(1,2),valsol(1,2);
183   math_Matrix gradsol(1,2,1,2);
184
185   gp_Vec dnplan,temp,d1u,d1v;
186
187   Value(Sol,valsol);
188   Derivatives(Sol,gradsol);
189   if (Abs(valsol(1)) <= Tol &&
190       Abs(valsol(2)) <= Tol*Tol) {
191
192     surf->D1(Sol(1),Sol(2),pts,d1u,d1v);
193     dnplan.SetLinearForm(1./normtg,d2gui,
194                          -1./normtg*(nplan.Dot(d2gui)),nplan); 
195
196     temp.SetXYZ(pts.XYZ()-ptgui.XYZ());
197
198     secmember(1) = nplan.Dot(d1gui) - dnplan.Dot(temp);
199     secmember(2) = 2.*d1gui.Dot(temp);
200
201 //  gradsol*der = secmember
202 //  avec der(1) = dU/dW, der(2) = dU/dW, W est le parametre de guide
203
204     math_Gauss Resol(gradsol);
205     if (Resol.IsDone()) {
206       Resol.Solve(secmember);
207       tgs.SetLinearForm(secmember(1),d1u,secmember(2),d1v);
208       tg2d.SetCoord(secmember(1),secmember(2));
209       istangent = Standard_False;
210     }
211     else {
212       istangent = Standard_True;
213     }
214     return Standard_True;
215   }
216
217   return Standard_False;
218 }