# Node re-numbering in 1D mesh GMSH

I'm working with Gmsh to generate 1D meshes of polygon edges. I have noticed that drawing a polygon by "vertices and lines" the program always assigns to the first N nodes of the mesh the coordinates of the N vertices of the polygon; all the other nodes instead are ordered clockwise. Is there a way to order all the nodes clockwise, including the vertices?

Thanks.

I'm not aware of any way to do this in a .geo file, under the GMSH application, or using the libgmsh interfaces. Somewhat annoyingly, the last operation gmsh does before a write tends to be a renumbering to sweep over 0D, 1D, 2D, and 3D objects sequentially. There has been some work on renumbering options recently, but it's targeted renumbering to make the indices dense rather than to allow other options.

On the other hand, the GMSH msh formats are very well documented and the ASCII text based ones are very easy to parse and rewrite. For what you want to do, the algorithm would go:

• parse the file once, storing an array of node values, and the element-node mappings.
• find the angles of each node from the centre of your polygon.
• Generate an integer array of the ordered node indices
• output a new file, outputting the node list in the new order and applying your index mapping to the element list.

This isn't totally trivial, but if you know a scripting language, wouldn't take forever to write.

• Done it thanks! A problem remains. In order to get the angle I need an inner point inside the polygon. Rightnow I choose the arithmethic mean between the polygon vertices but it is not that robust. In fact, if the polygon is not convex, the mean point can not belong to the polygon. How to choose a point that is always inside? Feb 15, 2019 at 17:28
• @JohnSnow If your polygon isn't convex, then the safest option is to "walk the mesh" when building your ordering. i.e start at a node, find an edge containing it and move to the other node on that edge, then delete the edge from your search list. This does leave the question of what clockwise means on such shapes though. Feb 15, 2019 at 18:21
• Not that easily implemented. I will try it. If you have some references or suggestion you will be very kind. I meanly work in fortran90 but also c/c++ is not a problem. Thanks Feb 15, 2019 at 18:31