我正在开发一个STL文件导入器,想利用给定的法线确定三角形的绕序。下面包含了4个三角形的示例数据(原始数据包含超过70k个三角形)。我的代码逻辑假设顶点是逆时针指定的,计算法线,然后将这个计算出来的法线与提供的法线进行点积运算。如果结果为正,则假设为逆时针,否则为顺时针。
tm.SetCCW(Dot(Cross(facet.getVertex2() - facet.getVertex1(),facet.getVertex3() - facet.getVertex1()),facet.getNormal()) > 0.0);
这个逻辑在某个3D扫描仪的一组文件上失败了。然而,当我将这些文件加载到Rhino3D中,并使用“Dir”查看法线方向时,Rhino的方向是正确的!我尝试了几个其他的STL查看器,也是一样的。
我的代码推断样本数据中的顶点按顺时针顺序提供,但是当使用该绕组顺序时,模型是内部反转的,这意味着提供的法线是错误的。
这让我得出结论,STL导入程序忽略提供的法线,并假设为逆时针绕组顺序。我正在寻找更有经验的STL文件格式人员,以确定我的假设是否正确。
solid object_name
facet normal -0.651094 0.733745 -0.194150
outer loop
vertex 30.335684 -40.893806 -68.126500
vertex 31.155055 -39.911656 -67.162500
vertex 30.263726 -40.702583 -67.162500
endloop
endfacet
facet normal -0.654292 0.732059 -0.189714
outer loop
vertex 30.335684 -40.893806 -68.126500
vertex 31.225185 -40.098797 -68.126500
vertex 31.155055 -39.911656 -67.162500
endloop
endfacet
facet normal -0.711866 0.677947 -0.183397
outer loop
vertex 31.225185 -40.098797 -68.126500
vertex 31.980540 -39.044870 -67.162500
vertex 31.155055 -39.911656 -67.162500
endloop
endfacet
facet normal -0.714326 0.676343 -0.179716
outer loop
vertex 31.225185 -40.098797 -68.126500
vertex 32.048799 -39.228928 -68.126500
vertex 31.980540 -39.044870 -67.162500
endloop
endfacet
endsolid
编辑:我对第一个方面的计算如下:
p1 = {30.335684, -40.893806, -68.126500}
p2 = {31.155055, -39.911656, -67.162500}
p3 = {30.263726, -40.702583, -67.162500}
u = p2 - p1 = {0.819371, 0.98215, 0.964}
w = p3 - p1 = {-0.071958, 0.191223, 0.964}
u x w = {0.762454, -0.859241, 0.227356} (calculated normal)
given normal = {-0.651094, 0.733745, -0.194150}
calculated_normal <dot> given_normal = -1.17103
verdict: 90 < theta < 270 where theta is the angle between the calculated and given normals