# Producing Delaunay Triangulations

Does anyone know how I can produce 2D Delaunay Triangulations in tikz by giving as inputs a list of randomly generated points? Or at least a program that takes that list and produces tikz output.

One way of doing it is by following this route: asy => svg => TikZ.

This d.asy code from the Asymptote docs creates random points and builds a triangulation:

size(200);
int np=12;
pair[] points;
real r() {return 1.2*(rand()/randMax*2-1);}

srand(1234321);
for(int i=0; i < np; ++i) points.push((r(),r()));

int[][] trn=triangulate(points);
for(int i=0; i < trn.length; ++i) {
draw(points[trn[i][0]]--points[trn[i][1]]);
draw(points[trn[i][2]]--points[trn[i][2]]);
draw(points[trn[i][2]]--points[trn[i][0]]);
}
for(int i=0; i < np; ++i) dot(points[i],red);


Generate d.svg output with a command:

asy -f svg d.asy


then convert it to TikZ with svg2tikz:

svg2tikz --standalone d.svg > d.tex


Resulting d.tex file looks like this:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}
\definecolor{cff0000}{RGB}{255,0,0}

\begin{tikzpicture}[y=0.80pt,x=0.80pt,yscale=-1, inner sep=0pt, outer sep=0pt]
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (39.9691,-90.7908) -- (43.3652,-100.6640);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (43.3652,-100.6640) -- (98.7641,-39.0366);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (98.7641,-39.0366) -- (39.9691,-90.7908);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (80.9286,65.0406) -- (-16.1836,36.7579);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-16.1836,36.7579) -- (98.7641,-39.0366);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (98.7641,-39.0366) -- (80.9286,65.0406);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-16.1836,36.7579) -- (39.9691,-90.7908);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (39.9691,-90.7908) -- (98.7641,-39.0366);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (98.7641,-39.0366) -- (-16.1836,36.7579);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-43.1652,96.4547) -- (-16.1836,36.7579);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-16.1836,36.7579) -- (35.5692,80.1023);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (35.5692,80.1023) -- (-43.1652,96.4547);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-98.9747,37.4920) -- (-48.7898,13.8156);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-48.7898,13.8156) -- (-43.1652,96.4547);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-43.1652,96.4547) -- (-98.9747,37.4920);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-78.9290,-89.2327) -- (-49.1180,-92.8069);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-49.1180,-92.8069) -- (-48.7898,13.8156);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-48.7898,13.8156) -- (-78.9290,-89.2327);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-98.9747,37.4920) -- (-78.9290,-89.2327);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-78.9290,-89.2327) -- (-48.7898,13.8156);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-48.7898,13.8156) -- (-98.9747,37.4920);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (77.7164,83.1456) -- (35.5692,80.1023);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (35.5692,80.1023) -- (80.9286,65.0406);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (80.9286,65.0406) -- (77.7164,83.1456);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (35.5692,80.1023) -- (-16.1836,36.7579);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-16.1836,36.7579) -- (80.9286,65.0406);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (80.9286,65.0406) -- (35.5692,80.1023);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-43.1652,96.4547) -- (-48.7898,13.8156);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-48.7898,13.8156) -- (-16.1836,36.7579);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-16.1836,36.7579) -- (-43.1652,96.4547);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (39.9691,-90.7908) -- (-49.1180,-92.8069);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-49.1180,-92.8069) -- (43.3652,-100.6640);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (43.3652,-100.6640) -- (39.9691,-90.7908);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-43.1652,96.4547) -- (35.5692,80.1023);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (35.5692,80.1023) -- (77.7164,83.1456);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (77.7164,83.1456) -- (-43.1652,96.4547);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-16.1836,36.7579) -- (-48.7898,13.8156);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-48.7898,13.8156) -- (39.9691,-90.7908);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (39.9691,-90.7908) -- (-16.1836,36.7579);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-48.7898,13.8156) -- (-49.1180,-92.8069);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (-49.1180,-92.8069) -- (39.9691,-90.7908);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[draw=black,line join=round,line cap=round,miter limit=10.04,line
width=0.401pt] (39.9691,-90.7908) -- (-48.7898,13.8156);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (43.3652,-100.6640) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (35.5692,80.1023) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (80.9286,65.0406) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (-49.1180,-92.8069) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (77.7164,83.1456) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (-78.9290,-89.2327) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (39.9691,-90.7908) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (-48.7898,13.8156) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (98.7641,-39.0366) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (-43.1652,96.4547) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (-98.9747,37.4920) circle (0.0425cm);
\end{scope}
\begin{scope}[cm={{1.0,0.0,0.0,1.0,(157.101,156.23)}}]
\path[fill=cff0000] (-16.1836,36.7579) circle (0.0425cm);
\end{scope}

\end{tikzpicture}
\end{document}


Processing it as usual: pdflatex d.tex gives the output: