Voronoi diagram: Difference between revisions

Content added Content deleted
(Updated D entry)
Line 624: Line 624:


=={{header|J}}==
=={{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.
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)
<lang j>NB. (number of points) voronoi (shape)
Line 631: Line 634:
(i.<./)@:(+/@:*:@:-"1&p)"1 ,"0/&i./ y
(i.<./)@:(+/@:*:@:-"1&p)"1 ,"0/&i./ y
)
)

load'viewmat'
viewmat 25 voronoi 500 500</lang>
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.
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}}==
=={{header|Liberty BASIC}}==