e3408ccfa26ac17bc8ebe888a15f38602141a6cf
[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
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. First, the
217 \Verb+luamesh.sty+ file must be in the directory:
218 \begin{center}
219 \Verb+~/texmf/tex/latex/luamesh/+
220 \end{center}
221 and secondly, the \Verb+luamesh.lua+ must be in the 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 We do not know these two systems, so 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 to draw the
254 triangulations :
255 \begin{enumerate}
256 \item \Verb+luamplib+ to use MetaPost via the \luatex library
257 \Verb+mplib+;
258 \item and \Verb+tikz+.
259 \end{enumerate}
260 We will see how to choose between these two \emph{drawing engines}.
261
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 (needed by \Verb+luamplib+);
266 \item \Verb+ifthen+ to help the programming with \TeX.
267 \end{enumerate}
268
269
270 \section{The Basic Macros}
271
272 Let us recall that 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, line by line (2 columns), the points. 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 added points to form a \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 corresponding
311 triangulation. 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, but it is useful to
360 understand how the drawing is made. 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, line by line (2 columns), the points. 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 added points to form a \emph{bounding box} and the corresponding
399 triangulation. By default, these triangles are removed at the end of
400 the algorithm. \emph{Here, because we plot only the vertices of the
401 mesh, there are no triangles, only dots.}
402 \item[color = \meta{value} (default: black):] The color of the
403 drawing.
404 \item[colorBbox = \meta{value} (default: black):] The color of the
405 drawing for the elements (points and triangles) belonging to the
406 bounding box.
407 \item[print = none (default) \textme{or} points:] To label the vertices of the
408 triangulation. This also adds a \emph{dot} at each vertex. Without
409 label, there is still the dot.
410 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
411 label the vertices of the triangulation. It is included in the math
412 mode delimiters \Verb+$...$+. The bounding box points are labeled
413 with numbers 1 to 4 and with a star exponent.
414 \item[tikz (boolean, default:false):] By default, this boolean is set
415 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
416 the picture. With this option, \Verb+tikz+ becomes the \textit{drawing
417 engine}.
418 \item[scale = \meta{value} (default: 1cm):] The scale option defines
419 the scale at which the picture is drawn (the same for both
420 axes). It must contain the unit of length (cm,
421 pt, etc.).
422 \end{optionsenum}
423 With the same external mesh point file presented in
424 section~\ref{sec:buildMesh}, we illustrate the different options.
425
426 \begin{Exemple}
427 \drawPointsMesh[%
428 tikz,
429 mode = ext,
430 bbox = show,
431 color = blue,
432 colorBbox = red,
433 print = points,
434 meshpoint = y,
435 scale = 1.3cm,
436 ]{mesh.txt}
437 \end{Exemple}
438
439
440 \subsection{Draw a Step of the Bowyer and Watson Algorithm}
441
442 \commande|\meshAddPointBW[«options»]{«list of points» or «file name»}{«point» or «number of line»}|\medskip
443
444 This command allows to plot the steps within the addition of a
445 point in a Delaunay triangulation, by the Bowyer and Watson
446 algorithm.
447
448 This macro produces the Delaunay triangulation (using the Bowyer and
449 Watson algorithm) of the given \meta{list of points} and shows a step
450 of the algorithm when the \meta{point} is added. The list of
451 points must be given in the following way:
452 \begin{center}
453 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
454 \end{center}
455 and the point is of the form \verb+(x,y)+. The \meta{file name}
456 and \meta{number of line} will be explained in the option
457 description.
458
459 One can use the macro as fallows:
460 \begin{Exemple}
461 \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)}
462 \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)}
463 \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)}
464 \end{Exemple}
465 The default value for \Verb+step+ is
466 \Verb+badtriangles+. Consequently, the first
467 line is equivalent to
468 \begin{latexcode}
469 \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)}
470 \end{latexcode}
471
472 \subsubsection{The Options}
473
474 There are several options (some of them are the same as for
475 \Verb+\buildMeshBW+) to customize the drawing.
476 \begin{optionsenum}
477 \item[mode = int (default) \textme{or} ext:] this option allows to
478 use either the previously described set of point in the first
479 argument, or
480 a file containing, line by line (2 columns), the points. Such a
481 file looks like :
482 \begin{verbatim}
483 x1 y1
484 x2 y2
485 x3 y3
486 ...
487 xn yn
488 \end{verbatim}
489 For the second argument of the macro, if we are in the
490 \Verb+mode = ext+, the argument must be the \emph{line number} of the file
491 corresponding to the point we want to add. The algorithm will stop the
492 line before to build the initial triangulation for which it will add
493 the point corresponding to the line. The subsequent lines in the file are
494 ignored.
495 \item[bbox = none (default) \textme{or} show:] this option allows to draw the
496 added points to form a \emph{bounding box} and the corresponding
497 triangulation. By default, these triangles are removed at the end of
498 the algorithm.
499 \item[color = \meta{value} (default: black):] The color of the
500 drawing.
501 \item[colorBbox = \meta{value} (default: black):] The color of the
502 drawing for the elements (points and triangles) belonging to the
503 bounding box.
504 \item[colorNew = \meta{value} (default: red):] The color of the
505 drawing of the ``new'' elements which are the point to add, the
506 polygon of the cavity, and the new triangles.
507 \item[colorBack = \meta{value} (default: black!20):] The color for the
508 filling of the region concerned by the addition of the new point.
509 \item[colorCircle = \meta{value} (default: green):] The color for
510 the circumcircle of the triangles containing the point to add.
511 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
512 label the vertices of the triangulation. It is included in the math
513 mode delimiters \Verb+$...$+. The bounding box points are labeled
514 with numbers 1 to 4 and with a star exponent.
515 \item[step = badtriangles (default) \textme{or} cavity \textme{or}
516 newtriangles:] To choose the step we want to draw, corresponding to
517 the steps of the Bowyer and Watson algorithm.
518 \item[newpoint = \meta{value} (default: P):] The letter(s) used to
519 label the new point of the triangulation. It is include in the math
520 mode delimiters \Verb+$...$+.
521 \item[tikz (boolean, default:false):] By default, this boolean is set
522 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
523 the picture. With this option, \Verb+tikz+ is the \textit{drawing
524 engine}.
525 \item[scale = \meta{value} (default: 1cm):] The scale option defines
526 the scale at which the picture is draw (the same for the two
527 axis). It must contain the unit of length (cm,
528 pt, etc.).
529 \end{optionsenum}
530
531 Here is an example of customizing the drawing. First, recall that
532 the external file \Verb+mesh.txt+ is:
533 \begin{verbatim}
534 0.3 0.3
535 1.5 1
536 4 0
537 4.5 2.5
538 1.81 2.14
539 2.5 0.5
540 2.8 1.5
541 \end{verbatim}
542 We draw the addition of the 6th point. The 7th line will be ignored.
543 \begin{Exemple}
544 \meshAddPointBW[
545 tikz,
546 mode = ext,
547 color = blue!70,
548 meshpoint = \alpha,
549 newpoint = y,
550 colorBack=red!10,
551 colorNew = green!50!red,
552 colorCircle = blue,
553 colorBbox = black!20,
554 bbox = show,
555 scale=1.4cm,
556 step=badtriangles]
557 {mesh.txt}{6}
558 \end{Exemple}
559
560 \section{The \emph{inc} Macros}\label{sec:inc}
561
562 The three macros presented in the above sections have complementary
563 macros, with the suffix \Verb+inc+ that allow the user to add code
564 (MetaPost or \Verb+tikz+, depending of the drawing engine) before and
565 after the code generated by \luamesh.
566
567 The three macros are:\medskip
568
569
570 \commande|\buildMeshBWinc[«options»]{«list of points» or «file name»}{«code before»}{«code after»}|\medskip
571
572 \commande|\drawPointsMeshinc[«options»]{«list of points» or «file name»}{«code before»}{«code after»}|\medskip
573
574 \commande|\meshAddPointBWinc[«options»]{«list of points» or «file name»}%|
575
576 \commande| {«point» or «number of line»}{«code before»}{«code after»}|\medskip
577
578 \subsection{With MetaPost}
579
580 We consider the case where the drawing engine is MetaPost (through the
581 \Verb+luamplib+ package).
582
583 We describe the feature taking one macro in example but the mechanism
584 and the possibilities are exactly the same for all the macros.
585
586 When we use the MetaPost drawing engine, the macros previously
587 described produced a code of the form
588 \begin{latexcode}
589 \begin{luamplib}
590 u:=<scale>;
591 beginfig(0);
592 <code for the drawing>
593 endfig;
594 \end{luamplib}
595 \end{latexcode}
596
597 Then, the arguments \meta{code before} and \meta{code after} are
598 inserted as follows:
599 \begin{latexcode}
600 \begin{luamplib}
601 u:=<scale>;
602 <<code before>>
603 <code for the drawing>
604 <<code after>>
605 \end{luamplib}
606 \end{latexcode}
607 \begin{warning}
608 With the \emph{inc} macros, the user has to add the \Verb+beginfig();+
609 and \Verb+endfig;+ commands to produce a picture. Indeed, this allows
610 to use the \Verb+\everymplib+ command from the \Verb+\luamplib+ package.
611 \end{warning}
612
613 \subsubsection{The \LaTeX{} Colors Inside the MetaPost Code}\label{sec:mpcolor}
614
615 The configurable colors
616 of the \LaTeX{} macro are accessible inside the MetaPost code. For
617 \Verb+\buildMeshBWinc+ and \Verb+\drawPointsMeshinc+, we have
618 \Verb+\luameshmpcolor+,
619 and \Verb+\luameshmpcolorBbox+.
620 For the macro \Verb+\meshAddPointBWinc+ we have three additional
621 colors : \Verb+\luameshmpcolorBack+, \Verb+\luameshmpcolorNew+, and
622 \Verb+\luameshmpcolorCircle+. Of course, we can define MetoPost
623 colors as well. Finally, the \Verb+luamplib+ mechanism of
624 \Verb+\mpcolor+ is also available.
625
626 \subsubsection{The Mesh Points}
627
628 At the beginning of the automatically generated code, a list of
629 MetaPost \Verb+pair+s are defined corresponding to all the vertices of
630 the mesh (when the option \Verb+bbox=show+, the last 4 points are the
631 \emph{bounding box points}). The points are available with the
632 \Verb+MeshPoints[]+ table of variables. The \Verb+MeshPoints[i]+ are
633 defined using the unit length \Verb+u+.
634
635 \subsubsection{Examples}
636
637 Here is three examples for the different macros.
638 \begin{Exemple}
639 \drawPointsMeshinc[
640 color = blue!50,
641 print = points,
642 meshpoint = x,
643 scale=0.8cm,
644 ]{(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)}%
645 {% code before
646 beginfig(0);
647 }%
648 {% code after
649 label(btex Mesh $\mathbb{T}$ etex, (0,2u)) withcolor \luameshmpcolor;
650 endfig;
651 }
652 \buildMeshBWinc[%
653 bbox = show,
654 color = red,
655 colorBbox = blue!30,
656 print = points,
657 meshpoint = x,
658 scale=0.8cm
659 ]{(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)}%
660 {% code before
661 beginfig(0);
662 }
663 {% code after
664 drawdblarrow MeshPoints[3] -- MeshPoints[9] withpen pencircle scaled 1pt
665 withcolor (0.3,0.7,0.2);
666 endfig;
667 }
668 \meshAddPointBWinc[
669 meshpoint = \alpha,
670 newpoint = y,
671 colorBack=red!10,
672 colorNew = green!50!red,
673 colorCircle = blue,
674 colorBbox = black!20,
675 bbox = show,
676 scale=0.8cm,
677 step=badtriangles]
678 {(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)}%
679 {%code before
680 picture drawing;
681 drawing := image(
682 }{%code after
683 );
684 beginfig(0);
685 fill MeshPoints[7]--MeshPoints[8]--MeshPoints[9]--MeshPoints[10]--cycle
686 withcolor \mpcolor{blue!10};
687 draw drawing;
688 endfig;
689 }
690 \end{Exemple}
691 \begin{warning}
692 The variables \Verb+MeshPoints[]+ are not defined for the argument
693 corresponding to the code to place before the code generated by
694 \luamesh. Hence, to use such variables, we have to define a
695 \Verb+picture+ as shown in the third example above.
696 \end{warning}
697
698
699 \subsection{With TikZ}
700
701 If we have chosen \Verb+tikz+ as the engine drawing, the added code
702 will be written in \Verb+tikz+. In that case, the two arguments
703 \meta{code before} and \meta{code after} will be inserted as follows:
704 \begin{latexcode}
705 \noindent
706 \begin{tikzpicture}[x=<scale>,y=<scale>]
707 <<code before>>
708 <generated code>
709 <<code after>>
710 \end{tikzpicture}
711 \end{latexcode}
712
713 Because the engine is \Verb+tikz+ their is no issue with colors, the
714 \LaTeX{} colors (e.g.: \Verb+xcolor+) can be directly used.
715
716 \subsubsection{The Mesh Points}
717
718 The points of the mesh are defined here as \Verb+tikz+
719 \Verb+\coordinate+ named as follows
720 \begin{latexcode}
721 \coordinate (MeshPoints1) at (...,...);
722 \coordinate (MeshPoints2) at (...,...);
723 \coordinate (MeshPoints3) at (...,...);
724 %etc.
725 \end{latexcode}
726
727 Once again these coordinates are not yet defined for the \meta{code
728 before} argument.
729
730 \subsubsection{Examples}
731
732 \begin{Exemple}
733 \drawPointsMeshinc[
734 tikz,
735 color = blue!50,
736 print = points,
737 meshpoint = x,
738 scale=0.8cm,
739 ]{(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)}%
740 {% code before
741 }%
742 {% code after
743 \node[color = blue!50] at (0,2) {Mesh $\mathbb{T}$} ;
744 }
745 \buildMeshBWinc[%
746 tikz,
747 bbox = show,
748 color = red,
749 colorBbox = blue!30,
750 print = points,
751 meshpoint = x,
752 scale=0.8cm
753 ]{(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)}%
754 {% code before
755 }
756 {% code after
757 \draw[<->,thick, color=green] (MeshPoints3) -- (MeshPoints9);
758 }
759 \end{Exemple}
760
761 \section{Voronio Diagrams}
762
763 Another interesting concept of Delaunay triangulation is that it is
764 \emph{dual} to it so-called Voronio diagram. For a finite set of
765 points $\{p_{1},\ldots, p_{n}\}$ in the Euclidean plane, for all
766 $p_{k}$, it corresponds a Voronoi cell $R_{k}$ consisting of
767 every point in the Euclidean plane whose distance to $p_{k}$ is less
768 than
769 or equal to its distance to any other $p_{k'}$.\bigskip
770
771
772 \commande|\buildVoronoiBW[«options»]{«list of points» or «file name»}|\medskip
773
774 This macro produce the Voronio diagram dual to the Delaunay
775 triangulation (computed by the Bowyer and Watson
776 algorithm) of the given \meta{list of points}. Once again, the
777 list of
778 points must be given in the following way :
779 \begin{center}
780 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
781 \end{center}
782
783 \begin{Exemple}
784 \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)}
785 \end{Exemple}
786
787 \subsection{The Options}\label{sec:voronoiOptions}
788
789
790 There are several options to customize the drawing.
791 \begin{optionsenum}
792 \item[mode = int (default) \textme{or} ext:] this option allows to
793 use either the previously described set of points in the argument, or
794 a file, containing, line by line (2 columns), the points. Such a
795 file looks like :
796 \begin{verbatim}
797 x1 y1
798 x2 y2
799 x3 y3
800 ...
801 xn yn
802 \end{verbatim}
803 \item[bbox = none (default) \textme{or} show:] this option allows to draw the
804 added points to form a \emph{bounding box}\footnote{The bounding
805 box is defined by four points place at 15\% around the box
806 defined by $(x_{\min},y_{\min})$, $(x_{\min},y_{\max})$,
807 $(x_{\max},y_{\max})$, and $(x_{\min},y_{\max})$. It is used by
808 the algorithm and will be computed in any case.} and the corresponding
809 triangulation. By default, these points are removed at the end of
810 the algorithm.
811 \item[color = \meta{value} (default: black):] The color of the
812 drawing.
813 \item[colorBbox = \meta{value} (default: black):] The color of the
814 drawing for the elements (points and triangles) belonging to the
815 bounding box.
816 \item[colorVoronoi = \meta{value} (default: black):] The color of the
817 drawing for the elements (points and polygons) belonging to the
818 Voronoi diagram.
819 \item[print = none (default) \textme{or} points:] To label the vertices of the
820 triangulation. Contrary to the previous macros, where
821 \Verb+print=none+, a \emph{dot} is produced at each vertex (of the
822 set of points and on the circumcircle center which are the nodes of
823 the Voronoi diagram).
824 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
825 label the vertices of the triangulation. It is included in the math
826 mode delimiters \Verb+$...$+. The bounding box points are labeled
827 with numbers 1 to 4 and with a star exponent.
828 \item[circumpoint = \meta{value} (default: P):] The letter(s) used to
829 label the vertices of the Voronoi diagram. It is included in the math
830 mode delimiters \Verb+$...$+.
831 \item[tikz (boolean, default:false):] By default, this boolean is set
832 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
833 the picture. With this option, \Verb+tikz+ becomes the \textit{drawing
834 engine}.
835 \item[scale = \meta{value} (default: 1cm):] The scale option defines
836 the scale at which the picture is drawn (the same for both
837 axes). It must contain the unit of length (cm,
838 pt, etc.).
839 \item[delaunay = none (default) \textme{or} show] This option
840 allows to draw the Delaunay triangulation under the Voronoi diagram.
841 \item[styleDelaunay = none (default) \textme{or} dashed] This option
842 allows to draw dashed lines for the Delaunay triangulation.
843 \item[styleVoronoi = none (default) \textme{or} dashed] This option
844 allows to draw dashed lines for the Voronoi edges.
845 \end{optionsenum}
846
847 \begin{Exemple}
848 \buildVoronoiBW[tikz,delaunay=show,styleDelaunay=dashed]
849 {(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)}
850 \end{Exemple}
851
852 \subsection{The \emph{inc} variant}
853
854 Once again, a variant of the macros is available allowing the user to
855 add code before and after the code produced by \luamesh. We refer to
856 the section~\ref{sec:inc} because it works the same way.
857
858 Let us note that:
859 \begin{itemize}
860 \item with MetaPost, the circumcenters are defined using
861 \Verb+pair CircumPoints[];+, and so, are accessible.
862 \item With \Verb+tikz+, there are new coordinates defined as follows
863 \begin{latexcode}
864 \coordinate (CircumPoints1) at (...,...);
865 \coordinate (CircumPoints2) at (...,...);
866 \coordinate (CircumPoints3) at (...,...);
867 % etc.
868 \end{latexcode}
869 \end{itemize}
870
871 Finally, when the MetaPost drawing engine is used, another color is
872 available (see~\ref{sec:mpcolor}): \Verb+\luameshmpcolorVoronoi+.
873
874
875 \section{With Gmsh}
876
877 Gmsh is a open source efficient software that produces meshes. The
878 exporting format is the \emph{MSH ASCII file format} and can be easily
879 read by a Lua program. \luamesh provides the user with dedicated
880 macros to read and draw meshes coming from a Gmsh exportation.\bigskip
881
882 \commande|\drawGmsh[«options»]{«file name»}|\medskip
883
884 This macro draw the triangulation produced by Gmsh and exported in the
885 \Verb+msh+ format. The argument is the name of the file to read
886 (e.g.: \Verb+maillage.msh+).
887
888 \begin{Exemple}
889 \drawGmsh{maillage.msh}
890 \end{Exemple}
891
892 There are several options to customize the drawing.
893 \begin{optionsenum}
894 \item[color = \meta{value} (default: black):] The color of the
895 drawing.
896 \item[print = none (default) \textme{or} points:] To label the vertices of the
897 triangulation. Contrary to the previous macros, where
898 \Verb+print=none+, a \emph{dot} is produced at each vertex (of the
899 set of points and on the circumcircle center which are the nodes of
900 the Voronoi diagram).
901 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
902 label the vertices of the triangulation. It is included in the math
903 mode delimiters \Verb+$...$+. The bounding box points are labeled
904 with numbers 1 to 4 and with a star exponent.
905 \item[tikz (boolean, default:false):] By default, this boolean is set
906 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
907 the picture. With this option, \Verb+tikz+ becomes the \textit{drawing
908 engine}.
909 \item[scale = \meta{value} (default: 1cm):] The scale option defines
910 the scale at which the picture is drawn (the same for both
911 axes). It must contain the unit of length (cm,
912 pt, etc.).
913 \end{optionsenum}
914 Here is an example:
915 \begin{Exemple}
916 \drawGmsh[scale=2cm,print=points, color=blue!30]{maillage.msh}
917 \end{Exemple}
918
919 \subsection{Gmsh and Voronoi Diagrams}
920
921 Because Gmsh generates Delaunay triangulations, we can plot the
922 Voronoi diagram associated. This is done by the following macro:\bigskip
923
924 \commande|\gmshVoronoi[«options»]{«file name»}|\medskip
925
926 \begin{Exemple}
927 \gmshVoronoi{maillage.msh}
928 \end{Exemple}
929
930
931 \subsection{The Options}\label{sec:voronoiOptions}
932
933
934 There are several options to customize the drawing.
935 \begin{optionsenum}
936 \item[color = \meta{value} (default: black):] The color of the
937 drawing.
938 \item[colorVoronoi = \meta{value} (default: black):] The color of the
939 drawing for the elements (points and polygons) belonging to the
940 Voronoi diagram.
941 \item[print = none (default) \textme{or} points:] To label the vertices of the
942 triangulation. Contrary to the previous macros, where
943 \Verb+print=none+, a \emph{dot} is produced at each vertex (of the
944 set of points and on the circumcircle center which are the nodes of
945 the Voronoi diagram).
946 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
947 label the vertices of the triangulation. It is included in the math
948 mode delimiters \Verb+$...$+. The bounding box points are labeled
949 with numbers 1 to 4 and with a star exponent.
950 \item[circumpoint = \meta{value} (default: P):] The letter(s) used to
951 label the vertices of the Voronoi diagram. It is included in the math
952 mode delimiters \Verb+$...$+.
953 \item[tikz (boolean, default:false):] By default, this boolean is set
954 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
955 the picture. With this option, \Verb+tikz+ becomes the \textit{drawing
956 engine}.
957 \item[scale = \meta{value} (default: 1cm):] The scale option defines
958 the scale at which the picture is drawn (the same for both
959 axes). It must contain the unit of length (cm,
960 pt, etc.).
961 \item[delaunay = none (default) \textme{or} show] This option
962 allows to draw the Delaunay triangulation under the Voronoi diagram.
963 \item[styleDelaunay = none (default) \textme{or} dashed] This option
964 allows to draw dashed lines for the Delaunay triangulation.
965 \item[styleVoronoi = none (default) \textme{or} dashed] This option
966 allows to draw dashed lines for the Voronoi edges.
967 \end{optionsenum}
968
969 \begin{Exemple}
970 \gmshVoronoi[tikz,scale=1.5cm, delaunay=show,styleVoronoi=dashed]{maillage.msh}
971 \end{Exemple}
972
973
974 \subsection{The \emph{inc} variants}
975
976 Once again, there exists \emph{inc} variant macros:\bigskip
977
978 \commande|\drawGmshinc[«options»]{«file name»}{«code before»}{«code after»}|\medskip
979
980 \commande|\gmshVoronoiinc[«options»]{«file name»}{«code before»}{«code after»}|\medskip
981
982 We refer to the previous sections for explanations.
983
984 \section{Gallery}
985 \subsection{With Animate}
986
987 If you use \emph{adobe acrobat reader}, you can easily produce an
988 animation of the Bowyer and Watson algorithm with the package
989 \Verb+animate+.
990
991 For example, the following code (in a file name \Verb+animation.tex+):
992 \begin{latexcode}
993 \documentclass{article}
994 %% lualatex compilation
995 \usepackage[margin=2.5cm]{geometry}
996 \usepackage{luamesh}
997 \usepackage{fontspec}
998 \usepackage{multido}
999 \pagestyle{empty}
1000 \def\drawPath{draw (-2,-2)*u--(8,-2)*u--(8,6)*u--(-2,6)*u--cycle withcolor 0.99white;}
1001 \def\clipPath{clip currentpicture to (-2,-2)*u--(8,-2)*u--(8,6)*u--(-2,6)*u--cycle;}
1002 \begin{document}
1003 \drawPointsMeshinc[mode=ext, bbox = show,colorBbox = blue!20,print=points]{mesh.txt}%
1004 {%
1005 beginfig(0);
1006 \drawPath
1007 }%
1008 {%
1009 \clipPath
1010 endfig;
1011 }
1012 \newpage\buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!20,print=points]{meshInit.txt}%
1013 {%
1014 beginfig(0);
1015 \drawPath
1016 }%
1017 {%
1018 \clipPath
1019 endfig;
1020 }
1021 \multido{\ii=5+1}{4}{%
1022 \newpage\meshAddPointBWinc[mode=ext,step=badtriangles,colorNew
1023 =green!20!red,colorBack=red!10,colorCircle = blue,bbox =
1024 show,colorBbox = blue!20]{mesh.txt}{\ii}%
1025 {%
1026 beginfig(0);
1027 \drawPath
1028 }%
1029 {%
1030 \clipPath
1031 endfig;
1032 } \newpage
1033 \meshAddPointBWinc[mode=ext,step=cavity,colorNew
1034 =green!20!red,colorBack=red!10,colorCircle = blue,bbox =
1035 show,colorBbox = blue!20]{mesh.txt}{\ii}%
1036 {%
1037 beginfig(0);
1038 \drawPath
1039 }%
1040 {%
1041 \clipPath
1042 endfig;
1043 } \newpage
1044 \meshAddPointBWinc[mode=ext,step=newtriangles,colorNew
1045 =green!20!red,colorBack=red!10,colorCircle = blue,bbox =
1046 show,colorBbox = blue!20]{mesh.txt}{\ii}%
1047 {%
1048 beginfig(0);
1049 \drawPath
1050 }%
1051 {%
1052 \clipPath
1053 endfig;
1054 }
1055 }
1056 \newpage
1057 \buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!20,print=points]{mesh.txt}%
1058 {%
1059 beginfig(0);
1060 \drawPath
1061 }%
1062 {%
1063 \clipPath
1064 endfig;
1065 }
1066 \newpage
1067 \buildMeshBWinc[mode=ext,print=points]{mesh.txt}%
1068 {%
1069 beginfig(0);
1070 \drawPath
1071 }%
1072 {%
1073 \clipPath
1074 endfig;
1075 }
1076 \end{document}
1077 \end{latexcode}
1078 produces a PDF with multiple pages. Using the \Verb+pdfcrop+ program,
1079 we crop the pages to the material, and then we can animate the PDF
1080 using the \Verb+animate+ package.
1081
1082 %\begin{Exemple}
1083 %\animategraphics[controls]{1}{animation-crop}{}{}
1084 %\end{Exemple}
1085
1086 \input{dum.bbl}
1087
1088 \end{document}
1089
1090
1091
1092 %%% Local Variables:
1093 %%% flyspell-mode: 1
1094 %%% ispell-local-dictionary: "american"
1095 %%% 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.