How to find the closest vertex on mesh according to a test point efficiently?

Hi,
I have many points and I wanna find the corresponding index of the closest topology vertex on the mesh of ever point. I don’t wanna use “DistanceTo” (I think it is very slow) and who has an efficient search method?
Albert
here are a picture and a 3dm file.


Closest Vertex.3dm (564.8 KB)

This should be fast:

    private static int[] ClosestVerticeId(Mesh mesh, List<Point3d> points)
    {
        PointCloud meshPtCloud = new PointCloud(mesh.Vertices.Select(v => (Point3d)v));
        int[] closestVerticeId = new int[points.Count];
        for (int i = 0; i < points.Count; i++)            
            closestVerticeId[i] = meshPtCloud.ClosestPoint(points[i]);            
        return closestVerticeId;
    }
1 Like

Thanks soooo much.