# Divide plane into non convex regions

## Recommended Posts

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.

##### Share on other sites
```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);
px [i] = p.x;
}

int sort_pts[] = argsort(px);
//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);
}

values[nvtx] = values[0];

for (int i;i<chi("npt");i++){
sample_pos = rand(i+ch("seed"));
append(samples,sample_pos);
}
int sort_pts[] = argsort(samples);
```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);
}

values[nvtx]= values[0];

for (int i;i<4;i++){
sample_pos = rand(i,prim+ch("seed")+iteration);
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);

int poly1[] = sort_pts[:vtx0+1];
insert(poly1,0,sort_pts[vtx1:]);
removeprim(0,prim,1);
```

## Create an account

Register a new account