How to get the normal direction of a gp_Pln object?

Hi,

How to get the normal direction of a gp_Pln object? My code follows below:

if (m_FirstShape.ShapeType() == TopAbs_FACE)
{
TopoDS_Face faceShape = TopoDS::Face(m_FirstShape);
Handle_Geom_Surface surface = BRep_Tool::Surface(faceShape);
Handle(Geom_Plane) pln = Handle(Geom_Plane)::DownCast(surface);
return pln->Pln().Axis().Direction();
}

But the result is not correct,why?

Thanks in advance!

Paul Jimenez's picture

My guess is that when you say "the result is not correct" you mean sometimes it's pointing to the opposite direction. To know when to flip the normal, check the Orientation of the Face. If it's TopAbs_REVERSED, flip the plane's Direction.

zhangzhigang824's picture

Hi Paul,

Thank you for you reply, and you answer is just right.
My revised code is:

if (m_FirstShape.ShapeType() == TopAbs_FACE)
{
TopoDS_Face faceShape = TopoDS::Face(m_FirstShape);
Handle_Geom_Surface surface = BRep_Tool::Surface(faceShape);
Handle(Geom_Plane) pln = Handle(Geom_Plane)::DownCast(surface);
if (m_FirstShape.Orientation() == TopAbs_REVERSED)
{
return pln->Pln().Axis().Direction().Reversed();
}
return pln->Pln().Axis().Direction();
}

Thanks again!