Normal of face

TLohi

CAD practitioner
Hello, I am having some difficulties to get normal of face out correctly.
I select face and calculate it normal using function:
Code:
inline void getPlaneNormal(const TopoDS_Face fc, gp_Dir &face_normal, gp_Pnt &pntCenter)
{
    if (fc.IsNull()) return false;

    BRepAdaptor_Surface surf(fc);
    ShapeAnalysis_Surface sas(surf.Surface().Surface());

    GProp_GProps props = GProp_GProps();
    BRepGProp::LinearProperties(fc,props);

    pntCenter = props.CentreOfMass();

    gp_Pnt2d uv = sas.ValueOfUV(pntCenter, 0.1).Coord();

    GeomLProp_SLProps curvature(surf.Surface().Surface(), uv.X(), uv.Y(), 1, 1e-6);

    face_normal = curvature.Normal();
}
Here is picture where normals are displayed
1672927284294.png

Analysis situs seems to calculate normals right way, but I can't find function that calculates normals from source code.

Any idea how to fix this or better way to calculate normal?

STEP file of model included, if it is helpful model is assembly that is created and STEP exported from SolidWorks

-TLohi
 

Attachments

  • screw_asm.STEP
    70 KB · Views: 1

Jonathan

CAD community veteran
I used this

Handle(Geom_Surface) faceGeo = BRep_Tool::Surface(TopoDS::Face(Face));
if (faceGeo.IsNull()) return result;

Standard_Real domainU, domainV = 0;

faceGeo->D1(U, V, result, U1, V1);

gp_Vec n = U1.Crossed(V1);

if (face.Orientation() == TopAbs_REVERSED) {
n.Reverse();
}
 
Top