3d model / stl文件的法线平均值

时间:2016-03-22 19:09:00

标签: python vector stl 3d normals

我正在尝试将分面模型/ stl文件转换为实体模型。我目前采用的方法是提取每个面/三角面的法向量和/或平面方程,并取其点积。

如果点积为1或接近1,则法线指向相同的方向,因此我将取其平均值。目标是为每个方面取10,000个法向量/平面方程,通过点积进行相互比较,然后输出近似于小平面模型的10个法向量/ 10平面方程。

用于比较分面模型/ STL文件的多个法向量的良好数据结构是什么?

我正在研究octrees / rtrees,但我对它们没有多少经验。我还考虑过使用Disco库的MapReduce方法。

以下方法可以适用于少数方面(50),但一旦达到1,000就成了挑战

# if the planes are not coplanar
    #place sympy code here
    #plane_list.append(sp.Plane(sp.Point3D(temp_tuple[1][0][0],temp_tuple[1][0][1],temp_tuple[1][0][2]), sp.Point3D(temp_tuple[1][1][0],temp_tuple[1][1][1],temp_tuple[1][1][2]), sp.Point3D(temp_tuple[1][2][0],temp_tuple[1][2][1],temp_tuple[1][2][2])))

    #compare normals from each plane equation
    for j in range(len(normals_list)):
        print("Normal for plane equation " +str(j) + " is "+ str(normals_list[j]))


        for k in range(len(normals_list)):
            # 
            if j is not k: 
                temp_array1=np.array(normals_list[j])
                temp_array2=np.array(normals_list[k])


                #dot_product=np.dot(temp_array1, temp_array2)
                dot_product=np.vdot(temp_array1,temp_array2)
                print("The vector dot product for "+str(j)+" and "+str(k)+" is "+str(dot_product))
                unit_vectorj = np.sqrt(np.dot(temp_array1, temp_array1))

                unit_vectork = np.sqrt(np.dot(temp_array2, temp_array2))


                #if the normals point in approximately the same direction
                if float(dot_product)==1.0:
                    cntr+=1
                    print("The number of times is "+str(cntr))
                    mean_normals.append(normals_list[j]) 

1 个答案:

答案 0 :(得分:0)

你检查过这个图书馆吗?: numpy-stl