0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / Geom2dGcc / Geom2dGcc_FunctionTanCuCuOnCu.cxx
1 // Created on: 1992-01-20
2 // Created by: Remi GILET
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <ElCLib.hxx>
19 #include <Geom2dAdaptor_Curve.hxx>
20 #include <Geom2dGcc_CurveTool.hxx>
21 #include <Geom2dGcc_FunctionTanCuCuOnCu.hxx>
22 #include <gp_Circ2d.hxx>
23 #include <gp_Lin2d.hxx>
24 #include <gp_Pnt2d.hxx>
25 #include <gp_Vec2d.hxx>
26 #include <math_Matrix.hxx>
27 #include <Standard_ConstructionError.hxx>
28
29 void Geom2dGcc_FunctionTanCuCuOnCu::
30   InitDerivative(const math_Vector&  X,
31                        gp_Pnt2d&     Point1,
32                        gp_Pnt2d&     Point2,
33                        gp_Pnt2d&     Point3,
34                        gp_Vec2d&     Tan1,
35                        gp_Vec2d&     Tan2,
36                        gp_Vec2d&     Tan3,
37                        gp_Vec2d&     D21,
38                        gp_Vec2d&     D22,
39                        gp_Vec2d&     D23) {
40   switch (TheType) {
41   case Geom2dGcc_CuCuOnCu:
42     {
43       Geom2dGcc_CurveTool::D2(Curv1,X(1),Point1,Tan1,D21);
44       Geom2dGcc_CurveTool::D2(Curv2,X(2),Point2,Tan2,D22);
45       Geom2dGcc_CurveTool::D2(Curvon,X(3),Point3,Tan3,D23);
46     }
47     break;
48   case Geom2dGcc_CiCuOnCu:
49     {
50       ElCLib::D2(X(1),Circ1,Point1,Tan1,D21);
51       Geom2dGcc_CurveTool::D2(Curv2,X(2),Point2,Tan2,D22);
52       Geom2dGcc_CurveTool::D2(Curvon,X(3),Point3,Tan3,D23);
53     }
54     break;
55   case Geom2dGcc_LiCuOnCu:
56     {
57       ElCLib::D1(X(1),Lin1,Point1,Tan1);
58       D21 = gp_Vec2d(0.,0.);
59       Geom2dGcc_CurveTool::D2(Curv2,X(2),Point2,Tan2,D22);
60       Geom2dGcc_CurveTool::D2(Curvon,X(3),Point3,Tan3,D23);
61     }
62     break;
63   case Geom2dGcc_CuPtOnCu:
64     {
65       Geom2dGcc_CurveTool::D2(Curv1,X(1),Point1,Tan1,D21);
66       Geom2dGcc_CurveTool::D2(Curvon,X(3),Point3,Tan3,D23);
67       Point2 = Pnt2;
68       Tan2 = gp_Vec2d(0.,0.);
69       D22 = gp_Vec2d(0.,0.);
70     }
71     break;
72   case Geom2dGcc_CuCuOnCi:
73     {
74       Geom2dGcc_CurveTool::D2(Curv1,X(1),Point1,Tan1,D21);
75       Geom2dGcc_CurveTool::D2(Curv2,X(2),Point2,Tan2,D22);
76       ElCLib::D2(X(3),Circon,Point3,Tan3,D23);
77     }
78     break;
79   case Geom2dGcc_CiCuOnCi:
80     {
81       ElCLib::D2(X(1),Circ1,Point1,Tan1,D21);
82       Geom2dGcc_CurveTool::D2(Curv2,X(2),Point2,Tan2,D22);
83       ElCLib::D2(X(3),Circon,Point3,Tan3,D23);
84     }
85     break;
86   case Geom2dGcc_LiCuOnCi:
87     {
88       ElCLib::D1(X(1),Lin1,Point1,Tan1);
89       D21 = gp_Vec2d(0.,0.);
90       Geom2dGcc_CurveTool::D2(Curv2,X(2),Point2,Tan2,D22);
91       ElCLib::D2(X(3),Circon,Point3,Tan3,D23);
92     }
93     break;
94   case Geom2dGcc_CuPtOnCi:
95     {
96       Geom2dGcc_CurveTool::D2(Curv1,X(1),Point1,Tan1,D21);
97       Point2 = Pnt2;
98       Tan2 = gp_Vec2d(0.,0.);
99       D22 = gp_Vec2d(0.,0.);
100       ElCLib::D2(X(3),Circon,Point3,Tan3,D23);
101     }
102     break;
103   case Geom2dGcc_CuCuOnLi:
104     {
105       Geom2dGcc_CurveTool::D2(Curv1,X(1),Point1,Tan1,D21);
106       Geom2dGcc_CurveTool::D2(Curv2,X(2),Point2,Tan2,D22);
107       ElCLib::D1(X(3),Linon,Point3,Tan3);
108       D23 = gp_Vec2d(0.,0.);
109     }
110     break;
111   case Geom2dGcc_CiCuOnLi:
112     {
113       ElCLib::D2(X(1),Circ1,Point1,Tan1,D21);
114       Geom2dGcc_CurveTool::D2(Curv2,X(2),Point2,Tan2,D22);
115       ElCLib::D1(X(3),Linon,Point3,Tan3);
116       D23 = gp_Vec2d(0.,0.);
117     }
118     break;
119   case Geom2dGcc_LiCuOnLi:
120     {
121       ElCLib::D1(X(1),Lin1,Point1,Tan1);
122       Geom2dGcc_CurveTool::D2(Curv2,X(2),Point2,Tan2,D22);
123       D21 = gp_Vec2d(0.,0.);
124       ElCLib::D1(X(3),Linon,Point3,Tan3);
125       D23 = gp_Vec2d(0.,0.);
126     }
127     break;
128   case Geom2dGcc_CuPtOnLi:
129     {
130       Geom2dGcc_CurveTool::D2(Curv1,X(1),Point1,Tan1,D21);
131       Point2 = Pnt2;
132       Tan2 = gp_Vec2d(0.,0.);
133       D22 = gp_Vec2d(0.,0.);
134       ElCLib::D1(X(3),Linon,Point3,Tan3);
135       D23 = gp_Vec2d(0.,0.);
136     }
137     break;
138   default:
139     {
140       throw Standard_ConstructionError();
141     }
142   }
143 }
144
145 Geom2dGcc_FunctionTanCuCuOnCu::
146   Geom2dGcc_FunctionTanCuCuOnCu(const Geom2dAdaptor_Curve&     C1  ,
147                              const Geom2dAdaptor_Curve&     C2  ,
148                              const Geom2dAdaptor_Curve&     C3  ,
149                              const Standard_Real Rad ) {
150   Curv1  = C1;
151   Curv2  = C2;
152   Curvon = C3;
153   FirstRad = Rad;
154   TheType = Geom2dGcc_CuCuOnCu;
155 }
156
157 Geom2dGcc_FunctionTanCuCuOnCu::
158   Geom2dGcc_FunctionTanCuCuOnCu(const gp_Circ2d&    C1  ,
159                              const Geom2dAdaptor_Curve&     C2  ,
160                              const Geom2dAdaptor_Curve&     C3  ,
161                              const Standard_Real Rad ) {
162   Circ1  = C1;
163   Curv2  = C2;
164   Curvon = C3;
165   FirstRad = Rad;
166   TheType = Geom2dGcc_CiCuOnCu;
167 }
168
169 Geom2dGcc_FunctionTanCuCuOnCu::
170   Geom2dGcc_FunctionTanCuCuOnCu(const gp_Lin2d&     L1  ,
171                              const Geom2dAdaptor_Curve&     C2  ,
172                              const Geom2dAdaptor_Curve&     C3  ,
173                              const Standard_Real Rad ) {
174   Lin1  = L1;
175   Curv2  = C2;
176   Curvon = C3;
177   FirstRad = Rad;
178   TheType = Geom2dGcc_LiCuOnCu;
179 }
180
181 Geom2dGcc_FunctionTanCuCuOnCu::
182   Geom2dGcc_FunctionTanCuCuOnCu(const Geom2dAdaptor_Curve& C1  ,
183                              const gp_Pnt2d&  P2  ,
184                              const Geom2dAdaptor_Curve&  C3  ,
185                              const Standard_Real       Rad ) {
186   Curv1  = C1;
187   Pnt2  = P2;
188   Curvon = C3;
189   FirstRad = Rad;
190   TheType = Geom2dGcc_CuPtOnCu;
191 }
192
193 Geom2dGcc_FunctionTanCuCuOnCu::
194   Geom2dGcc_FunctionTanCuCuOnCu(const Geom2dAdaptor_Curve& C1   ,
195                              const Geom2dAdaptor_Curve&  C2   ,
196                              const gp_Lin2d&  OnLi ,
197                              const Standard_Real       Rad  ) {
198   Curv1  = C1;
199   Curv2  = C2;
200   Linon = OnLi;
201   FirstRad = Rad;
202   TheType = Geom2dGcc_CuCuOnLi;
203 }
204
205 Geom2dGcc_FunctionTanCuCuOnCu::
206   Geom2dGcc_FunctionTanCuCuOnCu(const gp_Circ2d&           C1   ,
207                                const Geom2dAdaptor_Curve& C2   ,
208                                const gp_Lin2d&            OnLi ,
209                                const Standard_Real                 Rad  ) {
210   Circ1  = C1;
211   Curv2  = C2;
212   Linon = OnLi;
213   FirstRad = Rad;
214   TheType = Geom2dGcc_CiCuOnLi;
215 }
216
217 Geom2dGcc_FunctionTanCuCuOnCu::
218   Geom2dGcc_FunctionTanCuCuOnCu(const gp_Lin2d& L1  ,
219                                const Geom2dAdaptor_Curve&  C2  ,
220                                const gp_Lin2d&  OnLi ,
221                                const Standard_Real       Rad ) {
222   Lin1  = L1;
223   Curv2  = C2;
224   Linon = OnLi;
225   FirstRad = Rad;
226   TheType = Geom2dGcc_LiCuOnLi;
227 }
228
229 Geom2dGcc_FunctionTanCuCuOnCu::
230   Geom2dGcc_FunctionTanCuCuOnCu(const Geom2dAdaptor_Curve& C1  ,
231                                const gp_Pnt2d&            P2  ,
232                                const gp_Lin2d&            OnLi ,
233                                const Standard_Real                 Rad ) {
234   Curv1  = C1;
235   Pnt2  = P2;
236   Linon = OnLi;
237   FirstRad = Rad;
238   TheType = Geom2dGcc_CuPtOnLi;
239 }
240
241 Geom2dGcc_FunctionTanCuCuOnCu::
242   Geom2dGcc_FunctionTanCuCuOnCu(const Geom2dAdaptor_Curve& C1   ,
243                                const Geom2dAdaptor_Curve& C2   ,
244                                const gp_Circ2d&           OnCi ,
245                                const Standard_Real                 Rad  ) {
246   Curv1  = C1;
247   Curv2  = C2;
248   Circon = OnCi;
249   FirstRad = Rad;
250   TheType = Geom2dGcc_CuCuOnCi;
251 }
252
253 Geom2dGcc_FunctionTanCuCuOnCu::
254   Geom2dGcc_FunctionTanCuCuOnCu(const gp_Circ2d&           C1  ,
255                                const Geom2dAdaptor_Curve& C2  ,
256                                const gp_Circ2d&           OnCi ,
257                                const Standard_Real                 Rad ) {
258   Circ1  = C1;
259   Curv2  = C2;
260   Circon = OnCi;
261   FirstRad = Rad;
262   TheType = Geom2dGcc_CuCuOnCi;
263 }
264
265 Geom2dGcc_FunctionTanCuCuOnCu::
266   Geom2dGcc_FunctionTanCuCuOnCu(const gp_Lin2d& L1  ,
267                                const Geom2dAdaptor_Curve&  C2  ,
268                                const gp_Circ2d& OnCi ,
269                                const Standard_Real       Rad ) {
270   Lin1  = L1;
271   Curv2  = C2;
272   Circon = OnCi;
273   FirstRad = Rad;
274   TheType = Geom2dGcc_LiCuOnCi;
275 }
276
277 Geom2dGcc_FunctionTanCuCuOnCu::
278   Geom2dGcc_FunctionTanCuCuOnCu(const Geom2dAdaptor_Curve& C1  ,
279                                const gp_Pnt2d&            P2  ,
280                                const gp_Circ2d&           OnCi ,
281                                const Standard_Real                 Rad ) {
282   Curv1  = C1;
283   Pnt2  = P2;
284   Circon = OnCi;
285   FirstRad = Rad;
286   TheType = Geom2dGcc_CuPtOnCi;
287 }
288
289 Standard_Integer Geom2dGcc_FunctionTanCuCuOnCu::
290   NbVariables () const { return 4; }
291
292 Standard_Integer Geom2dGcc_FunctionTanCuCuOnCu::
293   NbEquations () const { return 4; }
294
295 Standard_Boolean Geom2dGcc_FunctionTanCuCuOnCu::
296   Value (const math_Vector& X    ,
297                math_Vector& Fval ) {
298   gp_Pnt2d Point1,Point2,Point3;
299   gp_Vec2d Tan1,Tan2,Tan3,D21,D22,D23;
300   InitDerivative(X,Point1,Point2,Point3,Tan1,Tan2,Tan3,D21,D22,D23);
301 //pipj (normes) et PiPj (non Normes).
302   gp_Vec2d P1P2(Point1,Point2);
303   gp_Vec2d P2P3(Point2,Point3);
304   gp_Vec2d P3P1(Point3,Point1);
305   gp_Vec2d p1p2,p2p3,p3p1;
306 //  if (FirstRad < 1.) {FirstRad = 1.; }
307   p1p2 = P1P2/FirstRad;
308   p2p3 = P2P3/FirstRad;
309   p3p1 = P3P1/FirstRad;
310 //norme des Tani.
311   Standard_Real nnor1 = Tan1.Magnitude();
312   Standard_Real nnor2 = Tan2.Magnitude();
313 // Fonctions Fui.
314 // ==============
315   Fval(1) = (P3P1.Dot(P3P1)-X(4)*X(4))/(FirstRad*FirstRad);
316   Fval(2) = (P2P3.Dot(P2P3)-X(4)*X(4))/(FirstRad*FirstRad);
317   Fval(3) = P3P1.Dot(Tan1)/(nnor1*FirstRad);
318   Fval(4) = P2P3.Dot(Tan2)/(nnor2*FirstRad);
319   return Standard_True;
320 }
321
322 Standard_Boolean Geom2dGcc_FunctionTanCuCuOnCu::
323   Derivatives (const math_Vector& X     ,
324                      math_Matrix& Deriv ) {
325   gp_Pnt2d Point1,Point2,Point3;
326   gp_Vec2d Tan1,Tan2,Tan3;
327   gp_Vec2d D21,D22,D23;
328   InitDerivative(X,Point1,Point2,Point3,Tan1,Tan2,Tan3,D21,D22,D23);
329 //pipj (normes) et PiPj (non Normes).
330   gp_Vec2d P1P2(Point1,Point2);
331   gp_Vec2d P2P3(Point2,Point3);
332   gp_Vec2d P3P1(Point3,Point1);
333   gp_Vec2d p1p2,p2p3,p3p1;
334 //  if (FirstRad < 1.) {FirstRad = 1.; }
335   p1p2 = P1P2/FirstRad;
336   p2p3 = P2P3/FirstRad;
337   p3p1 = P3P1/FirstRad;
338 //normales au courbes normees Nori et non nromees nori et norme des nori.
339   Standard_Real nnor1 = Tan1.Magnitude();
340   Standard_Real nnor2 = Tan2.Magnitude();
341 // Derivees dFui/uj  1 <= ui <= 3 , 1 <= uj <= 3
342 // =============================================
343   Deriv(1,1) = 2.*Tan1.Dot(P3P1)/(FirstRad*FirstRad);
344   Deriv(1,2) = 0.;
345   Deriv(1,3) = -2.*Tan3.Dot(P3P1)/(FirstRad*FirstRad);
346   Deriv(1,4) = -2.*X(4)/(FirstRad*FirstRad);
347
348   Deriv(2,1) = 0.;
349   Deriv(2,2) = -2.*Tan2.Dot(P2P3)/(FirstRad*FirstRad);
350   Deriv(2,3) = 2.*Tan3.Dot(P2P3)/(FirstRad*FirstRad);
351   Deriv(2,4) = -2.*X(4)/(FirstRad*FirstRad);
352
353   Deriv(3,1) = (P3P1.Dot(D21)+Tan1.Dot(Tan1))/(FirstRad*nnor1)-
354     (P3P1.Dot(Tan1)*D21.Dot(Tan1))/(FirstRad*nnor1*nnor1*nnor1);
355   Deriv(3,2) = 0.;
356   Deriv(3,3) = -(Tan3.Dot(Tan1))/(FirstRad*nnor1);
357   Deriv(3,4) = 0.;
358
359   Deriv(4,1) = 0.;
360   Deriv(4,2) = (P2P3.Dot(D22)-Tan2.Dot(Tan2))/(FirstRad*nnor2)-
361     P2P3.Dot(Tan2)*Tan2.Dot(D22)/(FirstRad*nnor2*nnor2*nnor2);
362   Deriv(4,3) = Tan3.Dot(Tan2)/(FirstRad*nnor1);
363   Deriv(4,4) = 0.;
364   return Standard_True;
365 }
366
367 Standard_Boolean Geom2dGcc_FunctionTanCuCuOnCu::
368   Values (const math_Vector& X     ,
369                 math_Vector& Fval  ,
370                 math_Matrix& Deriv ) {
371   gp_Pnt2d Point1,Point2,Point3;
372   gp_Vec2d Tan1,Tan2,Tan3;
373   gp_Vec2d D21,D22,D23;
374   InitDerivative(X,Point1,Point2,Point3,Tan1,Tan2,Tan3,D21,D22,D23);
375 //pipj (normes) et PiPj (non Normes).
376   gp_Vec2d P1P2(Point1,Point2);
377   gp_Vec2d P2P3(Point2,Point3);
378   gp_Vec2d P3P1(Point3,Point1);
379   gp_Vec2d p1p2,p2p3,p3p1;
380 //  if (FirstRad < 1.) {FirstRad = 1.; }
381   p1p2 = P1P2/FirstRad;
382   p2p3 = P2P3/FirstRad;
383   p3p1 = P3P1/FirstRad;
384 //normales au courbes normees Nori et non nromees nori et norme des nori.
385   Standard_Real nnor1 = Tan1.Magnitude();
386   Standard_Real nnor2 = Tan2.Magnitude();
387 // Fonctions Fui.
388 // ==============
389   Fval(1) = (P3P1.Dot(P3P1)-X(4)*X(4))/(FirstRad*FirstRad);
390   Fval(2) = (P2P3.Dot(P2P3)-X(4)*X(4))/(FirstRad*FirstRad);
391   Fval(3) = P3P1.Dot(Tan1)/(nnor1*FirstRad);
392   Fval(4) = P2P3.Dot(Tan2)/(nnor2*FirstRad);
393 // Derivees dFui/uj  1 <= ui <= 3 , 1 <= uj <= 3
394 // =============================================
395   Deriv(1,1) = 2.*Tan1.Dot(P3P1)/(FirstRad*FirstRad);
396   Deriv(1,2) = 0.;
397   Deriv(1,3) = -2.*Tan3.Dot(P3P1)/(FirstRad*FirstRad);
398   Deriv(1,4) = -2.*X(4)/(FirstRad*FirstRad);
399
400   Deriv(2,1) = 0.;
401   Deriv(2,2) = -2.*Tan2.Dot(P2P3)/(FirstRad*FirstRad);
402   Deriv(2,3) = 2.*Tan3.Dot(P2P3)/(FirstRad*FirstRad);
403   Deriv(2,4) = -2.*X(4)/(FirstRad*FirstRad);
404
405   Deriv(3,1) = (P3P1.Dot(D21)+Tan1.Dot(Tan1))/(FirstRad*nnor1)-
406     (P3P1.Dot(Tan1)*D21.Dot(Tan1))/(FirstRad*nnor1*nnor1*nnor1);
407   Deriv(3,2) = 0.;
408   Deriv(3,3) = -(Tan3.Dot(Tan1))/(FirstRad*nnor1);
409   Deriv(3,4) = 0.;
410
411   Deriv(4,1) = 0.;
412   Deriv(4,2) = (P2P3.Dot(D22)-Tan2.Dot(Tan2))/(FirstRad*nnor2)-
413     P2P3.Dot(Tan2)*Tan2.Dot(D22)/(FirstRad*nnor2*nnor2*nnor2);
414   Deriv(4,3) = Tan3.Dot(Tan2)/(FirstRad*nnor1);
415   Deriv(4,4) = 0.;
416   return Standard_True;
417 }
418