Uniformly spaced circle mesh has some artifacts (python)

Hi All,
want to create a circle mesh in Python to create uniformly spaced mesh (so no polar mesh), but currently mesh has some visual artifacts cause by how the vertices are distributed (where the triangles switch direction). Any pointers where i am missing the logic? I am bound to using python math or numpy, as libraries like trimesh for some reason won’t install on my system. I am not looking for a rhino/gh unique method as I want to share the code

def circle_points(radii, num_points_per_circle):
    circles = []
    for r, n in zip(radii, num_points_per_circle):
        t = np.linspace(0, 2 * np.pi, n, endpoint=False)
        x = r * np.cos(t)
        y = r * np.sin(t)
        circles.append(np.c_[x, y])
    return np.vstack(circles)

I attach the full code
start_mesh.gh (6.9 KB)

so something more like this source image online:
image

Hello
Generate triangulated vertices and keep the ones that are inside a circle slightly little than the one you want, then generate point outsides, use Delaunay to have the mesh. Then apply some relaxation on the mesh (the difficult part).

Here is the Grasshopper demonstration.
you could use Triangular to have the inner points

Then use a circle to have the outer points

Then relax using Kangaroo


mesh disk triangle Kangaroo.gh (20.0 KB)

Hi Laurent elegant solution thanks.

I’ll see if i can replicate this and port this to python. My goal is to make a version that doesn’t reply on gh and can run as jupyiter notebook.

For this i have available: NumPy, SciPy (scipy.spatial import Voronoi, Delaunay) and
from Shapely stuff like .geometry import Point, Polygon

explains why I had to copy past the picture from a paper :wink:

I am not a Python guy so I don’t know were will be the constrain but if you can do the mesh half job is done. Relaxation will imply the need to have topology in order to calculate the “forces” on point.
A vector on each point will be calculated knowing the neighbors. You also have to know the naked points (they don’t move).
Here finishes what I can do. But there are lots Python masters.

here is a link with a small algorithm to smooth mesh, it is C# but if Python mesh has similar method it will be simple to implement.

And for the record, C# smoothing could be improved if not using Mesh connectivity in each loop but precalculating it before the looping.
From 756 ms to 59 ms or 2.3 s to 173 ms (X13 improvement)


  M.Vertices.CombineIdentical(true, true);
    M.Vertices.UseDoublePrecisionVertices = true;

    Mesh M2 = M.DuplicateMesh();

    Point3d[] newVerts = new Point3d[M.Vertices.Count];
    bool[] locked = new bool[M.Vertices.Count];

    int[][] tab_tab_neighbourIndices = new int[M2.Vertices.Count][];
    for(int i = 0;i < M2.Vertices.Count;i++)
    {
      tab_tab_neighbourIndices[i] = M2.Vertices.GetConnectedVertices(i);
    }

    foreach (int i in y)
      locked[i] = true;

    for(int iter = 0; iter < iters;iter++)
    {
      for(int i = 0;i < M2.Vertices.Count;i++)
      {
        if(locked[i])
          newVerts[i] = M2.Vertices[i];
        else
        {
          Point3d avg = new Point3d();
          for(int j = 0;j < tab_tab_neighbourIndices[i].Length;j++)
          {
            avg = avg + M2.Vertices[tab_tab_neighbourIndices[i][j]];
          }
          avg = avg / tab_tab_neighbourIndices[i].Length;
          newVerts[i] = avg;
        }

      }
      for(int i = 0;i < M2.Vertices.Count;i++)
      {
        M2.Vertices.SetVertex(i, newVerts[i]);
      }
    }

    A = M2;
1 Like