Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5817

What is the easiest way to know the minimal distance between 2 mesh (Objects .stl)?

$
0
0

@davedufour1991 wrote:

Hi!

So i will start with the code i use to do it :

            # Save mesh so we can calculate the smallest distance
            mesh_obj = rs.coercemesh(CurentObj)
            vertices = mesh_obj.Vertices
            normals = mesh_obj.Normals   
            
            # Go through all the points and mesure the smallest distance to the mesh
            for index, vertex in enumerate(vertices): #
                
                ClosestPoint=rs.MeshClosestPoint(Lastobj,[vertex.X,vertex.Y,vertex.Z])
                
                PointDistance=rs.Distance(ClosestPoint[0],[vertex.X,vertex.Y,vertex.Z])
                
                if  PointDistance <  SmallestDistance : #store the good value
                    SmallestDistance = PointDistance
                    GoodIndex=index
                    CurentObjPoints=[vertex.X,vertex.Y,vertex.Z]
                    LastObjPoints=ClosestPoint[0] 

I will now explain why are we doing that. We are importing multiples .STL files and we want to optimize the printing volume. To do so, we check the distance between the two observed objects and we move them to the minimal distance we can due to the printer tolerance.

Doing it that way, with this code, take time and i wanted to know if there was another function or others way to do it faster and more efficiently. We did that with V5, but we have access to V6 now.

Thank you for your help!

  -Dave

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 5817

Trending Articles