|
|
Following threads in p.b.images, here's a more generically-useful version of my
Voronoi cells.
It's a macro that produces an array of Voronoi polygons in the x-z plane given
an input array of seed points. Each polygon is stored as a list of vertices, so
each element in the output array is itself an array of points (NOT a 2D array!).
The macro also removes collinear points, so each polygon might not be the same
size (use dimension_size to find the number of vertices for each polygon).
Also included is my util macro for shrinking a partly-assigned array.
Bill
Post a reply to this message
Attachments:
Download 'voronoi.inc.txt' (3 KB)
|
|
|
|
Example usage:
#declare Sd = seed(0);
#declare N = 250;
#declare Points = array[N];
#for (I, 0, N-1)
#declare Points[I] = <rand(Sd)*20-10, 0, rand(Sd)*20-10>;
#end
#declare Cells = array[1];
VoronoiCells(Points, Cells)
#for (I, 0, N-1)
#declare NC = dimension_size(Cells[I], 1);
#if (NC > 2)
prism {
0, rand(Sd)*4 + 1,
NC+1,
#for (J, 0, NC-1)
<Cells[I][J].x, Cells[I][J].z>,
#end
<Cells[I][0].x, Cells[I][0].z>
pigment { rgb <rand(Sd)*0.5+0.5, rand(Sd)*0.5+0.5, rand(Sd)*0.5+0.5> }
finish { ambient 0 }
}
#end
#end
Post a reply to this message
|
|