# Circular order of edges around vertex

I'm trying to get a circular order of connected edges to a vertex.

From the bmesh module, we can have a BMEdgeSeq of linked edges to a vertex with the link_edges function. But the edges list is not ordered (in a circular way)

It is possible from the documentation of BMEdgeSeq to sort with a key, but, where are the possible key ?

Last solution, compute myself an angle between each edge to find a circular order (clockwise or not), but that seems heavy for meshes with a lot of vertices.

Any ideas ?

• Clockwise ? But As you might guess, ordering is not necessary for 3 edges and less... – minitoine Oct 16 '17 at 12:22
• Have you ever heard about Winged_edge Structure ? Edges are ordered.. Why are you talking about 12 o'clock ? I just need an order. For a cube, it can be 1,2,3 or 2,1,3, or 3,2,1 or 3,1,2, whatever. The important thing to have is to iterate over the edge in a circular way. Why are you talking about a cube ? It's a exception case. Edit: I added a picture, for you and your cube. – minitoine Oct 16 '17 at 12:40
• You have to have some point of reference,. From the winged edge wiki The ordering is such that the surfaces are ordered counter-clockwise with respect to the innate orientation of the intersection edge or using your wonderful images as a guide: The axis of your clock is -vert.normal project the edge vectors onto the plane defined by the normal (the face of the clock) and sort from arbitrary edge. Oh and yeah would only need 12 o'clock if first was needed. – batFINGER Oct 16 '17 at 13:09
• Which implies my last solution, that blender don't have this information and that we have to compute it. But a plane projection for each vertex for each vertex edges is very heavy. I am disappointed that such a tool like Blender doesn't give this kind of information. Thx, anyway. – minitoine Oct 16 '17 at 13:14
• Have a look at BMLoops – batFINGER Oct 16 '17 at 14:34

Here what i've made for my problem. As pointed out, it uses bmesh and BMLoop structures to do it.

# Return edges around param vertex in counter-clockwise order
def connectedEdgesFromVertex_CCW(vertex):

edges_CCW_order = []

edge = first_edge
while edge not in edges_CCW_order:
edges_CCW_order.append(edge)
edge = rightEdgeForEdgeRegardToVertex(edge, vertex)

return edges_CCW_order

# Return the right edge of param edge regard to param vertex
def rightEdgeForEdgeRegardToVertex(edge, vertex):
right_loop = None

for loop in edge.link_loops:
if loop.vert == vertex:
right_loop = loop
break