BRepLProp_SLProps give me wrong normal

Hi,
I found a lot a cases for which BRepLProp_SLProps returns wrong normal to surface.

Someone can explain me why? Is there a bug in OCC?

I put an example image http://www.enormis.it/forum/normals.gif

The code to reproduce the situation is

TColgp_Array2OfPnt array2(1,5,1,4);
array2.SetValue(1,1,gp_Pnt(0,2000,600));
array2.SetValue(1,2,gp_Pnt(0,1000,400));
array2.SetValue(1,3,gp_Pnt(0,0,200));
array2.SetValue(1,4,gp_Pnt(0,-500,0));
array2.SetValue(2,1,gp_Pnt(1000,1500,400));
array2.SetValue(2,2,gp_Pnt(1000,1000,300));
array2.SetValue(2,3,gp_Pnt(1000,500,200));
array2.SetValue(2,4,gp_Pnt(1000,0,100));
array2.SetValue(3,1,gp_Pnt(2500,3000,300));
array2.SetValue(3,2,gp_Pnt(2500,2000,600));
array2.SetValue(3,3,gp_Pnt(2500,0,0));
array2.SetValue(3,4,gp_Pnt(2500,-1000,300));
array2.SetValue(4,1,gp_Pnt(4000,1500,100));
array2.SetValue(4,2,gp_Pnt(4000,1000,200));
array2.SetValue(4,3,gp_Pnt(4000,500,300));
array2.SetValue(4,4,gp_Pnt(4000,0,400));
array2.SetValue(5,1,gp_Pnt(5000,2000,0));
array2.SetValue(5,2,gp_Pnt(5000,1000,200));
array2.SetValue(5,3,gp_Pnt(5000,0,400));
array2.SetValue(5,4,gp_Pnt(5000,-500,600));
Handle (Geom_BSplineSurface) BSplineSurf = GeomAPI_PointsToBSplineSurface(array2,3,8,GeomAbs_C2,0.001);
TopoDS_Face aFace = BRepBuilderAPI_MakeFace(BSplineSurf);
Handle(AIS_Shape) anAISShape=new AIS_Shape(aFace);
myAISContext->Display(anAISShape, Standard_False);
myAISContext->SetMaterial(anAISShape, Graphic3d_NOM_ALUMINIUM, Standard_False);
myAISContext->SetTransparency(anAISShape, 0.4, Standard_False);
myAISContext->SetDisplayMode(anAISShape, Standard_True);
fitAll();
//
GProp_GProps system;
BRepGProp::SurfaceProperties(aFace, system);
gp_Pnt centro = system.CentreOfMass();
//
BRepAdaptor_Surface adaptorSurface(aFace);
Standard_Real u, v;
GeomLib_Tool::Parameters(BSplineSurf, centro, Precision::Confusion(), u, v);
BRepLProp_SLProps props(adaptorSurface, u, v, 2, Precision::Confusion());
gp_Dir normalePianoTaglio;
//props.TangentU(normalePianoTaglio);
props.TangentV(normalePianoTaglio);
gp_Ax1 asseNormale(centro, props.Normal());
Handle(Geom_Plane) pianoTaglio = new Geom_Plane(centro, normalePianoTaglio);
GeomAPI_IntSS intersector(BSplineSurf, pianoTaglio, Precision::Confusion());
Handle(Geom_Curve) curva = intersector.Line(1);
BRepAdaptor_Curve adaptorCurve(BRepBuilderAPI_MakeEdge(curva).Edge());
GCPnts_UniformDeflection algo(adaptorCurve, 1, Precision::Confusion(), true);
gp_Pnt point;
gp_Dir normale;
for (int index = 1; index {
point = algo.Value(index);
GeomLib_Tool::Parameters(BSplineSurf, point, Precision::Confusion(), u, v);
BRepLProp_SLProps props(adaptorSurface, u, v, 2, Precision::Confusion());
normale = props.Normal();
myAISContext->Display( new AIS_Point( new Geom_CartesianPoint( point) ) );
myAISContext->Display( new AIS_Line( new Geom_Line( point, normale )) );
}

Marco Matt's picture

I did some more investigation.
When the normal is wrong, also the directions of the first derivate for both U and V are wrong, but perpendicular to the wrong normal.