Voronoi diagram: Difference between revisions

(Updated D entry)
Line 624:
 
=={{header|J}}==
 
=== Explicit version ===
 
A straightforward solution: generate random points and for each pixel find the index of the least distance. Note that the square root is avoided to improve performance.
<lang j>NB. (number of points) voronoi (shape)
Line 631 ⟶ 634:
(i.<./)@:(+/@:*:@:-"1&p)"1 ,"0/&i./ y
)
 
load'viewmat'
viewmat 25 voronoi 500 500</lang>
 
Another solution generates Voronoi cells from Delaunay triangulation. The page [[Voronoi diagram/J/Delaunay triangulation]] also contains a convex hull algorithm.
 
=== Tacit version ===
 
This a direct reformulation of the explicit version.
 
<lang j>Voronoi=. ,"0/&i./@:] (i. <./)@:(+/@:*:@:-"1)"1 _ ] ?.@$~ 2 ,~ [</lang>
 
=={{header|Liberty BASIC}}==
Anonymous user