6240670e776af067d387a411c0ccb6ef40e638cb
[occt.git] / src / IntImp / IntImp_ZerCOnSSParFunc.gxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <gp_Pnt.hxx>
16 #include <gp_Vec.hxx>
17 #include <gp_Pnt2d.hxx>
18 #include <gp_Vec2d.hxx>
19
20 #ifndef DEB
21 #define No_Standard_RangeError
22 #define No_Standard_OutOfRange
23 #endif
24
25
26 #define SURFACE1 (*((ThePSurface *)(surface1)))
27 #define SURFACE2 (*((ThePSurface *)(surface2)))
28 #define CURVE    (*((TheCurveOnSurf *)(curve)))
29
30 IntImp_ZerCOnSSParFunc::IntImp_ZerCOnSSParFunc(const ThePSurface& S1,
31                                                const TheCurveOnSurf& C,
32                                                const ThePSurface& S2)
33 {
34   surface1 = (Standard_Address)(&S1);
35   surface2 = (Standard_Address)(&S2);
36   curve    = (Standard_Address)(&C);
37 }
38
39 Standard_Integer IntImp_ZerCOnSSParFunc::NbVariables()const { return 3;}
40
41 Standard_Integer IntImp_ZerCOnSSParFunc::NbEquations()const { return 3;}
42
43 Standard_Boolean IntImp_ZerCOnSSParFunc::Value(const math_Vector& X,
44                                             math_Vector& F){
45
46   gp_Pnt Psurf(ThePSurfaceTool::Value(SURFACE1,X(1),X(2)));
47   gp_Pnt2d p2d(TheCurveTool::Value(CURVE,X(3)));
48   gp_Pnt Pcurv(ThePSurfaceTool::Value(SURFACE2,p2d.X(),p2d.Y()));
49
50   F(1) = Psurf.X()-Pcurv.X();
51   F(2) = Psurf.Y()-Pcurv.Y();
52   F(3) = Psurf.Z()-Pcurv.Z();
53   f = F(1)*F(1)+ F(2)*F(2)+ F(3)*F(3);
54   p = gp_Pnt((Psurf.XYZ()+Pcurv.XYZ())/2.);
55   return Standard_True;
56 }
57
58 Standard_Boolean IntImp_ZerCOnSSParFunc::Derivatives ( const math_Vector& X,
59                                                     math_Matrix& D) {
60   gp_Pnt Psurf,Pcurv;
61   gp_Vec D1u,D1v,D1w;
62   gp_Pnt2d p2d;
63   gp_Vec2d d2d;
64   gp_Vec d1u,d1v;
65
66   ThePSurfaceTool::D1(SURFACE1,X(1),X(2),Psurf,D1u,D1v);
67   TheCurveTool::D1(CURVE,X(3),p2d,d2d);
68   ThePSurfaceTool::D1(SURFACE2,p2d.X(),p2d.Y(),Pcurv,d1u,d1v);
69   D1w.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
70
71   D(1,1) = D1u.X();
72   D(1,2) = D1v.X();
73   D(1,3) = -D1w.X();
74   D(2,1) = D1u.Y();
75   D(2,2) = D1v.Y();
76   D(2,3) = -D1w.Y();
77   D(3,1) = D1u.Z();
78   D(3,2) = D1v.Z();
79   D(3,3) = -D1w.Z();
80   return Standard_True;
81
82
83 Standard_Boolean IntImp_ZerCOnSSParFunc::Values( const math_Vector& X,
84                                               math_Vector& F,
85                                               math_Matrix& D) {
86   gp_Pnt Psurf,Pcurv;
87   gp_Vec D1u,D1v,D1w;
88
89   gp_Pnt2d p2d;
90   gp_Vec2d d2d;
91   gp_Vec d1u,d1v;
92
93   ThePSurfaceTool::D1(SURFACE1,X(1),X(2),Psurf,D1u,D1v);
94   TheCurveTool::D1(CURVE,X(3),p2d,d2d);
95   ThePSurfaceTool::D1(SURFACE2,p2d.X(),p2d.Y(),Pcurv,d1u,d1v);
96   D1w.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
97
98   D(1,1) = D1u.X();
99   D(1,2) = D1v.X();
100   D(1,3) = -D1w.X();
101   D(2,1) = D1u.Y();
102   D(2,2) = D1v.Y();
103   D(2,3) = -D1w.Y();
104   D(3,1) = D1u.Z();
105   D(3,2) = D1v.Z();
106   D(3,3) = -D1w.Z();
107   F(1) = Psurf.X()-Pcurv.X();
108   F(2) = Psurf.Y()-Pcurv.Y();
109   F(3) = Psurf.Z()-Pcurv.Z();
110   f = F(1)*F(1)+ F(2)*F(2)+ F(3)*F(3);
111   p = gp_Pnt((Psurf.XYZ()+Pcurv.XYZ())/2.);
112   return Standard_True;
113 }
114
115 const gp_Pnt& IntImp_ZerCOnSSParFunc::Point() const { return p;}
116
117 Standard_Real IntImp_ZerCOnSSParFunc::Root() const { return f;}
118
119 const ThePSurface& IntImp_ZerCOnSSParFunc::AuxillarSurface() const { 
120   return SURFACE1;}
121
122 const TheCurveOnSurf& IntImp_ZerCOnSSParFunc::AuxillarCurve() const { 
123   return CURVE;}
124
125 #undef SURFACE1
126 #undef SURFACE2
127 #undef CURVE