AntoineSfx Posted April 21, 2021 Share Posted April 21, 2021 Do you know a way to divide the plane into non convex, non overlapping regions ? Problem I'm trying to solve: given a grid and a set of points inside that grid, I would like to generate a set of curves / primitives that represent some region around that points as if the region has grown organically. I've has some success with Cluster, but the result is too clean, because in the end, it's doing something similar to a Voronoi diagram. Maybe there is something I could do after this to randomize the points on the borders. Quote Link to comment Share on other sites More sharing options...
Librarian Posted April 21, 2021 Share Posted April 21, 2021 vector p; int pts[]; float px[]; for(int i;i<ch("npt");i++){ p.x = rand(0.1*i+ch("seed")); p.y = rand(p.x); pts [i]= addpoint(0,p); px [i] = p.x; } int sort_pts[] = argsort(px); if(chi("argsort"))addprim(0,"polyline",sort_pts); else addprim(0,"polyline",pts); //int sort_pts[] = argsort(px); //sort_pts = reorder(pts,sort_pts); float sample_pos; float samples[]; vector values[]; int prim = 0; int pt; int nvtx = primvertexcount(1,prim); int pts[]; for(int vtx;vtx<nvtx;vtx++){ samples[vtx] = float(vtx)/primvertexcount(1,0); pt = vertexpoint(1,vertexindex(1,prim,vtx)); values[vtx] = point(1,"P",pt); pts[vtx] = addpoint(0,values[vtx]); } values[nvtx] = values[0]; for (int i;i<chi("npt");i++){ sample_pos = rand(i+ch("seed")); append(pts,addpoint(0,spline("linear",sample_pos,values))); append(samples,sample_pos); } int sort_pts[] = argsort(samples); addprim(0,"poly",sort_pts); float sample_pos; float samples[]; vector values[]; int iteration = detail(1,"iteration"); int prim = iteration; //int prim = 0; int pt; int nvtx = primvertexcount(0,prim); int pts []; for(int vtx;vtx<nvtx;vtx++){ samples[vtx]=float(vtx)/primvertexcount(0,prim); pt = vertexpoint(0,vertexindex(0,prim,vtx)); values[vtx] = point(0,"P",pt); pts[vtx] = addpoint(0,values[vtx]); } values[nvtx]= values[0]; for (int i;i<4;i++){ sample_pos = rand(i,prim+ch("seed")+iteration); append(pts,addpoint(0,spline("linear",sample_pos,values))); append(samples,sample_pos); } int sort_pts[] = argsort(samples); sort_pts = reorder(pts,sort_pts); int vtx0= int(ceil(samples[-2]*primvertexcount(0,prim))); int vtx1= int(ceil(samples[-1]*primvertexcount(0,prim))); if (vtx0>vtx1){ int t = vtx0; vtx0 = vtx1; vtx1 = t+1; }else{ vtx1+=1; } int poly0[] = sort_pts[vtx0:vtx1+1]; //poly0= slice(sort_pts,vtx0,vtx1+1); addprim(0,"poly",poly0); int poly1[] = sort_pts[:vtx0+1]; insert(poly1,0,sort_pts[vtx1:]); addprim(0,"poly",poly1); removeprim(0,prim,1); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.