简体   繁体   中英

average of normals for 3d model/stl file

I am trying to convert a faceted model/stl file to a solid model. The approach that I am currently taking is to extract the normal vector and/or plane equation for each facet/triangle face and take their dot product.

If the dot product is 1 or close to 1 then the normals are pointing in the same direction and so I will take the average of them. The goal is to take say 10,000 normal vectors/plane equations for each facet, compare them with each other via the dot product, and then output say 10 normal vector/10 plane equations that approximate the facet model.

What would be a good data structure for comparing multiple normal vectors for a faceted model/STL file?

I am looking into octrees/rtrees but I do not have much experience with them. I have also considered using a MapReduce approach with the Disco library.

The approach below could work fine for a small number of facets (50) but once you get to 1,000 it becomes a challenge

# 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]) 

您是否检查过该库?: numpy-stl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM