1 % luamesh: compute and draw meshes with lua, luamplib and tikz
3 % Originally written by Maxime Chupin <mc@melusine.eu.org>,
6 % Distributed under the terms of the GNU free documentation licence:
7 % http://www.gnu.org/licenses/fdl.html
8 % without any invariant section or cover text.
10 \documentclass{lltxdoc
}
11 \usepackage{tcolorbox
}
13 \usepackage[tikz
]{bclogo
}
17 \title{\Verb+luamesh+: compute and draw meshes with
\lualatex}
18 \author{Maxime Chupin
\email{mc@melusine.eu.org
}}
22 \definecolor{darkred
}{rgb
}{0.8,
0.1,
0.1}
25 \newcommand*
\commande{\noindent\hspace{-
30pt
}%
26 \SaveVerb[aftersave=
{%
31 \newcommand*
\textme[1]{\textcolor{black
}{\rmfamily\textit{#1}}}
32 \newcommand*
\meta[1]{% % meta
33 \textme{\ensuremath{\langle}#1\ensuremath{\rangle}}}
34 \newcommand*
\optstar{% % optional star
35 \meta{\ensuremath{*
}}\xspace}
37 \newcommand\R{\mathbf{R
}}
38 \setlength{\fboxsep}{2pt
}
40 codes=
{\catcode`\«
\active \catcode`\×
\active },
41 defineactive=
{\makefancyog\makefancytimes},
42 formatcom=
\color{darkred
},
45 % rendre «...» équivalent à \meta{...}
47 \newcommandx\makefancyog[0][addprefix=
\global]{%
48 \def«#
#1»
{\meta{#
#1}}}}
49 % rendre × équivalent à \optstar
51 \newcommandx\makefancytimes[0][addprefix=
\global]{%
55 \tcbuselibrary{listings,breakable
}
57 \definecolor{vert
}{rgb
}{0.1,
0.4,
0.1}
58 \definecolor{bleu
}{rgb
}{0.1,
0.1,
0.4}
60 numberstyle=
\footnotesize\color{vert
},
61 keywordstyle=
\ttfamily\bfseries\color{blue
},
62 basicstyle=
\ttfamily\footnotesize,
63 commentstyle=
\itshape\color{vert
},
64 stringstyle=
\ttfamily,
65 showstringspaces=false,
69 defaultdialect=
[LaTeX
]TeX,
70 morekeywords=
{buildMeshBW,buildMeshBWinc,drawPointsMesh,buildVoronoiBW,buildVoronoiBWinc,
71 drawPointsMeshinc, meshAddPointBW,
72 meshAddPointBWinc,drawGmsh,drawGmshinc,gmshVoronoi,gmshVoronoiinc
}% frame=tb
75 \lstdefinelanguage{lua
}
76 {morekeywords=
{for,end,function,do,if,else,elseif,then,
77 tex.print,tex.sprint,io.read,io.open,string.find,string.explode,require
},
79 morecomment=
[s
]{--
[[}{]]},
83 \newtcblisting{Exemple
}{%
84 arc=
0pt,outer arc=
0pt,
86 colframe=red!
75!black,
88 boxsep=
0pt,left=
5pt,right=
5pt,top=
5pt,bottom=
5pt, bottomtitle =
90 boxrule=
0pt,bottomrule=
0.5pt,toprule=
0.5pt, toprule at break =
91 0pt, bottomrule at break =
0pt,
92 listing options=
{breaklines
},
95 \newtcblisting{commandshell
}{colback=black,colupper=white,colframe=black,
97 listing only,boxsep=
0pt,listing
98 options=
{style=tcblatex,language=sh
},
99 every listing line=
{\textcolor{red
}{\small\ttfamily\bfseries user \$>
}}}
101 \newtcblisting{latexcode
}{
102 arc=
0pt,outer arc=
0pt,
104 colframe=red!
75!black,
106 boxsep=
0pt,left=
5pt,right=
5pt,top=
5pt,bottom=
5pt, bottomtitle =
108 boxrule=
0pt,bottomrule=
0.5pt,toprule=
0.5pt, toprule at break =
109 0pt, bottomrule at break =
0pt,
110 listing only,boxsep=
0pt,listing
115 \newcommand\luamesh{\Verb+luamesh+
\xspace}
117 \newenvironment{optionsenum
}[1][]
118 {\begin{description
}[font=
\color{darkred
}\ttfamily]}
121 \newenvironment{warning
}{%
122 \setlength{\logowidth}{24pt
}
124 arc=
0pt,outer arc=
0pt,colback=gray!
10!white,colframe=gray!
60!white,
125 boxsep=
0pt,left=
5pt,right=
5pt,top=
5pt,bottom=
5pt, bottomtitle =
3pt, toptitle=
3pt,
126 boxrule=
0pt,bottomrule=
0.5pt,toprule=
0.5pt
}
129 \begin{wrapfigure
}[2]{L
}{17pt
}%
136 {\end{tcolorbox
}\medskip}
138 \lstset{moredelim=*
[s
][\color{red
}\rmfamily\itshape]{<
}{>
}}
139 \lstset{moredelim=*
[s
][\color{blue
}\rmfamily\itshape]{<<
}{>>
}}
140 \usepackage[colorlinks=true
]{hyperref
}
142 %% === Page de garde ===================================================
143 \thispagestyle{empty
}
144 \begin{tikzpicture
}[remember picture, overlay
]
145 \node[below right, shift=
{(-
4pt,
4pt)
}] at (current page.north west)
{%
146 \includegraphics{fond.pdf
}%
151 \includegraphics{luamesh-title
}\\
152 {\large compute and draw meshes with
\lualatex}\\
[1cm
]
153 \parbox{0.6\textwidth}{
155 mode=ext,step=badtriangles,
156 colorNew =green!
20!red,
164 \parbox{0.4\textwidth}{\Large\raggedleft
165 \textbf{Contributor
}\\
166 Maxime
\textsc{Chupin
}
170 Version
0.2,
29 novembre
2016\\
171 \url{http://melusine.eu.org/syracuse/G/delaunay/
}
173 %% == Page de garde ====================================================
179 The package
\Verb|luamesh| allows to compute and draw
2D Delaunay
180 triangulation. The algorithm is written with lua, and depending on the
181 choice of the ``engine'', the drawing is done by MetaPost (with
182 \Verb|luamplib|) or by
\Verb|tikz|.
184 The Delaunay triangulation algorithm is the Bowyer and Watson
185 algorithm. Several macros are provided to draw the global mesh, the
186 set of points, or a particular step of the algorithm.
189 I would like to thank Jean-Michel Sarlat, who hosts the development
190 with a git project on the
\Verb+melusine+ machine:
192 \url{https://melusine.eu.org/syracuse/G/delaunay/
}
194 I would also like to thank the first user, an intensive
195 \emph{test
} user, and a very kind English corrector: Nicole Spillane.
199 \section{Installation
}
202 Of course, you can just put the two files
\Verb+luamesh.lua+ and
203 \Verb+luamesh.sty+ in the working directory but this is not
207 \subsection{With
\TeX live and Linux or Mac OSX
}
209 To install
\luamesh with
\TeX live, you have to create the local
210 \Verb+texmf+ directory in your
\Verb+home+.
216 Then place the files in the correct directories. The
217 \Verb+luamesh.sty+ file must be in directory:
219 \Verb+~/texmf/tex/latex/luamesh/+
221 and the
\Verb+luamesh.lua+ file must be in directory:
223 \Verb+~/texmf/scripts/luamesh/+
226 Once you have done this,
\luamesh can be included in your
document
232 \subsection{With Mik
\TeX{} and Windows
}
234 As these two systems are unknown to the contributor, we refer to the
235 documentation for integrating local additions to Mik
\TeX:
237 \url{http://docs.miktex.org/manual/localadditions.html
}
241 \subsection{A
\lualatex package
}
243 If you want to use this package, you must compile your
document with
247 lualatex mylatexfile.tex
251 \subsection{Dependencies
}
253 This package is built upon two main existing packages that one used to
257 \item \Verb+luamplib+ to use MetaPost via the
\luatex library
261 We will see how to choose between these two
\emph{drawing engines
}.
262 Moreover, the following packages are necessary:
264 \item \Verb+xkeyval+ to manage the optional arguments;
265 \item \Verb+xcolor+ to use colors (required by
\Verb+luamplib+);
266 \item \Verb+ifthen+ to help programming with
\TeX.
270 \section{The Basic Macros
}
272 This package provides macros to draw two
273 dimensional triangulations (or meshes).
275 \subsection{Draw a Complete Mesh
}\label{sec:buildMesh
}
277 \commande|
\buildMeshBW[«options»
]{«list of points» or «file name»
}|
\medskip
279 This macro produces the Delaunay triangulation (using the Bowyer and
280 Watson algorithm) of the given
\meta{list of points
}. The list of
281 points must be given in the following way :
283 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
287 \buildMeshBW{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}
290 \subsubsection{The Options
}
292 There are several options to customize the drawing.
294 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
295 use either the previously described set of points in the argument, or
296 a file containing the points line by line (in
2 columns). Such a
305 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
306 points added to form the
\emph{bounding box
}\footnote{The bounding
307 box is defined by four points place at
15\% around the box
308 defined by $(x_
{\min},y_
{\min})$, $(x_
{\min},y_
{\max})$,
309 $(x_
{\max},y_
{\max})$, and $(x_
{\min},y_
{\max})$. It is used by
310 the algorithm and will be computed in any case.
} and the
311 triangles attached. By default, these triangles are removed at the end of
313 \item[color =
\meta{value
} (default: black):
] The
color of the
315 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
316 drawing for the elements (points and triangles) belonging to the
318 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
319 triangulation. This also adds a
\emph{dot
} at each vertex.
320 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
321 label the vertices of the triangulation. It is included in the math
322 mode delimiters
\Verb+$...$+. The bounding box points are labeled
323 with numbers
1 to
4 and with a star exponent.
324 \item[tikz (boolean, default:false):
] By default, this boolean is set
325 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
326 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
328 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
329 the scale at which the picture is drawn (the same for both
330 axes). It must contain the unit of length (cm,
334 To illustrate the options, let us show you an example. We consider a
335 file
\Verb+mesh.txt+:
359 The drawing engine is not very relevant here, although it is useful to
360 understand how the drawing is produced. However, the engine will be
362 the so called
\emph{inc
} macros (section~
\ref{sec:inc
}) for adding
363 code before and after the one generated by
367 \subsection{Draw the Set of Points
}
369 \commande|
\drawPointsMesh[«options»
]{«list of points» or «file name»
}|
\medskip
371 With the
\Verb+
\drawPointsMesh+, we plot the set of (user chosen) points from
372 which the Bowyer and Watson algorithm computes the triangulation.
374 The use of this macro is quite similar to
375 \Verb+
\buildMeshBW+. Here is an example of the basic uses.
377 \drawPointsMesh{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}
381 \subsubsection{The Options
}
383 There are several options (exactly the same as for the
384 \Verb+
\buildMeshBW+) to customize the drawing.
386 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
387 use either the previously described set of points as the argument, or
388 a file containing the points line by line (in
2 columns). Such a
397 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
398 points added to form the
\emph{bounding box
}\footnote{The bounding
399 box is defined by four points place at
15\% around the box
400 defined by $(x_
{\min},y_
{\min})$, $(x_
{\min},y_
{\max})$,
401 $(x_
{\max},y_
{\max})$, and $(x_
{\min},y_
{\max})$. It is used by
402 the algorithm and will be computed in any case.
} and the
403 triangles attached. By default, these triangles are removed at the end of
404 the algorithm.
\emph{Here, because we plot only the vertices of the
405 mesh, there are no triangles, only dots.
}
406 \item[color =
\meta{value
} (default: black):
] The
color of the
408 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
409 drawing for the elements (points and triangles) belonging to the
411 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
412 triangulation. This also adds a
\emph{dot
} at each vertex. With no
413 label, the dot remains.
414 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
415 label the vertices of the triangulation. This is included in the math
416 mode delimiters
\Verb+$...$+. The bounding box points are labeled
417 with numbers
1 to
4 and with a star exponent.
418 \item[tikz (boolean, default:false):
] By default, this boolean is set
419 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
420 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
422 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
423 the scale at which the picture is drawn (the same for both
424 axes). It must contain the unit of length (cm,
427 With the same external mesh point file presented in
428 section~
\ref{sec:buildMesh
}, we illustrate the different options.
444 \subsection{Draw a Step of the Bowyer and Watson Algorithm
}
446 \commande|
\meshAddPointBW[«options»
]{«list of points» or «file name»
}{«point» or «number of line»
}|
\medskip
448 This command allows to plot the steps within the addition of a
449 point in a Delaunay triangulation by the Bowyer and Watson
452 This macro produces the Delaunay triangulation (using the Bowyer and
453 Watson algorithm) of the given
\meta{list of points
} and shows a step
454 of the algorithm when the
\meta{point
} is added. The list of
455 points must be given in the following way:
457 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
459 and the point is of the form
\verb+(x,y)+. The
\meta{file name
}
460 and
\meta{number of line
} will be explained in the option
463 One can use the macro as follows:
465 \meshAddPointBW[step=badtriangles
]{(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}{(
2.2,
1.8)
}
466 \meshAddPointBW[step=cavity
]{(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}{(
2.2,
1.8)
}
467 \meshAddPointBW[step=newtriangles
]{(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}{(
2.2,
1.8)
}
469 The default value for
\Verb+step+ is
470 \Verb+badtriangles+. Consequently, the first
471 line is equivalent to
473 \meshAddPointBW{(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}{(
2.2,
1.8)
}
476 \subsubsection{The Options
}
478 There are several options (some of them are the same as for
479 \Verb+
\buildMeshBW+) to customize the drawing.
481 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
482 use either the previously described set of points as the argument, or
483 a file containing the points line by line (in
2 columns). Such a
492 For the second argument of the macro, if we are in
493 \Verb+mode = ext+, the argument must be the
\emph{line number
} of the file
494 corresponding to the point we want to add. The algorithm will stop at the
495 previous line to build the initial triangulation and proceed to add
496 the point corresponding to the line requested. The subsequent lines in
499 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
500 added points that form the
\emph{bounding box
} and the triangles
501 attached. Although they are always computed, by default, these
502 triangles are removed at the end of
504 \item[color =
\meta{value
} (default: black):
] The
color of the
506 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
507 drawing for the elements (points and triangles) belonging to the
509 \item[colorNew =
\meta{value
} (default: red):
] The
color of the
510 drawing of the ``new'' elements which are the point to add, the
511 polygon delimiting the cavity, and the new triangles.
512 \item[colorBack =
\meta{value
} (default: black!
20):
] The
color for the
513 filling of the region concerned by the addition of the new point.
514 \item[colorCircle =
\meta{value
} (default: green):
] The
color for
515 the circumcircle of the triangles containing the point to add.
516 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
517 label the vertices of the triangulation. It is included in the math
518 mode delimiters
\Verb+$...$+. The bounding box points are labeled
519 with numbers
1 to
4 and with a star exponent.
520 \item[step = badtriangles (default)
\textme{or
} cavity
\textme{or
}
521 newtriangles:
] To choose the step we want to draw, corresponding to
522 the steps of the Bowyer and Watson algorithm.
523 \item[newpoint =
\meta{value
} (default: P):
] The letter(s) used to
524 label the new point of the triangulation. It is include in the math
525 mode delimiters
\Verb+$...$+.
526 \item[tikz (boolean, default:false):
] By default, this boolean is set
527 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
528 the picture. With this option,
\Verb+tikz+ is the
\textit{drawing
530 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
531 the scale at which the picture is drawn (the same for both
532 axis). It must contain the unit of length (cm,
536 Here is an example of customizing the drawing. First, recall that
537 the external file
\Verb+mesh.txt+ is:
547 We draw the addition of the
6th point. The
7th line will be ignored.
556 colorNew = green!
50!red,
558 colorBbox = black!
20,
565 \section{The
\emph{inc
} Macros
}\label{sec:inc
}
567 The three macros presented in the above sections have complementary
568 macros, with the suffix
\Verb+inc+ that allow the user to add code
569 (MetaPost or
\Verb+tikz+, depending of the drawing engine) before and
570 after the code generated by
\luamesh.
572 The three macros are:
\medskip
575 \commande|
\buildMeshBWinc[«options»
]{«list of points» or «file name»
}{«code before»
}{«code after»
}|
\medskip
577 \commande|
\drawPointsMeshinc[«options»
]{«list of points» or «file name»
}{«code before»
}{«code after»
}|
\medskip
579 \commande|
\meshAddPointBWinc[«options»
]{«list of points» or «file name»
}%|
581 \commande|
{«point» or «number of line»
}{«code before»
}{«code after»
}|
\medskip
583 \subsection{With MetaPost
}
585 We consider the case where the drawing engine is MetaPost (through the
586 \Verb+luamplib+ package).
588 The feature is described for the
\Verb+
\buildMeshBWinc+ but the mechanism
589 and possibilities are exactly the same for all three macros.
591 When we use the MetaPost drawing engine, the macros previously
592 described produce a code of the form
597 <code for the drawing>
602 Then, the arguments
\meta{code before
} and
\meta{code after
} are
608 <code for the drawing>
613 With the
\emph{inc
} macros, the user has to add the
\Verb+beginfig();+
614 and
\Verb+endfig;+ commands to produce a picture. Indeed, this allows
615 to use the
\Verb+
\everymplib+ command from the
\Verb+
\luamplib+ package.
618 \subsubsection{The
\LaTeX{} Colors Inside the MetaPost Code
}\label{sec:mpcolor
}
620 The configurable colors
621 of the
\LaTeX{} macro are accessible inside the MetaPost code. For
622 \Verb+
\buildMeshBWinc+ and
\Verb+
\drawPointsMeshinc+,
623 \Verb+
\luameshmpcolor+,
624 and
\Verb+
\luameshmpcolorBbox+ have been defined.
625 For the macro
\Verb+
\meshAddPointBWinc+ three additional
626 colors are present:
\Verb+
\luameshmpcolorBack+,
627 \Verb+
\luameshmpcolorNew+, and
628 \Verb+
\luameshmpcolorCircle+. Of course, MetaPost
629 colors can be defined as well. Finally, the
\Verb+luamplib+ mechanism
630 \Verb+
\mpcolor+ is also available.
632 \subsubsection{The Mesh Points
}
634 At the beginning of the automatically generated code, a list of
635 MetaPost
\Verb+pair+s are defined corresponding to all the vertices in
636 the mesh (when the option
\Verb+bbox=show+, the last
4 points are the
637 \emph{bounding box points
}). The points are available with the
638 \Verb+MeshPoints
[]+ table of variables. The
\Verb+pair+s ($
\R^
{2}$ points)
639 \Verb+MeshPoints
[i
]+ are
640 defined using the unit length
\Verb+u+.
642 \subsubsection{Examples
}
644 Here is three examples for the different macros.
651 ]{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}%
656 label(btex Mesh $
\mathbb{T
}$ etex, (
0,
2u)) withcolor
\luameshmpcolor;
666 ]{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}%
671 drawdblarrow MeshPoints
[3] -- MeshPoints
[9] withpen pencircle scaled
1pt
672 withcolor (
0.3,
0.7,
0.2);
679 colorNew = green!
50!red,
681 colorBbox = black!
20,
685 {(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5)
}{(
2.8,
1.5)
}%
692 fill MeshPoints
[7]--MeshPoints
[8]--MeshPoints
[9]--MeshPoints
[10]--cycle
693 withcolor
\mpcolor{blue!
10};
699 The variables
\Verb+MeshPoints
[]+ are not defined for the argument
700 corresponding to the code placed
\textbf{before
} the code generated by
701 \luamesh. Hence, to use such variables, we have to define a
702 \Verb+picture+ as shown in the third example above.
706 \subsection{With TikZ
}
708 If we have chosen
\Verb+tikz+ as the drawing engine, the added code
709 will be written in
\Verb+tikz+. In that case, the two arguments
710 \meta{code before
} and
\meta{code after
} will be inserted as follows:
713 \begin{tikzpicture
}[x=<scale>,y=<scale>
]
720 Because the engine is
\Verb+tikz+ their is no issue with colors, the
721 \LaTeX{} colors (e.g.:
\Verb+xcolor+) can be used directly.
723 \subsubsection{The Mesh Points
}
725 The mesh points are defined here as
\Verb+tikz+
726 \Verb+
\coordinate+ and named as follows
728 \coordinate (MeshPoints1) at (...,...);
729 \coordinate (MeshPoints2) at (...,...);
730 \coordinate (MeshPoints3) at (...,...);
734 Once again these coordinates are not yet defined to be used in the
735 code given by
\meta{code
738 \subsubsection{Examples
}
747 ]{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}%
751 \node[color = blue!
50] at (
0,
2)
{Mesh $
\mathbb{T
}$
} ;
761 ]{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}%
765 \draw[<->,thick,
color=green
] (MeshPoints3) -- (MeshPoints9);
769 \section{Voronoï Diagrams
}
771 Another interesting feature of b Delaunay triangulation is that its
772 \emph{dual
} is the so-called Voronoï diagram. More precisely, for a
774 points $\
{p_
{1},
\ldots, p_
{n
}\
}$ in the Euclidean plane, the Voronoï
775 cell $R_
{k
}$ corresponding to $p_
{k
}$ is the set of
776 all points in the Euclidean plane $
\R^
{2}$ whose distance to $p_
{k
}$ is less
778 or equal to its distance to any other $p_
{k'
}$.
\bigskip
781 \commande|
\buildVoronoiBW[«options»
]{«list of points» or «file name»
}|
\medskip
783 This macro produce the Voronoï diagram of the given
\meta{list of
784 points
}. Once again, the
786 points must be given in the following way :
788 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
792 \buildVoronoiBW{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5);(
0.1,
2);(
1.5,-
0.3)
}
795 \subsection{The Options
}\label{sec:voronoiOptions
}
798 There are several options to customize the drawing.
800 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
801 use either the previously described set of points in the argument, or
802 a file containing the points line by line (in
2 columns). Such a
811 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
812 added points to form a
\emph{bounding box
}\footnote{The bounding
813 box is defined by four points place at
15\% around the box
814 defined by $(x_
{\min},y_
{\min})$, $(x_
{\min},y_
{\max})$,
815 $(x_
{\max},y_
{\max})$, and $(x_
{\min},y_
{\max})$. It is used by
816 the algorithm and will be computed in any case.
} and the corresponding
817 triangulation. By default, these points are removed at the end of
819 \item[color =
\meta{value
} (default: black):
] The
color of the
821 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
822 drawing for the elements (points and triangles) belonging to the
824 \item[colorVoronoi =
\meta{value
} (default: black):
] The
color of the
825 drawing for the elements (points and polygons) belonging to the
827 \item[print = none (default)
\textme{or
} points:
] To label the
829 triangulation. Contrary to the previous macros, where
830 \Verb+print=none+, a
\emph{dot
} is produced at each vertex of the
831 set of points and at the circumcircle centers which are the nodes of
833 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
834 label the vertices of the triangulation. This is included in the math
835 mode delimiters
\Verb+$...$+. The bounding box points are labelled
836 with numbers
1 to
4 and with a star exponent.
837 \item[circumpoint =
\meta{value
} (default: P):
] The letter(s) used to
838 label the vertices of the Voronoï diagram. This is included in the math
839 mode delimiters
\Verb+$...$+.
840 \item[tikz (boolean, default:false):
] By default, this boolean is set
841 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
842 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
844 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
845 the scale at which the picture is drawn (the same for both
846 axes). It must contain the unit of length (cm,
848 \item[delaunay = none (default)
\textme{or
} show:
] This option
849 allows to draw the Delaunay triangulation under the Voronoï diagram.
850 \item[styleDelaunay = none (default)
\textme{or
} dashed:
] This option
851 allows to draw the Delaunay triangulation in dashed lines.
852 \item[styleVoronoi = none (default)
\textme{or
} dashed:
] This option
853 allows to draw the Voronoï edges in dashed lines.
857 \buildVoronoiBW[tikz,delaunay=show,styleDelaunay=dashed
]
858 {(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5);(
0.1,
2);(
1.5,-
0.3)
}
861 \subsection{The
\emph{inc
} variant
}
863 Once again, a variant of the macros is available allowing the user to
864 add code before and after the code produced by
\luamesh. We refer to
865 section~
\ref{sec:inc
} because it works the same way.
869 \item with MetaPost, the circumcenters are defined using
870 \Verb+pair CircumPoints
[];+ and so they are accessible.
871 \item With
\Verb+tikz+, there are new coordinates defined as follows
873 \coordinate (CircumPoints1) at (...,...);
874 \coordinate (CircumPoints2) at (...,...);
875 \coordinate (CircumPoints3) at (...,...);
880 Finally, when the MetaPost drawing engine is used another
color is
881 available (see~
\ref{sec:mpcolor
}):
\Verb+
\luameshmpcolorVoronoi+.
886 Gmsh is an open source efficient software that produces meshes. The
887 exporting format is the
\emph{MSH ASCII file format
} and can be easily
888 read by a Lua program.
\luamesh provides the user with dedicated
889 macros to read and draw meshes coming from a Gmsh exportation.
\bigskip
891 \commande|
\drawGmsh[«options»
]{«file name»
}|
\medskip
893 This macro draws the triangulation produced by Gmsh and exported in the
894 \Verb+msh+ format. The argument is the name of the file to be read
895 (e.g.:
\Verb+maillage.msh+).
898 \drawGmsh{maillage.msh
}
901 There are several options to customize the drawing.
903 \item[color =
\meta{value
} (default: black):
] The
color of the
905 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
906 triangulation. Contrary to some previous macros, when
907 \Verb+print=none+ a
\emph{dot
} is produced at each vertex of the
908 set of points and at the circumcircle centers (these are the nodes of
909 the Voronoï diagram).
910 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
911 label the vertices of the triangulation. This is included in the math
912 mode delimiters
\Verb+$...$+. The bounding box points are labeled
913 with numbers
1 to
4 and with a star exponent.
914 \item[tikz (boolean, default:false):
] By default, this boolean is set
915 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
916 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
918 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
919 the scale at which the picture is drawn (the same for both
920 axes). It must contain the unit of length (cm,
925 \drawGmsh[scale=
2cm,print=points,
color=blue!
30]{maillage.msh
}
928 \subsection{Gmsh and Voronoï Diagrams
}
930 Because Gmsh generates Delaunay triangulations, we can plot the associated
931 Voronoï diagram. This is done by the following macro:
\bigskip
933 \commande|
\gmshVoronoi[«options»
]{«file name»
}|
\medskip
936 \gmshVoronoi{maillage.msh
}
940 \subsection{The Options
}\label{sec:voronoiOptions
}
943 There are several options to customize the drawing.
945 \item[color =
\meta{value
} (default: black):
] The
color of the
947 \item[colorVoronoi =
\meta{value
} (default: black):
] The
color of the
948 drawing for the elements (points and polygons) belonging to the
950 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
951 triangulation. Contrary to some previous macros, when
952 \Verb+print=none+, a
\emph{dot
} is produced at each vertex of the
953 set of points and at the circumcircle centers (these are the nodes of
954 the Voronoï diagram).
955 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
956 label the vertices of the triangulation. It is included in the math
957 mode delimiters
\Verb+$...$+. The bounding box points are labeled
958 with numbers
1 to
4 and with a star exponent.
959 \item[circumpoint =
\meta{value
} (default: P):
] The letter(s) used to
960 label the vertices of the Voronoï diagram. This is included in the math
961 mode delimiters
\Verb+$...$+.
962 \item[tikz (boolean, default:false):
] By default, this boolean is set
963 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
964 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
966 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
967 the scale at which the picture is drawn (the same for both
968 axes). It must contain the unit of length (cm,
970 \item[delaunay = none (default)
\textme{or
} show
] This option
971 allows to draw the Delaunay triangulation overlapped with the
973 \item[styleDelaunay = none (default)
\textme{or
} dashed
] This option
974 allows to draw the Delaunay triangulation in dashed lines.
975 \item[styleVoronoi = none (default)
\textme{or
} dashed
] This option
976 allows to draw the Voronoï edges in dashed lines.
980 \gmshVoronoi[tikz,scale=
1.5cm, delaunay=show,styleVoronoi=dashed
]{maillage.msh
}
984 \subsection{The
\emph{inc
} variants
}
986 Once again, there exist
\emph{inc
} variant macros:
\bigskip
988 \commande|
\drawGmshinc[«options»
]{«file name»
}{«code before»
}{«code after»
}|
\medskip
990 \commande|
\gmshVoronoiinc[«options»
]{«file name»
}{«code before»
}{«code after»
}|
\medskip
992 We refer to the previous sections for explanations.
995 \subsection{With Animate
}
997 If you use
\emph{Adobe Acrobat reader
}, you can easily produce an
998 animation of the Bowyer and Watson algorithm with the package
1001 For example, the following code (in a file name
\Verb+animation.tex+):
1003 \documentclass{article
}
1004 %% lualatex compilation
1005 \usepackage[margin=
2.5cm
]{geometry
}
1006 \usepackage{luamesh
}
1007 \usepackage{fontspec
}
1008 \usepackage{multido
}
1010 \def\drawPath{draw (-
2,-
2)*u--(
8,-
2)*u--(
8,
6)*u--(-
2,
6)*u--cycle withcolor
0.99white;
}
1011 \def\clipPath{clip currentpicture to (-
2,-
2)*u--(
8,-
2)*u--(
8,
6)*u--(-
2,
6)*u--cycle;
}
1013 \drawPointsMeshinc[mode=ext, bbox = show,colorBbox = blue!
20,print=points
]{mesh.txt
}%
1022 \newpage\buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!
20,print=points
]{meshInit.txt
}%
1031 \multido{\ii=
5+
1}{4}{%
1032 \newpage\meshAddPointBWinc[mode=ext,step=badtriangles,colorNew
1033 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1034 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1043 \meshAddPointBWinc[mode=ext,step=cavity,colorNew
1044 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1045 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1054 \meshAddPointBWinc[mode=ext,step=newtriangles,colorNew
1055 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1056 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1067 \buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!
20,print=points
]{mesh.txt
}%
1077 \buildMeshBWinc[mode=ext,print=points
]{mesh.txt
}%
1088 produces a PDF with multiple pages. Using the
\Verb+pdfcrop+ program,
1089 we crop the pages to the material, and then we can animate the PDF
1090 using the
\Verb+animate+ package.
1093 %\animategraphics[controls]{1}{animation-crop}{}{}
1102 %%% Local Variables:
1103 %%% flyspell-mode: 1
1104 %%% ispell-local-dictionary: "american"