0022312: Translation of french commentaries in OCCT files
[occt.git] / src / Contap / Contap_SurfProps.gxx
1 // File:      Contap_SurfProps.gxx
2 // Created:   Fri Feb 24 15:37:28 1995
3 // Author:    Jacques GOUSSARD
4 // Copyright: OPEN CASCADE 2000
5
6 #include <ElSLib.hxx>
7
8 //=======================================================================
9 //function : Normale
10 //purpose  : 
11 //=======================================================================
12
13 void Contap_SurfProps::Normale(const TheSurface& S, 
14                                const Standard_Real U, 
15                                const Standard_Real V,
16                                gp_Pnt& P,
17                                gp_Vec& Norm)
18 {
19
20   GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(S);
21   switch (typS) {
22   case GeomAbs_Plane:
23     {
24       gp_Pln pl(TheSurfaceTool::Plane(S));
25       Norm = pl.Axis().Direction();
26       P = ElSLib::Value(U,V,pl);
27       if (!pl.Direct()) {
28         Norm.Reverse();
29       }
30     }
31     break;
32
33
34   case GeomAbs_Sphere:
35     {
36       gp_Sphere sp(TheSurfaceTool::Sphere(S));
37       P = ElSLib::Value(U,V,sp);
38       Norm = gp_Vec(sp.Location(),P);
39       if (sp.Direct()) {
40         Norm.Divide(sp.Radius());
41       }
42       else {
43         Norm.Divide(-sp.Radius());
44       }
45     }
46     break;
47
48   case GeomAbs_Cylinder:
49     {
50       gp_Cylinder cy(TheSurfaceTool::Cylinder(S));
51       P = ElSLib::Value(U,V,cy);
52       Norm.SetLinearForm(Cos(U),cy.XAxis().Direction(),
53                          Sin(U),cy.YAxis().Direction());
54       if (!cy.Direct()) {
55         Norm.Reverse();
56       }
57     }
58     break;
59
60
61   case GeomAbs_Cone:
62     {
63       gp_Cone co(TheSurfaceTool::Cone(S));
64       P = ElSLib::Value(U,V,co);
65       Standard_Real Angle = co.SemiAngle();
66       Standard_Real Sina = sin(Angle);
67       Standard_Real Cosa = cos(Angle);
68       Standard_Real Rad = co.RefRadius(); 
69
70       Standard_Real Vcalc = V;
71       if (Abs(V*Sina + Rad) <= 1e-12) { // on est a l`apex
72         /*
73            Standard_Real Vfi = TheSurfaceTool::FirstVParameter(S);
74            if (Vfi < -Rad/Sina) { // partie valide pour V < Vapex
75            Vcalc = V - 1;
76            }
77            else {
78            Vcalc = V + 1.;
79            }
80            */
81         Norm.SetCoord(0,0,0);
82         return;
83       }
84
85       if (Rad + Vcalc*Sina < 0.) {
86         Norm.SetLinearForm(Sina,       co.Axis().Direction(),
87                            Cosa*cos(U),co.XAxis().Direction(),
88                            Cosa*sin(U),co.YAxis().Direction());
89       }
90       else {
91         Norm.SetLinearForm(-Sina,       co.Axis().Direction(),
92                             Cosa*cos(U),co.XAxis().Direction(),
93                             Cosa*sin(U),co.YAxis().Direction());
94       }
95       if (!co.Direct()) {
96         Norm.Reverse();
97       }
98     }
99     break;
100   default:
101     {
102       gp_Vec d1u,d1v;
103       TheSurfaceTool::D1(S,U,V,P,d1u,d1v);
104       Norm = d1u.Crossed(d1v);
105     }
106     break;
107
108
109   }
110 }
111
112
113 //=======================================================================
114 //function : DerivAndNorm
115 //purpose  : 
116 //=======================================================================
117
118 void Contap_SurfProps::DerivAndNorm(const TheSurface& S, 
119                                     const Standard_Real U, 
120                                     const Standard_Real V,
121                                     gp_Pnt& P,
122                                     gp_Vec& d1u,
123                                     gp_Vec& d1v,
124                                     gp_Vec& Norm)
125 {
126
127   GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(S);
128   switch (typS) {
129   case GeomAbs_Plane:
130     {
131       gp_Pln pl(TheSurfaceTool::Plane(S));
132       Norm = pl.Axis().Direction();
133       ElSLib::D1(U,V,pl,P,d1u,d1v);
134       if (!pl.Direct()) {
135         Norm.Reverse();
136       }
137     }
138     break;
139
140
141   case GeomAbs_Sphere:
142     {
143       gp_Sphere sp(TheSurfaceTool::Sphere(S));
144       ElSLib::D1(U,V,sp,P,d1u,d1v);
145       Norm = gp_Vec(sp.Location(),P);
146       if (sp.Direct()) {
147         Norm.Divide(sp.Radius());
148       }
149       else {
150         Norm.Divide(-sp.Radius());
151       }
152     }
153     break;
154
155   case GeomAbs_Cylinder:
156     {
157       gp_Cylinder cy(TheSurfaceTool::Cylinder(S));
158       ElSLib::D1(U,V,cy,P,d1u,d1v);
159       Norm.SetLinearForm(Cos(U),cy.XAxis().Direction(),
160                          Sin(U),cy.YAxis().Direction());
161       if (!cy.Direct()) {
162         Norm.Reverse();
163       }
164     }
165     break;
166
167
168   case GeomAbs_Cone:
169     {
170       gp_Cone co(TheSurfaceTool::Cone(S));
171       ElSLib::D1(U,V,co,P,d1u,d1v);
172       Standard_Real Angle = co.SemiAngle();
173       Standard_Real Sina = Sin(Angle);
174       Standard_Real Cosa = Cos(Angle);
175       Standard_Real Rad = co.RefRadius(); 
176
177       Standard_Real Vcalc = V;
178       if (Abs(V*Sina + Rad) <= RealEpsilon()) { // on est a l`apex
179         Standard_Real Vfi = TheSurfaceTool::FirstVParameter(S);
180         if (Vfi < -Rad/Sina) { // partie valide pour V < Vapex
181           Vcalc = V - 1;
182         }
183         else {
184           Vcalc = V + 1.;
185         }
186       }
187
188       if (Rad + Vcalc*Sina < 0.) {
189         Norm.SetLinearForm(Sina,       co.Axis().Direction(),
190                            Cosa*Cos(U),co.XAxis().Direction(),
191                            Cosa*Sin(U),co.YAxis().Direction());
192       }
193       else {
194         Norm.SetLinearForm(-Sina,       co.Axis().Direction(),
195                             Cosa*Cos(U),co.XAxis().Direction(),
196                             Cosa*Sin(U),co.YAxis().Direction());
197       }
198       if (!co.Direct()) {
199         Norm.Reverse();
200       }
201     }
202     break;
203   default:
204     {
205       TheSurfaceTool::D1(S,U,V,P,d1u,d1v);
206       Norm = d1u.Crossed(d1v);
207     }
208     break;
209   }
210 }
211
212
213 //=======================================================================
214 //function : NormAndDn
215 //purpose  : 
216 //=======================================================================
217
218 void Contap_SurfProps::NormAndDn(const TheSurface& S, 
219                                  const Standard_Real U, 
220                                  const Standard_Real V,
221                                  gp_Pnt& P,
222                                  gp_Vec& Norm,
223                                  gp_Vec& Dnu,
224                                  gp_Vec& Dnv)
225 {
226
227   GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(S);
228   switch (typS) {
229   case GeomAbs_Plane:
230     {
231       gp_Pln pl(TheSurfaceTool::Plane(S));
232       P = ElSLib::Value(U,V,pl);
233       Norm = pl.Axis().Direction();
234       if (!pl.Direct()) {
235         Norm.Reverse();
236       }
237       Dnu = Dnv = gp_Vec(0.,0.,0.);
238     }
239     break;
240
241   case GeomAbs_Sphere:
242     {
243       gp_Sphere sp(TheSurfaceTool::Sphere(S));
244       ElSLib::D1(U,V,sp,P,Dnu,Dnv);
245       Norm = gp_Vec(sp.Location(),P);
246       Standard_Real Rad = sp.Radius();
247       if (!sp.Direct()) {
248         Rad = -Rad;
249       }
250       Norm.Divide(Rad);
251       Dnu.Divide(Rad);
252       Dnv.Divide(Rad);
253     }
254     break;
255
256   case GeomAbs_Cylinder:
257     {
258       gp_Cylinder cy(TheSurfaceTool::Cylinder(S));
259       P = ElSLib::Value(U,V,cy);
260       Norm.SetLinearForm(Cos(U),cy.XAxis().Direction(),
261                          Sin(U),cy.YAxis().Direction());
262       Dnu.SetLinearForm(-Sin(U),cy.XAxis().Direction(),
263                          Cos(U),cy.YAxis().Direction());
264       if (!cy.Direct()) {
265         Norm.Reverse();
266         Dnu.Reverse();
267       }
268       Dnv = gp_Vec(0.,0.,0.);
269     }
270     break;
271
272   case GeomAbs_Cone:
273     {
274
275       gp_Cone co(TheSurfaceTool::Cone(S));
276       P = ElSLib::Value(U,V,co);
277       Standard_Real Angle = co.SemiAngle();
278       Standard_Real Sina = Sin(Angle);
279       Standard_Real Cosa = Cos(Angle);
280       Standard_Real Rad = co.RefRadius(); 
281       Standard_Real Vcalc = V;
282       if (Abs(V*Sina + Rad) <= RealEpsilon()) { // on est a l`apex
283         Standard_Real Vfi = TheSurfaceTool::FirstVParameter(S);
284         if (Vfi < -Rad/Sina) { // partie valide pour V < Vapex
285           Vcalc = V - 1;
286         }
287         else {
288           Vcalc = V + 1.;
289         }
290       }
291
292       if (Rad + Vcalc*Sina < 0.) {
293         Norm.SetLinearForm(Sina,       co.Axis().Direction(),
294                            Cosa*Cos(U),co.XAxis().Direction(),
295                            Cosa*Sin(U),co.YAxis().Direction());
296       }
297       else {
298         Norm.SetLinearForm(-Sina,       co.Axis().Direction(),
299                             Cosa*Cos(U),co.XAxis().Direction(),
300                             Cosa*Sin(U),co.YAxis().Direction());
301       }
302       Dnu.SetLinearForm(-Cosa*Sin(U),co.XAxis().Direction(),
303                          Cosa*Cos(U),co.YAxis().Direction());
304       if (!co.Direct()) {
305         Norm.Reverse();
306         Dnu.Reverse();
307       }
308       Dnv = gp_Vec(0.,0.,0.);
309     }
310     break;
311   
312   default: 
313     {
314       gp_Vec d1u,d1v,d2u,d2v,d2uv;
315       TheSurfaceTool::D2(S,U,V,P,d1u,d1v,d2u,d2v,d2uv);
316       Norm = d1u.Crossed(d1v);
317       Dnu = d2u.Crossed(d1v) + d1u.Crossed(d2uv);
318       Dnv = d2uv.Crossed(d1v) + d1u.Crossed(d2v);
319     }
320     break;
321   }
322 }