1 // Created on: 1995-02-24
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-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.
19 //=======================================================================
22 //=======================================================================
24 void Contap_SurfProps::Normale(const TheSurface& S,
25 const Standard_Real U,
26 const Standard_Real V,
31 GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(S);
35 gp_Pln pl(TheSurfaceTool::Plane(S));
36 Norm = pl.Axis().Direction();
37 P = ElSLib::Value(U,V,pl);
47 gp_Sphere sp(TheSurfaceTool::Sphere(S));
48 P = ElSLib::Value(U,V,sp);
49 Norm = gp_Vec(sp.Location(),P);
51 Norm.Divide(sp.Radius());
54 Norm.Divide(-sp.Radius());
59 case GeomAbs_Cylinder:
61 gp_Cylinder cy(TheSurfaceTool::Cylinder(S));
62 P = ElSLib::Value(U,V,cy);
63 Norm.SetLinearForm(Cos(U),cy.XAxis().Direction(),
64 Sin(U),cy.YAxis().Direction());
74 gp_Cone co(TheSurfaceTool::Cone(S));
75 P = ElSLib::Value(U,V,co);
76 Standard_Real Angle = co.SemiAngle();
77 Standard_Real Sina = sin(Angle);
78 Standard_Real Cosa = cos(Angle);
79 Standard_Real Rad = co.RefRadius();
81 Standard_Real Vcalc = V;
82 if (Abs(V*Sina + Rad) <= 1e-12) { // on est a l`apex
84 Standard_Real Vfi = TheSurfaceTool::FirstVParameter(S);
85 if (Vfi < -Rad/Sina) { // partie valide pour V < Vapex
96 if (Rad + Vcalc*Sina < 0.) {
97 Norm.SetLinearForm(Sina, co.Axis().Direction(),
98 Cosa*cos(U),co.XAxis().Direction(),
99 Cosa*sin(U),co.YAxis().Direction());
102 Norm.SetLinearForm(-Sina, co.Axis().Direction(),
103 Cosa*cos(U),co.XAxis().Direction(),
104 Cosa*sin(U),co.YAxis().Direction());
114 TheSurfaceTool::D1(S,U,V,P,d1u,d1v);
115 Norm = d1u.Crossed(d1v);
124 //=======================================================================
125 //function : DerivAndNorm
127 //=======================================================================
129 void Contap_SurfProps::DerivAndNorm(const TheSurface& S,
130 const Standard_Real U,
131 const Standard_Real V,
138 GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(S);
142 gp_Pln pl(TheSurfaceTool::Plane(S));
143 Norm = pl.Axis().Direction();
144 ElSLib::D1(U,V,pl,P,d1u,d1v);
154 gp_Sphere sp(TheSurfaceTool::Sphere(S));
155 ElSLib::D1(U,V,sp,P,d1u,d1v);
156 Norm = gp_Vec(sp.Location(),P);
158 Norm.Divide(sp.Radius());
161 Norm.Divide(-sp.Radius());
166 case GeomAbs_Cylinder:
168 gp_Cylinder cy(TheSurfaceTool::Cylinder(S));
169 ElSLib::D1(U,V,cy,P,d1u,d1v);
170 Norm.SetLinearForm(Cos(U),cy.XAxis().Direction(),
171 Sin(U),cy.YAxis().Direction());
181 gp_Cone co(TheSurfaceTool::Cone(S));
182 ElSLib::D1(U,V,co,P,d1u,d1v);
183 Standard_Real Angle = co.SemiAngle();
184 Standard_Real Sina = Sin(Angle);
185 Standard_Real Cosa = Cos(Angle);
186 Standard_Real Rad = co.RefRadius();
188 Standard_Real Vcalc = V;
189 if (Abs(V*Sina + Rad) <= RealEpsilon()) { // on est a l`apex
190 Standard_Real Vfi = TheSurfaceTool::FirstVParameter(S);
191 if (Vfi < -Rad/Sina) { // partie valide pour V < Vapex
199 if (Rad + Vcalc*Sina < 0.) {
200 Norm.SetLinearForm(Sina, co.Axis().Direction(),
201 Cosa*Cos(U),co.XAxis().Direction(),
202 Cosa*Sin(U),co.YAxis().Direction());
205 Norm.SetLinearForm(-Sina, co.Axis().Direction(),
206 Cosa*Cos(U),co.XAxis().Direction(),
207 Cosa*Sin(U),co.YAxis().Direction());
216 TheSurfaceTool::D1(S,U,V,P,d1u,d1v);
217 Norm = d1u.Crossed(d1v);
224 //=======================================================================
225 //function : NormAndDn
227 //=======================================================================
229 void Contap_SurfProps::NormAndDn(const TheSurface& S,
230 const Standard_Real U,
231 const Standard_Real V,
238 GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(S);
242 gp_Pln pl(TheSurfaceTool::Plane(S));
243 P = ElSLib::Value(U,V,pl);
244 Norm = pl.Axis().Direction();
248 Dnu = Dnv = gp_Vec(0.,0.,0.);
254 gp_Sphere sp(TheSurfaceTool::Sphere(S));
255 ElSLib::D1(U,V,sp,P,Dnu,Dnv);
256 Norm = gp_Vec(sp.Location(),P);
257 Standard_Real Rad = sp.Radius();
267 case GeomAbs_Cylinder:
269 gp_Cylinder cy(TheSurfaceTool::Cylinder(S));
270 P = ElSLib::Value(U,V,cy);
271 Norm.SetLinearForm(Cos(U),cy.XAxis().Direction(),
272 Sin(U),cy.YAxis().Direction());
273 Dnu.SetLinearForm(-Sin(U),cy.XAxis().Direction(),
274 Cos(U),cy.YAxis().Direction());
279 Dnv = gp_Vec(0.,0.,0.);
286 gp_Cone co(TheSurfaceTool::Cone(S));
287 P = ElSLib::Value(U,V,co);
288 Standard_Real Angle = co.SemiAngle();
289 Standard_Real Sina = Sin(Angle);
290 Standard_Real Cosa = Cos(Angle);
291 Standard_Real Rad = co.RefRadius();
292 Standard_Real Vcalc = V;
293 if (Abs(V*Sina + Rad) <= RealEpsilon()) { // on est a l`apex
294 Standard_Real Vfi = TheSurfaceTool::FirstVParameter(S);
295 if (Vfi < -Rad/Sina) { // partie valide pour V < Vapex
303 if (Rad + Vcalc*Sina < 0.) {
304 Norm.SetLinearForm(Sina, co.Axis().Direction(),
305 Cosa*Cos(U),co.XAxis().Direction(),
306 Cosa*Sin(U),co.YAxis().Direction());
309 Norm.SetLinearForm(-Sina, co.Axis().Direction(),
310 Cosa*Cos(U),co.XAxis().Direction(),
311 Cosa*Sin(U),co.YAxis().Direction());
313 Dnu.SetLinearForm(-Cosa*Sin(U),co.XAxis().Direction(),
314 Cosa*Cos(U),co.YAxis().Direction());
319 Dnv = gp_Vec(0.,0.,0.);
325 gp_Vec d1u,d1v,d2u,d2v,d2uv;
326 TheSurfaceTool::D2(S,U,V,P,d1u,d1v,d2u,d2v,d2uv);
327 Norm = d1u.Crossed(d1v);
328 Dnu = d2u.Crossed(d1v) + d1u.Crossed(d2uv);
329 Dnv = d2uv.Crossed(d1v) + d1u.Crossed(d2v);