normal to topoDS_Face

Hi,
I want to compute the normal to a TopoDS_Face.
If somebody knows how to make it...
Thanks in advance
Sam

I do this:

Handle(Geom_Surface) Surf = BRep_Tool::Surface(currentFace);
edgeExplor.Init(currentFace,TopAbs_EDGE);
TopoDS_Edge E = TopoDS::Edge(edgeExplor.Current());
double first, last;
Handle(Geom2d_Curve) Curve = BRep_Tool::CurveOnSurface (E,currentFace,first,last);
gp_Pnt2d P2d;
Curve->D0(first,P2d);

GeomLProp_SLProps SLProps(Surf, 1, 0.1);

SLProps.SetParameters(P2d.X(), P2d.Y());

gp_Dir direc=SLProps.Normal();
Vec3 normal(direc.X(),direc.Y(),direc.Z());

TopAbs_Orientation orient = currentFace.Orientation();

if (orient==TopAbs_REVERSED )
// normal is oriented inside the shape ->reoriente it!
{
normal.set(0,-direc.X());
normal.set(1,-direc.Y());
normal.set(2,-direc.Z());
//std::cerr }

Benedicte Martin's picture

hi

it's very easy to compute the normal to a TopoDS_Face

TopoDS_Face aFace;
BRepAdaptor_Surface aSurface(aFace);
Standard_Real u1,u2,v1,v2;
u1 = aSurface.FirstUParameter();
u2 = aSurface.LastUParameter();
v1 = aSurface.FirstVParameter();
v2 = aSurface.LastVParameter();

gp_Pnt aCenterOfFace;
gp_Vec aVec1,aVec2,aNormalOfFace;

aSurface.D1((u1+u2)/2,(v1+v2)/2,aCenterOfFace,aVec1,aVec2);

aNormalOfFace = aVec1^aVec2;

peter kurnev's picture

Hi Sam.

I consider that you know 2D-point (on surface of the face) where yuor normal will be. So, try to use the code:
//=======================================
// foo
//=======================================
void foo(const gp_Pnt2d aP2D, // 2D-point
const TopoDS_Face& aF,// face
gp_Dir& DNS) // normal
{
gp_Pnt aP;
gp_Vec aD1U, aD1V;

const Handle(Geom_Surface)&aS=
BRep_Tool::Surface(aF);
aS->D1(aP2D.X(), aP2D.Y(), aP, aD1U, aD1V);

gp_Dir aDD1U(aD1U);
gp_Dir aDD1V(aD1V);
aDNS=aDD1U^aDD1V;
if (aF.Orientation()==TopAbs_REVERSED){
aDNS.Reverse();
}
}

Regards,
Peter

Jonathan Hill's picture

Hi Peter,

The function you posted above will do what I need, at the moment I have a 3D point which I get from GeomAPI_IntCS::Point(1), could you explain how I can get the 2D point of the surface.

Many Thanks
Jonathan

John Brown's picture

How about BOPTools_Tools3D::GetNormalToSurface()?

I'm computing normals on surface this way (from triangulation data).
You need surface, and UV position on surface:
//...
TopoDS_Face F = TopoDS::Face(ex.Current());
// Surface (face on this surface)
Handle (Geom_Surface) surface = BRep_Tool::Surface(F);
// Face orientation
TopAbs_Orientation faceOrientation = F.Orientation();
// Get triangulation
TopLoc_Location L;
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
const TColgp_Array1OfPnt2d & uvnodes = facing->UVNodes(); //UVs
//...
// now you have nodes, UVs in nodes, orientation and surface
:)