有人知道我如何通过输入随机生成的点列表在 tikz 中生成 2D Delaunay 三角剖分吗?或者至少有一个程序可以获取该列表并生成 tikz 输出。
答案1
其中一种方法是按照这个路线:asy
=> svg
=> TikZ
。
文档中的这段d.asy
代码Asymptote
创建了随机点并建立了三角测量:
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);
d.svg
使用命令生成输出:
asy -f svg d.asy
然后将其转换TikZ
为svg2tikz:
svg2tikz --standalone d.svg > d.tex
生成的d.tex
文件如下所示:
\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}
照常处理:pdflatex d.tex
给出输出: