POV-Ray : Newsgroups : povray.text.scene-files : Voronoi cell polygon macro Server Time
31 Oct 2024 19:44:01 EDT (-0400)
  Voronoi cell polygon macro (Message 1 to 2 of 2)  
From: Bill Pragnell
Subject: Voronoi cell polygon macro
Date: 24 Nov 2022 19:25:00
Message: <web.63800ad9a4dfc19bb96893c06f35e431@news.povray.org>
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)

From: Bill Pragnell
Subject: Re: Voronoi cell polygon macro
Date: 24 Nov 2022 19:35:00
Message: <web.63800c97102ee226b96893c06f35e431@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.