Finding and sorting uppermost vertices of a concave mesh

This is probably an @Bunny83 question but if anyone else has insight I’d appreciate it:

I have put together a system where I take a given 3D mesh and I grab all the vertices along the exterior and top of the mesh (i.e. if you have a box mesh it would pick up the top four verts). Currently I do this by using @Bunny83’s edge detection method (Get Outer/Edge Vertices C# - Questions & Answers - Unity Discussions) to grab all exterior verts, then simply delete any vertices not at the very top of the mesh.

This works fine for a convex mesh because sorting the remaining verts is easy: simply sort them by their angle around the centroid. However this won’t work for a concave mesh.

The obvious solution is to modify the SortEdges() method on the edge detection script to strip out the lower verts while maintain the proper sort order but no matter what I do, I can’t quite seem to get it.

Just a heads-up that Bunny83’s edge detection code (Get Outer/Edge Vertices C# - Questions & Answers - Unity Discussions) actually does everything I needed, there was just a minor bug in the code. I’ve posted my bugfix on the initial thread.