d2cbafd84034691e4b1f77a26a1ebbc8a7126e12
[delaunay.git] / doc / luamesh-doc.tex
1 % luamesh: compute and draw meshes with lua, luamplib and tikz
2 %
3 % Originally written by Maxime Chupin <mc@melusine.eu.org>,
4 % 2010.
5 %
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.
9
10 \documentclass{lltxdoc}
11 \usepackage{tcolorbox}
12 \usepackage{enumitem}
13 \usepackage[tikz]{bclogo}
14 \usepackage{wrapfig}
15 \usepackage{animate}
16
17 \title{\Verb+luamesh+: compute and draw meshes with \lualatex}
18 \author{Maxime Chupin \email{mc@melusine.eu.org}}
19 \date{\today}
20
21
22 \definecolor{darkred}{rgb}{0.8,0.1,0.1}
23
24
25 \newcommand*\commande{\noindent\hspace{-30pt}%
26 \SaveVerb[aftersave={%
27 \UseVerb{Vitem}
28 }%
29 ]{Vitem}}
30
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}
36 \DefineShortVerb{\|}
37 \newcommand\R{\mathbf{R}}
38 \setlength{\fboxsep}{2pt}
39 \fvset{%
40 codes={\catcode`\«\active \catcode`\×\active },
41 defineactive={\makefancyog\makefancytimes},
42 formatcom=\color{darkred},
43 frame=single
44 }
45 % rendre «...» équivalent à \meta{...}
46 {\catcode`\«\active
47 \newcommandx\makefancyog[0][addprefix=\global]{%
48 \def«##1»{\meta{##1}}}}
49 % rendre × équivalent à \optstar
50 {\catcode`\×\active
51 \newcommandx\makefancytimes[0][addprefix=\global]{%
52 \def×{\optstar{}}}}
53
54
55 \tcbuselibrary{listings,breakable}
56
57 \definecolor{vert}{rgb}{0.1,0.4,0.1}
58 \definecolor{bleu}{rgb}{0.1,0.1,0.4}
59 \lstset{
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,
66 language=[LaTeX]TeX,
67 breaklines=true,
68 breakindent=30pt,
69 defaultdialect=[LaTeX]TeX,
70 morekeywords={buildMeshBW,buildMeshBWinc,drawPointsMesh,buildVoronoiBW,buildVoronoiBWinc,
71 drawPointsMeshinc, meshAddPointBW,
72 meshAddPointBWinc,drawGmsh,drawGmshinc,gmshVoronoi,gmshVoronoiinc}% frame=tb
73 }
74
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},
78 morecomment=[l]{--},
79 morecomment=[s]{--[[}{]]},
80 morestring=[b]''
81 }
82
83 \newtcblisting{Exemple}{%
84 arc=0pt,outer arc=0pt,
85 colback=red!2!white,
86 colframe=red!75!black,
87 breakable,
88 boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt, bottomtitle =
89 3pt, toptitle=3pt,
90 boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, toprule at break =
91 0pt, bottomrule at break = 0pt,
92 listing options={breaklines},
93 }
94
95 \newtcblisting{commandshell}{colback=black,colupper=white,colframe=black,
96 arc=0pt,
97 listing only,boxsep=0pt,listing
98 options={style=tcblatex,language=sh},
99 every listing line={\textcolor{red}{\small\ttfamily\bfseries user \$> }}}
100
101 \newtcblisting{latexcode}{
102 arc=0pt,outer arc=0pt,
103 colback=red!2!white,
104 colframe=red!75!black,
105 breakable,
106 boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt, bottomtitle =
107 3pt, toptitle=3pt,
108 boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, toprule at break =
109 0pt, bottomrule at break = 0pt,
110 listing only,boxsep=0pt,listing
111 options={breaklines}
112 }
113
114
115 \newcommand\luamesh{\Verb+luamesh+\xspace}
116
117 \newenvironment{optionsenum}[1][]
118 {\begin{description}[font=\color{darkred}\ttfamily]}
119 {\end{description}}
120
121 \newenvironment{warning}{%
122 \setlength{\logowidth}{24pt}
123 \tcbset{%
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}
127 \medskip
128 \begin{tcolorbox}%
129 \begin{wrapfigure}[2]{L}{17pt}%
130 % \raisebox{-5pt}{
131 \vspace*{-0.55cm}
132 \bcinfo
133 % }%
134 \end{wrapfigure}
135 }%
136 {\end{tcolorbox}\medskip}
137
138 \lstset{moredelim=*[s][\color{red}\rmfamily\itshape]{<}{>}}
139 \lstset{moredelim=*[s][\color{blue}\rmfamily\itshape]{<<}{>>}}
140 \usepackage[colorlinks=true]{hyperref}
141 \begin{document}
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}%
147 };
148 \end{tikzpicture}%
149
150 \noindent
151 \includegraphics{luamesh-title}\\
152 {\large compute and draw meshes with \lualatex}\\[1cm]
153 \parbox{0.6\textwidth}{
154 \meshAddPointBW[
155 mode=ext,step=badtriangles,
156 colorNew =green!20!red,
157 colorBack=red!10,
158 colorCircle = blue,
159 bbox = show,
160 colorBbox = black!30
161 ]
162 {meshgarde.txt}{7}
163 }\hfill
164 \parbox{0.4\textwidth}{\Large\raggedleft
165 \textbf{Contributor}\\
166 Maxime \textsc{Chupin}
167 }
168 \vfill
169 \begin{center}
170 Version 0.2, 29 novembre 2016\\
171 \url{http://melusine.eu.org/syracuse/G/delaunay/}
172 \end{center}
173 %% == Page de garde ====================================================
174 \newpage
175
176 \maketitle
177
178 \begin{abstract}
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|.
183
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.
187 \end{abstract}
188
189 I would like to thank Jean-Michel Sarlat, who hosts the development
190 with a git project on the \Verb+melusine+ machine:
191 \begin{center}
192 \url{https://melusine.eu.org/syracuse/G/delaunay/}
193 \end{center}
194 I would also like to thank the first user, an intensive
195 \emph{test} user, and a very kind English corrector: Nicole Spillane.
196
197 \tableofcontents
198
199 \section{Installation}
200
201
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
204 recommended.
205
206
207 \subsection{With \TeX live and Linux or Mac OSX}
208
209 To install \luamesh with \TeX live, you have to create the local
210 \Verb+texmf+ directory in your \Verb+home+.
211
212 \begin{commandshell}
213 mkdir ~/texmf
214 \end{commandshell}
215
216 Then place the files in the correct directories. The
217 \Verb+luamesh.sty+ file must be in directory:
218 \begin{center}
219 \Verb+~/texmf/tex/latex/luamesh/+
220 \end{center}
221 and the \Verb+luamesh.lua+ file must be in directory:
222 \begin{center}
223 \Verb+~/texmf/scripts/luamesh/+
224 \end{center}
225
226 Once you have done this, \luamesh can be included in your document
227 with
228 \begin{latexcode}
229 \usepackage{luamesh}
230 \end{latexcode}
231
232 \subsection{With Mik\TeX{} and Windows}
233
234 As these two systems are unknown to the contributor, we refer to the
235 documentation for integrating local additions to Mik\TeX:
236 \begin{center}
237 \url{http://docs.miktex.org/manual/localadditions.html}
238 \end{center}
239
240
241 \subsection{A \lualatex package}
242
243 If you want to use this package, you must compile your document with
244 \Verb+lualatex+:
245
246 \begin{commandshell}
247 lualatex mylatexfile.tex
248 \end{commandshell}
249
250
251 \subsection{Dependencies}
252
253 This package is built upon two main existing packages that one used to
254 draw the
255 triangulations :
256 \begin{enumerate}
257 \item \Verb+luamplib+ to use MetaPost via the \luatex library
258 \Verb+mplib+;
259 \item \Verb+tikz+.
260 \end{enumerate}
261 We will see how to choose between these two \emph{drawing engines}.
262 Moreover, the following packages are necessary:
263 \begin{enumerate}
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.
267 \end{enumerate}
268
269
270 \section{The Basic Macros}
271
272 This package provides macros to draw two
273 dimensional triangulations (or meshes).
274
275 \subsection{Draw a Complete Mesh}\label{sec:buildMesh}
276
277 \commande|\buildMeshBW[«options»]{«list of points» or «file name»}|\medskip
278
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 :
282 \begin{center}
283 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
284 \end{center}
285
286 \begin{Exemple}
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)}
288 \end{Exemple}
289
290 \subsubsection{The Options}
291
292 There are several options to customize the drawing.
293 \begin{optionsenum}
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
297 file looks like :
298 \begin{verbatim}
299 x1 y1
300 x2 y2
301 x3 y3
302 ...
303 xn yn
304 \end{verbatim}
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
312 the algorithm.
313 \item[color = \meta{value} (default: black):] The color of the
314 drawing.
315 \item[colorBbox = \meta{value} (default: black):] The color of the
316 drawing for the elements (points and triangles) belonging to the
317 bounding box.
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
327 engine}.
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,
331 pt, etc.).
332 \end{optionsenum}
333
334 To illustrate the options, let us show you an example. We consider a
335 file \Verb+mesh.txt+:
336 \begin{verbatim}
337 0.3 0.3
338 1.5 1
339 4 0
340 4.5 2.5
341 1.81 2.14
342 2.5 0.5
343 2.8 1.5
344 \end{verbatim}
345 \begin{Exemple}
346 \buildMeshBW[%
347 tikz,
348 mode = ext,
349 bbox = show,
350 color = red,
351 colorBbox = blue!30,
352 print = points,
353 meshpoint = x,
354 scale = 1.3cm,
355 ]{mesh.txt}
356 \end{Exemple}
357
358 \begin{warning}
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
361 relevant to
362 the so called \emph{inc} macros (section~\ref{sec:inc}) for adding
363 code before and after the one generated by
364 \luamesh.
365 \end{warning}
366
367 \subsection{Draw the Set of Points}
368
369 \commande|\drawPointsMesh[«options»]{«list of points» or «file name»}|\medskip
370
371 With the \Verb+\drawPointsMesh+, we plot the set of (user chosen) points from
372 which the Bowyer and Watson algorithm computes the triangulation.
373
374 The use of this macro is quite similar to
375 \Verb+\buildMeshBW+. Here is an example of the basic uses.
376 \begin{Exemple}
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)}
378 \end{Exemple}
379
380
381 \subsubsection{The Options}
382
383 There are several options (exactly the same as for the
384 \Verb+\buildMeshBW+) to customize the drawing.
385 \begin{optionsenum}
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
389 file looks like :
390 \begin{verbatim}
391 x1 y1
392 x2 y2
393 x3 y3
394 ...
395 xn yn
396 \end{verbatim}
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
407 drawing.
408 \item[colorBbox = \meta{value} (default: black):] The color of the
409 drawing for the elements (points and triangles) belonging to the
410 bounding box.
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
421 engine}.
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,
425 pt, etc.).
426 \end{optionsenum}
427 With the same external mesh point file presented in
428 section~\ref{sec:buildMesh}, we illustrate the different options.
429
430 \begin{Exemple}
431 \drawPointsMesh[%
432 tikz,
433 mode = ext,
434 bbox = show,
435 color = blue,
436 colorBbox = red,
437 print = points,
438 meshpoint = y,
439 scale = 1.3cm,
440 ]{mesh.txt}
441 \end{Exemple}
442
443
444 \subsection{Draw a Step of the Bowyer and Watson Algorithm}
445
446 \commande|\meshAddPointBW[«options»]{«list of points» or «file name»}{«point» or «number of line»}|\medskip
447
448 This command allows to plot the steps within the addition of a
449 point in a Delaunay triangulation by the Bowyer and Watson
450 algorithm.
451
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:
456 \begin{center}
457 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
458 \end{center}
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
461 description.
462
463 One can use the macro as follows:
464 \begin{Exemple}
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)}
468 \end{Exemple}
469 The default value for \Verb+step+ is
470 \Verb+badtriangles+. Consequently, the first
471 line is equivalent to
472 \begin{latexcode}
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)}
474 \end{latexcode}
475
476 \subsubsection{The Options}
477
478 There are several options (some of them are the same as for
479 \Verb+\buildMeshBW+) to customize the drawing.
480 \begin{optionsenum}
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
484 file looks like :
485 \begin{verbatim}
486 x1 y1
487 x2 y2
488 x3 y3
489 ...
490 xn yn
491 \end{verbatim}
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
497 the file are
498 ignored.
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
503 the algorithm.
504 \item[color = \meta{value} (default: black):] The color of the
505 drawing.
506 \item[colorBbox = \meta{value} (default: black):] The color of the
507 drawing for the elements (points and triangles) belonging to the
508 bounding box.
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
529 engine}.
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,
533 pt, etc.).
534 \end{optionsenum}
535
536 Here is an example of customizing the drawing. First, recall that
537 the external file \Verb+mesh.txt+ is:
538 \begin{verbatim}
539 0.3 0.3
540 1.5 1
541 4 0
542 4.5 2.5
543 1.81 2.14
544 2.5 0.5
545 2.8 1.5
546 \end{verbatim}
547 We draw the addition of the 6th point. The 7th line will be ignored.
548 \begin{Exemple}
549 \meshAddPointBW[
550 tikz,
551 mode = ext,
552 color = blue!70,
553 meshpoint = \alpha,
554 newpoint = y,
555 colorBack=red!10,
556 colorNew = green!50!red,
557 colorCircle = blue,
558 colorBbox = black!20,
559 bbox = show,
560 scale=1.4cm,
561 step=badtriangles]
562 {mesh.txt}{6}
563 \end{Exemple}
564
565 \section{The \emph{inc} Macros}\label{sec:inc}
566
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.
571
572 The three macros are:\medskip
573
574
575 \commande|\buildMeshBWinc[«options»]{«list of points» or «file name»}{«code before»}{«code after»}|\medskip
576
577 \commande|\drawPointsMeshinc[«options»]{«list of points» or «file name»}{«code before»}{«code after»}|\medskip
578
579 \commande|\meshAddPointBWinc[«options»]{«list of points» or «file name»}%|
580
581 \commande| {«point» or «number of line»}{«code before»}{«code after»}|\medskip
582
583 \subsection{With MetaPost}
584
585 We consider the case where the drawing engine is MetaPost (through the
586 \Verb+luamplib+ package).
587
588 The feature is described for the \Verb+\buildMeshBWinc+ but the mechanism
589 and possibilities are exactly the same for all three macros.
590
591 When we use the MetaPost drawing engine, the macros previously
592 described produce a code of the form
593 \begin{latexcode}
594 \begin{luamplib}
595 u:=<scale>;
596 beginfig(0);
597 <code for the drawing>
598 endfig;
599 \end{luamplib}
600 \end{latexcode}
601
602 Then, the arguments \meta{code before} and \meta{code after} are
603 inserted as follows:
604 \begin{latexcode}
605 \begin{luamplib}
606 u:=<scale>;
607 <<code before>>
608 <code for the drawing>
609 <<code after>>
610 \end{luamplib}
611 \end{latexcode}
612 \begin{warning}
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.
616 \end{warning}
617
618 \subsubsection{The \LaTeX{} Colors Inside the MetaPost Code}\label{sec:mpcolor}
619
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.
631
632 \subsubsection{The Mesh Points}
633
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+.
641
642 \subsubsection{Examples}
643
644 Here is three examples for the different macros.
645 \begin{Exemple}
646 \drawPointsMeshinc[
647 color = blue!50,
648 print = points,
649 meshpoint = x,
650 scale=0.8cm,
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)}%
652 {% code before
653 beginfig(0);
654 }%
655 {% code after
656 label(btex Mesh $\mathbb{T}$ etex, (0,2u)) withcolor \luameshmpcolor;
657 endfig;
658 }
659 \buildMeshBWinc[%
660 bbox = show,
661 color = red,
662 colorBbox = blue!30,
663 print = points,
664 meshpoint = x,
665 scale=0.8cm
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)}%
667 {% code before
668 beginfig(0);
669 }
670 {% code after
671 drawdblarrow MeshPoints[3] -- MeshPoints[9] withpen pencircle scaled 1pt
672 withcolor (0.3,0.7,0.2);
673 endfig;
674 }
675 \meshAddPointBWinc[
676 meshpoint = \alpha,
677 newpoint = y,
678 colorBack=red!10,
679 colorNew = green!50!red,
680 colorCircle = blue,
681 colorBbox = black!20,
682 bbox = show,
683 scale=0.8cm,
684 step=badtriangles]
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)}%
686 {%code before
687 picture drawing;
688 drawing := image(
689 }{%code after
690 );
691 beginfig(0);
692 fill MeshPoints[7]--MeshPoints[8]--MeshPoints[9]--MeshPoints[10]--cycle
693 withcolor \mpcolor{blue!10};
694 draw drawing;
695 endfig;
696 }
697 \end{Exemple}
698 \begin{warning}
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.
703 \end{warning}
704
705
706 \subsection{With TikZ}
707
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:
711 \begin{latexcode}
712 \noindent
713 \begin{tikzpicture}[x=<scale>,y=<scale>]
714 <<code before>>
715 <generated code>
716 <<code after>>
717 \end{tikzpicture}
718 \end{latexcode}
719
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.
722
723 \subsubsection{The Mesh Points}
724
725 The mesh points are defined here as \Verb+tikz+
726 \Verb+\coordinate+ and named as follows
727 \begin{latexcode}
728 \coordinate (MeshPoints1) at (...,...);
729 \coordinate (MeshPoints2) at (...,...);
730 \coordinate (MeshPoints3) at (...,...);
731 %etc.
732 \end{latexcode}
733
734 Once again these coordinates are not yet defined to be used in the
735 code given by \meta{code
736 before} argument.
737
738 \subsubsection{Examples}
739
740 \begin{Exemple}
741 \drawPointsMeshinc[
742 tikz,
743 color = blue!50,
744 print = points,
745 meshpoint = x,
746 scale=0.8cm,
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)}%
748 {% code before
749 }%
750 {% code after
751 \node[color = blue!50] at (0,2) {Mesh $\mathbb{T}$} ;
752 }
753 \buildMeshBWinc[%
754 tikz,
755 bbox = show,
756 color = red,
757 colorBbox = blue!30,
758 print = points,
759 meshpoint = x,
760 scale=0.8cm
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)}%
762 {% code before
763 }
764 {% code after
765 \draw[<->,thick, color=green] (MeshPoints3) -- (MeshPoints9);
766 }
767 \end{Exemple}
768
769 \section{Voronoï Diagrams}
770
771 Another interesting feature of b Delaunay triangulation is that its
772 \emph{dual} is the so-called Voronoï diagram. More precisely, for a
773 finite set of
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
777 than
778 or equal to its distance to any other $p_{k'}$.\bigskip
779
780
781 \commande|\buildVoronoiBW[«options»]{«list of points» or «file name»}|\medskip
782
783 This macro produce the Voronoï diagram of the given \meta{list of
784 points}. Once again, the
785 list of
786 points must be given in the following way :
787 \begin{center}
788 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
789 \end{center}
790
791 \begin{Exemple}
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)}
793 \end{Exemple}
794
795 \subsection{The Options}\label{sec:voronoiOptions}
796
797
798 There are several options to customize the drawing.
799 \begin{optionsenum}
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
803 file looks like :
804 \begin{verbatim}
805 x1 y1
806 x2 y2
807 x3 y3
808 ...
809 xn yn
810 \end{verbatim}
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
818 the algorithm.
819 \item[color = \meta{value} (default: black):] The color of the
820 drawing.
821 \item[colorBbox = \meta{value} (default: black):] The color of the
822 drawing for the elements (points and triangles) belonging to the
823 bounding box.
824 \item[colorVoronoi = \meta{value} (default: black):] The color of the
825 drawing for the elements (points and polygons) belonging to the
826 Voronoï diagram.
827 \item[print = none (default) \textme{or} points:] To label the
828 vertices in 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
832 the Voronoï diagram.
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
843 engine}.
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,
847 pt, etc.).
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.
854 \end{optionsenum}
855
856 \begin{Exemple}
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)}
859 \end{Exemple}
860
861 \subsection{The \emph{inc} variant}
862
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.
866
867 Let us note that:
868 \begin{itemize}
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
872 \begin{latexcode}
873 \coordinate (CircumPoints1) at (...,...);
874 \coordinate (CircumPoints2) at (...,...);
875 \coordinate (CircumPoints3) at (...,...);
876 % etc.
877 \end{latexcode}
878 \end{itemize}
879
880 Finally, when the MetaPost drawing engine is used another color is
881 available (see~\ref{sec:mpcolor}): \Verb+\luameshmpcolorVoronoi+.
882
883
884 \section{With Gmsh}
885
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
890
891 \commande|\drawGmsh[«options»]{«file name»}|\medskip
892
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+).
896
897 \begin{Exemple}
898 \drawGmsh{maillage.msh}
899 \end{Exemple}
900
901 There are several options to customize the drawing.
902 \begin{optionsenum}
903 \item[color = \meta{value} (default: black):] The color of the
904 drawing.
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
917 engine}.
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,
921 pt, etc.).
922 \end{optionsenum}
923 Here is an example:
924 \begin{Exemple}
925 \drawGmsh[scale=2cm,print=points, color=blue!30]{maillage.msh}
926 \end{Exemple}
927
928 \subsection{Gmsh and Voronoï Diagrams}
929
930 Because Gmsh generates Delaunay triangulations, we can plot the associated
931 Voronoï diagram. This is done by the following macro:\bigskip
932
933 \commande|\gmshVoronoi[«options»]{«file name»}|\medskip
934
935 \begin{Exemple}
936 \gmshVoronoi{maillage.msh}
937 \end{Exemple}
938
939
940 \subsection{The Options}\label{sec:voronoiOptions}
941
942
943 There are several options to customize the drawing.
944 \begin{optionsenum}
945 \item[color = \meta{value} (default: black):] The color of the
946 drawing.
947 \item[colorVoronoi = \meta{value} (default: black):] The color of the
948 drawing for the elements (points and polygons) belonging to the
949 Voronoï diagram.
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
965 engine}.
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,
969 pt, etc.).
970 \item[delaunay = none (default) \textme{or} show] This option
971 allows to draw the Delaunay triangulation overlapped with the
972 Voronoï diagram.
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.
977 \end{optionsenum}
978
979 \begin{Exemple}
980 \gmshVoronoi[tikz,scale=1.5cm, delaunay=show,styleVoronoi=dashed]{maillage.msh}
981 \end{Exemple}
982
983
984 \subsection{The \emph{inc} variants}
985
986 Once again, there exist \emph{inc} variant macros:\bigskip
987
988 \commande|\drawGmshinc[«options»]{«file name»}{«code before»}{«code after»}|\medskip
989
990 \commande|\gmshVoronoiinc[«options»]{«file name»}{«code before»}{«code after»}|\medskip
991
992 We refer to the previous sections for explanations.
993
994 \section{Gallery}
995 \subsection{With Animate}
996
997 If you use \emph{Adobe Acrobat reader}, you can easily produce an
998 animation of the Bowyer and Watson algorithm with the package
999 \Verb+animate+.
1000
1001 For example, the following code (in a file name \Verb+animation.tex+):
1002 \begin{latexcode}
1003 \documentclass{article}
1004 %% lualatex compilation
1005 \usepackage[margin=2.5cm]{geometry}
1006 \usepackage{luamesh}
1007 \usepackage{fontspec}
1008 \usepackage{multido}
1009 \pagestyle{empty}
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;}
1012 \begin{document}
1013 \drawPointsMeshinc[mode=ext, bbox = show,colorBbox = blue!20,print=points]{mesh.txt}%
1014 {%
1015 beginfig(0);
1016 \drawPath
1017 }%
1018 {%
1019 \clipPath
1020 endfig;
1021 }
1022 \newpage\buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!20,print=points]{meshInit.txt}%
1023 {%
1024 beginfig(0);
1025 \drawPath
1026 }%
1027 {%
1028 \clipPath
1029 endfig;
1030 }
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}%
1035 {%
1036 beginfig(0);
1037 \drawPath
1038 }%
1039 {%
1040 \clipPath
1041 endfig;
1042 } \newpage
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}%
1046 {%
1047 beginfig(0);
1048 \drawPath
1049 }%
1050 {%
1051 \clipPath
1052 endfig;
1053 } \newpage
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}%
1057 {%
1058 beginfig(0);
1059 \drawPath
1060 }%
1061 {%
1062 \clipPath
1063 endfig;
1064 }
1065 }
1066 \newpage
1067 \buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!20,print=points]{mesh.txt}%
1068 {%
1069 beginfig(0);
1070 \drawPath
1071 }%
1072 {%
1073 \clipPath
1074 endfig;
1075 }
1076 \newpage
1077 \buildMeshBWinc[mode=ext,print=points]{mesh.txt}%
1078 {%
1079 beginfig(0);
1080 \drawPath
1081 }%
1082 {%
1083 \clipPath
1084 endfig;
1085 }
1086 \end{document}
1087 \end{latexcode}
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.
1091
1092 %\begin{Exemple}
1093 %\animategraphics[controls]{1}{animation-crop}{}{}
1094 %\end{Exemple}
1095
1096 \input{dum.bbl}
1097
1098 \end{document}
1099
1100
1101
1102 %%% Local Variables:
1103 %%% flyspell-mode: 1
1104 %%% ispell-local-dictionary: "american"
1105 %%% End:

Licence Creative Commons Les fichiers de Syracuse sont mis à disposition (sauf mention contraire) selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.