algorithmic modeling for Rhino
I am trying to sort vertices of surface in clockwise order. I observed that for fresh geometry, brep.DuplicateVertices() provides a list of vertices in some order only. And that is acceptable to me.
However, for surfaces derived from some splitting operation in Rhino, the vertices are not provided in order (Clockwise or counter-clockwise).
Is there a simple way to do that? I read this discussion. But I am not sure if the centroid approach would work for a case like image below.
I am trying to do this using Python, but C# or a pseudo code will work too.
Yeah it is pain in the ass to do this, I was trying to find method to unify mesh windings similarly as weaverbird does.https://gamedev.stackexchange.com/questions/30537/how-to-determine-...
However if you are limited to 1 polyline only.
For meshes I used this approach
You could do is
Mesh.GetNakedEdgePointStatus() to get all the vertices’ (not topology vertices!) naked edge statuses. Then start at one vertex and enumerate all edges that radiate from that vertex. Take the edge that has a naked opposite vertex and keep going from that vertex until you reach the beginning.
The same logic can be applied to breps.
You can apply graph method, but I believe just looping thought edges with its adjacency is a straight forward process.
nice to see you are back!
Here's the method I usually use for this (as you can see, for concave polygons the center point approach is indeed sensitive, so you may need to come up with a heuristic to deal with your specific case):
Edit: This concave hull approach might also fit your needs.
EditII: I think I might have misunderstood the problem, my bad, more coffee :)
Concave hull example is really nice.
Thank you, Petras and Anders for prompt responses. I am looking into what you both shared. Will post back where I end up. Appreciate the support.
Hi Devang, could a gh definition pass as pseudo code too? In the example I Also cut a hole in the (already trimmed) surface:
If you start writing a script I would duplicate the BrepLoops (not available through vanilla gh), and sort the verts along those: they'll be sorted CCW for the outerloops, and CW for the innerloops (note: reverse of what you asked for). I think that's the 'safest' approach.
Although I am trying to do this in Python, your example is a great help. I will try to mimic this logic in Python. Will post how it turns out.
Thanks a lot!
Maybe I am missing a point, but:
1. If you have a surface you can take the naked edges and join them.
2. You can take the first two lines as vector and compute the cross product.
3. Then check if the resulting Vector looks up or down e.g. computing the dot product against Z
4. resort all down or up vectors -> resulting points are all sorted clockwise or counterclockwise...
This works as long as you have a direction Z....