Doc: documentation des nouvelles macros (Voronoi, gmsh), tentative de mise en place...
[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,
71 drawPointsMeshinc, meshAddPointBW, meshAddPointBWinc}% frame=tb
72 }
73
74 \lstdefinelanguage{lua}
75 {morekeywords={for,end,function,do,if,else,elseif,then,
76 tex.print,tex.sprint,io.read,io.open,string.find,string.explode,require},
77 morecomment=[l]{--},
78 morecomment=[s]{--[[}{]]},
79 morestring=[b]''
80 }
81
82 \newtcblisting{Exemple}{%
83 arc=0pt,outer arc=0pt,
84 colback=red!2!white,
85 colframe=red!75!black,
86 breakable,
87 boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt, bottomtitle =
88 3pt, toptitle=3pt,
89 boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, toprule at break =
90 0pt, bottomrule at break = 0pt,
91 listing options={breaklines},
92 }
93
94 \newtcblisting{commandshell}{colback=black,colupper=white,colframe=black,
95 arc=0pt,
96 listing only,boxsep=0pt,listing
97 options={style=tcblatex,language=sh},
98 every listing line={\textcolor{red}{\small\ttfamily\bfseries user \$> }}}
99
100 \newtcblisting{latexcode}{
101 arc=0pt,outer arc=0pt,
102 colback=red!2!white,
103 colframe=red!75!black,
104 breakable,
105 boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt, bottomtitle =
106 3pt, toptitle=3pt,
107 boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, toprule at break =
108 0pt, bottomrule at break = 0pt,
109 listing only,boxsep=0pt,listing
110 options={breaklines}
111 }
112
113
114 \newcommand\luamesh{\Verb+luamesh+\xspace}
115
116 \newenvironment{optionsenum}[1][]
117 {\begin{description}[font=\color{darkred}\ttfamily]}
118 {\end{description}}
119
120 \newenvironment{warning}{%
121 \setlength{\logowidth}{24pt}
122 \tcbset{%
123 arc=0pt,outer arc=0pt,colback=gray!10!white,colframe=gray!60!white,
124 boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt, bottomtitle = 3pt, toptitle=3pt,
125 boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt}
126 \medskip
127 \begin{tcolorbox}%
128 \begin{wrapfigure}[2]{L}{17pt}%
129 % \raisebox{-5pt}{
130 \vspace*{-0.55cm}
131 \bcinfo
132 % }%
133 \end{wrapfigure}
134 }%
135 {\end{tcolorbox}\medskip}
136
137 \lstset{moredelim=*[s][\color{red}\rmfamily\itshape]{<}{>}}
138 \lstset{moredelim=*[s][\color{blue}\rmfamily\itshape]{<<}{>>}}
139 \usepackage[colorlinks=true]{hyperref}
140 \begin{document}
141 %% === Page de garde ===================================================
142 \thispagestyle{empty}
143 \begin{tikzpicture}[remember picture, overlay]
144 \node[below right, shift={(-4pt,4pt)}] at (current page.north west) {%
145 \includegraphics{fond.pdf}%
146 };
147 \end{tikzpicture}%
148
149 \noindent
150 \includegraphics{luamesh-title}\\
151 {\large compute and draw meshes with \lualatex}\\[1cm]
152 \parbox{0.6\textwidth}{
153 \meshAddPointBW[
154 mode=ext,step=badtriangles,
155 colorNew =green!20!red,
156 colorBack=red!10,
157 colorCircle = blue,
158 bbox = show,
159 colorBbox = black!30
160 ]
161 {meshgarde.txt}{7}
162 }\hfill
163 \parbox{0.4\textwidth}{\Large\raggedleft
164 \textbf{Contributor}\\
165 Maxime \textsc{Chupin}
166 }
167 \vfill
168 \begin{center}
169 Version 0.1, 25 novembre 2016\\
170 \url{http://melusine.eu.org/syracuse/G/delaunay/}
171 \end{center}
172 %% == Page de garde ====================================================
173 \newpage
174
175 \maketitle
176
177 \begin{abstract}
178 The package \Verb|luamesh| allows to compute and draw 2D Delaunay
179 triangulation. The algorithm is written with lua, and depending on the
180 choice of the ``engine'', the drawing is done by MetaPost (with
181 \Verb|luamplib|) or by \Verb|tikz|.
182
183 The Delaunay triangulation algorithm is the Bowyer and Watson
184 algorithm. Several macros are provided to draw the global mesh, the
185 set of points, or a particular step of the algorithm.
186 \end{abstract}
187
188 I would like to thank Jean-Michel Sarlat, who hosts the development
189 with a git project on the \Verb+melusine+ machine:
190 \begin{center}
191 \url{https://melusine.eu.org/syracuse/G/delaunay/}
192 \end{center}
193 I would also like to thank the first user, an intensive
194 \emph{test} user, and a very kind English corrector: Nicole Spillane.
195
196 \tableofcontents
197
198 \section{Installation}
199
200
201 Of course, you can just put the two files \Verb+luamesh.lua+ and
202 \Verb+luamesh.sty+ in the working directory, but this is not
203 recommended.
204
205
206 \subsection{With \TeX live and Linux or Mac OSX}
207
208 To install \luamesh with \TeX live, you have to create the local
209 \Verb+texmf+ directory in your \Verb+home+.
210
211 \begin{commandshell}
212 mkdir ~/texmf
213 \end{commandshell}
214
215 Then place the files in the correct directories. First, the
216 \Verb+luamesh.sty+ file must be in the directory:
217 \begin{center}
218 \Verb+~/texmf/tex/latex/luamesh/+
219 \end{center}
220 and secondly, the \Verb+luamesh.lua+ must be in the directory:
221 \begin{center}
222 \Verb+~/texmf/scripts/luamesh/+
223 \end{center}
224
225 Once you have done this, \luamesh can be included in your document
226 with
227 \begin{latexcode}
228 \usepackage{luamesh}
229 \end{latexcode}
230
231 \subsection{With Mik\TeX{} and Windows}
232
233 We do not know these two systems, so we refer to the
234 documentation for integrating local additions to Mik\TeX:
235 \begin{center}
236 \url{http://docs.miktex.org/manual/localadditions.html}
237 \end{center}
238
239
240 \subsection{A \lualatex package}
241
242 If you want to use this package, you must compile your document with
243 \Verb+lualatex+:
244
245 \begin{commandshell}
246 lualatex mylatexfile.tex
247 \end{commandshell}
248
249
250 \subsection{Dependencies}
251
252 This package is built upon two main existing packages to draw the
253 triangulations :
254 \begin{enumerate}
255 \item \Verb+luamplib+ to use MetaPost via the \luatex library
256 \Verb+mplib+;
257 \item and \Verb+tikz+.
258 \end{enumerate}
259 We will see how to choose between these two \emph{drawing engines}.
260
261 Moreover, the following packages are necessary:
262 \begin{enumerate}
263 \item \Verb+xkeyval+ to manage the optional arguments;
264 \item \Verb+xcolor+ to use colors (needed by \Verb+luamplib+);
265 \item \Verb+ifthen+ to help the programming with \TeX.
266 \end{enumerate}
267
268
269 \section{The Basic Macros}
270
271 Let us recall that this package provides macros to draw two
272 dimensional triangulations (or meshes).
273
274 \subsection{Draw a Complete Mesh}\label{sec:buildMesh}
275
276 \commande|\buildMeshBW[«options»]{«list of points» or «file name»}|\medskip
277
278 This macro produces the Delaunay triangulation (using the Bowyer and
279 Watson algorithm) of the given \meta{list of points}. The list of
280 points must be given in the following way :
281 \begin{center}
282 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
283 \end{center}
284
285 \begin{Exemple}
286 \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)}
287 \end{Exemple}
288
289 \subsubsection{The Options}
290
291 There are several options to customize the drawing.
292 \begin{optionsenum}
293 \item[mode = int (default) \textme{or} ext:] this option allows to
294 use either the previously described set of points in the argument, or
295 a file, containing, line by line (2 columns), the points. Such a
296 file looks like :
297 \begin{verbatim}
298 x1 y1
299 x2 y2
300 x3 y3
301 ...
302 xn yn
303 \end{verbatim}
304 \item[bbox = none (default) \textme{or} show:] this option allows to draw the
305 added points to form a \emph{bounding box}\footnote{The bounding
306 box is defined by four points place at 15\% around the box
307 defined by $(x_{\min},y_{\min})$, $(x_{\min},y_{\max})$,
308 $(x_{\max},y_{\max})$, and $(x_{\min},y_{\max})$. It is used by
309 the algorithm and will be computed in any case.} and the corresponding
310 triangulation. By default, these triangles are removed at the end of
311 the algorithm.
312 \item[color = \meta{value} (default: black):] The color of the
313 drawing.
314 \item[colorBbox = \meta{value} (default: black):] The color of the
315 drawing for the elements (points and triangles) belonging to the
316 bounding box.
317 \item[print = none (default) \textme{or} points:] To label the vertices of the
318 triangulation. This also adds a \emph{dot} at each vertex.
319 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
320 label the vertices of the triangulation. It is included in the math
321 mode delimiters \Verb+$...$+. The bounding box points are labeled
322 with numbers 1 to 4 and with a star exponent.
323 \item[tikz (boolean, default:false):] By default, this boolean is set
324 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
325 the picture. With this option, \Verb+tikz+ becomes the \textit{drawing
326 engine}.
327 \item[scale = \meta{value} (default: 1cm):] The scale option defines
328 the scale at which the picture is drawn (the same for both
329 axes). It must contain the unit of length (cm,
330 pt, etc.).
331 \end{optionsenum}
332
333 To illustrate the options, let us show you an example. We consider a
334 file \Verb+mesh.txt+:
335 \begin{verbatim}
336 0.3 0.3
337 1.5 1
338 4 0
339 4.5 2.5
340 1.81 2.14
341 2.5 0.5
342 2.8 1.5
343 \end{verbatim}
344 \begin{Exemple}
345 \buildMeshBW[%
346 tikz,
347 mode = ext,
348 bbox = show,
349 color = red,
350 colorBbox = blue!30,
351 print = points,
352 meshpoint = x,
353 scale = 1.3cm,
354 ]{mesh.txt}
355 \end{Exemple}
356
357 \begin{warning}
358 The drawing engine is not very relevant here, but it is useful to
359 understand how the drawing is made. However, the engine will be
360 relevant to
361 the so called \emph{inc} macros (section~\ref{sec:inc}), for adding
362 code before and after the one generated by
363 \luamesh.
364 \end{warning}
365
366 \subsection{Draw the Set of Points}
367
368 \commande|\drawPointsMesh[«options»]{«list of points» or «file name»}|\medskip
369
370 With the \Verb+\drawPointsMesh+, we plot the set of (user chosen) points from
371 which the Bowyer and Watson algorithm computes the triangulation.
372
373 The use of this macro is quite similar to
374 \Verb+\buildMeshBW+. Here is an example of the basic uses.
375 \begin{Exemple}
376 \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)}
377 \end{Exemple}
378
379
380 \subsubsection{The Options}
381
382 There are several options (exactly the same as for the
383 \Verb+\buildMeshBW+) to customize the drawing.
384 \begin{optionsenum}
385 \item[mode = int (default) \textme{or} ext:] this option allows to
386 use either the previously described set of points as the argument, or
387 a file, containing, line by line (2 columns), the points. Such a
388 file looks like :
389 \begin{verbatim}
390 x1 y1
391 x2 y2
392 x3 y3
393 ...
394 xn yn
395 \end{verbatim}
396 \item[bbox = none (default) \textme{or} show:] this option allows to draw the
397 added points to form a \emph{bounding box} and the corresponding
398 triangulation. By default, these triangles are removed at the end of
399 the algorithm. \emph{Here, because we plot only the vertices of the
400 mesh, there are no triangles, only dots.}
401 \item[color = \meta{value} (default: black):] The color of the
402 drawing.
403 \item[colorBbox = \meta{value} (default: black):] The color of the
404 drawing for the elements (points and triangles) belonging to the
405 bounding box.
406 \item[print = none (default) \textme{or} points:] To label the vertices of the
407 triangulation. This also adds a \emph{dot} at each vertex. Without
408 label, there is still the dot.
409 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
410 label the vertices of the triangulation. It is included in the math
411 mode delimiters \Verb+$...$+. The bounding box points are labeled
412 with numbers 1 to 4 and with a star exponent.
413 \item[tikz (boolean, default:false):] By default, this boolean is set
414 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
415 the picture. With this option, \Verb+tikz+ becomes the \textit{drawing
416 engine}.
417 \item[scale = \meta{value} (default: 1cm):] The scale option defines
418 the scale at which the picture is drawn (the same for both
419 axes). It must contain the unit of length (cm,
420 pt, etc.).
421 \end{optionsenum}
422 With the same external mesh point file presented in
423 section~\ref{sec:buildMesh}, we illustrate the different options.
424
425 \begin{Exemple}
426 \drawPointsMesh[%
427 tikz,
428 mode = ext,
429 bbox = show,
430 color = blue,
431 colorBbox = red,
432 print = points,
433 meshpoint = y,
434 scale = 1.3cm,
435 ]{mesh.txt}
436 \end{Exemple}
437
438
439 \subsection{Draw a Step of the Bowyer and Watson Algorithm}
440
441 \commande|\meshAddPointBW[«options»]{«list of points» or «file name»}{«point» or «number of line»}|\medskip
442
443 This command allows to plot the steps within the addition of a
444 point in a Delaunay triangulation, by the Bowyer and Watson
445 algorithm.
446
447 This macro produces the Delaunay triangulation (using the Bowyer and
448 Watson algorithm) of the given \meta{list of points} and shows a step
449 of the algorithm when the \meta{point} is added. The list of
450 points must be given in the following way:
451 \begin{center}
452 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
453 \end{center}
454 and the point is of the form \verb+(x,y)+. The \meta{file name}
455 and \meta{number of line} will be explained in the option
456 description.
457
458 One can use the macro as fallows:
459 \begin{Exemple}
460 \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)}
461 \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)}
462 \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)}
463 \end{Exemple}
464 The default value for \Verb+step+ is
465 \Verb+badtriangles+. Consequently, the first
466 line is equivalent to
467 \begin{latexcode}
468 \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)}
469 \end{latexcode}
470
471 \subsubsection{The Options}
472
473 There are several options (some of them are the same as for
474 \Verb+\buildMeshBW+) to customize the drawing.
475 \begin{optionsenum}
476 \item[mode = int (default) \textme{or} ext:] this option allows to
477 use either the previously described set of point in the first
478 argument, or
479 a file containing, line by line (2 columns), the points. Such a
480 file looks like :
481 \begin{verbatim}
482 x1 y1
483 x2 y2
484 x3 y3
485 ...
486 xn yn
487 \end{verbatim}
488 For the second argument of the macro, if we are in the
489 \Verb+mode = ext+, the argument must be the \emph{line number} of the file
490 corresponding to the point we want to add. The algorithm will stop the
491 line before to build the initial triangulation for which it will add
492 the point corresponding to the line. The subsequent lines in the file are
493 ignored.
494 \item[bbox = none (default) \textme{or} show:] this option allows to draw the
495 added points to form a \emph{bounding box} and the corresponding
496 triangulation. By default, these triangles are removed at the end of
497 the algorithm.
498 \item[color = \meta{value} (default: black):] The color of the
499 drawing.
500 \item[colorBbox = \meta{value} (default: black):] The color of the
501 drawing for the elements (points and triangles) belonging to the
502 bounding box.
503 \item[colorNew = \meta{value} (default: red):] The color of the
504 drawing of the ``new'' elements which are the point to add, the
505 polygon of the cavity, and the new triangles.
506 \item[colorBack = \meta{value} (default: black!20):] The color for the
507 filling of the region concerned by the addition of the new point.
508 \item[colorCircle = \meta{value} (default: green):] The color for
509 the circumcircle of the triangles containing the point to add.
510 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
511 label the vertices of the triangulation. It is included in the math
512 mode delimiters \Verb+$...$+. The bounding box points are labeled
513 with numbers 1 to 4 and with a star exponent.
514 \item[step = badtriangles (default) \textme{or} cavity \textme{or}
515 newtriangles:] To choose the step we want to draw, corresponding to
516 the steps of the Bowyer and Watson algorithm.
517 \item[newpoint = \meta{value} (default: P):] The letter(s) used to
518 label the new point of the triangulation. It is include in the math
519 mode delimiters \Verb+$...$+.
520 \item[tikz (boolean, default:false):] By default, this boolean is set
521 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
522 the picture. With this option, \Verb+tikz+ is the \textit{drawing
523 engine}.
524 \item[scale = \meta{value} (default: 1cm):] The scale option defines
525 the scale at which the picture is draw (the same for the two
526 axis). It must contain the unit of length (cm,
527 pt, etc.).
528 \end{optionsenum}
529
530 Here is an example of customizing the drawing. First, recall that
531 the external file \Verb+mesh.txt+ is:
532 \begin{verbatim}
533 0.3 0.3
534 1.5 1
535 4 0
536 4.5 2.5
537 1.81 2.14
538 2.5 0.5
539 2.8 1.5
540 \end{verbatim}
541 We draw the addition of the 6th point. The 7th line will be ignored.
542 \begin{Exemple}
543 \meshAddPointBW[
544 tikz,
545 mode = ext,
546 color = blue!70,
547 meshpoint = \alpha,
548 newpoint = y,
549 colorBack=red!10,
550 colorNew = green!50!red,
551 colorCircle = blue,
552 colorBbox = black!20,
553 bbox = show,
554 scale=1.4cm,
555 step=badtriangles]
556 {mesh.txt}{6}
557 \end{Exemple}
558
559 \section{The \emph{inc} Macros}\label{sec:inc}
560
561 The three macros presented in the above sections have complementary
562 macros, with the suffix \Verb+inc+ that allow the user to add code
563 (MetaPost or \Verb+tikz+, depending of the drawing engine) before and
564 after the code generated by \luamesh.
565
566 The three macros are:\medskip
567
568
569 \commande|\buildMeshBWinc[«options»]{«list of points» or «file name»}{«code before»}{«code after»}|\medskip
570
571 \commande|\drawPointsMeshinc[«options»]{«list of points» or «file name»}{«code before»}{«code after»}|\medskip
572
573 \commande|\meshAddPointBWinc[«options»]{«list of points» or «file name»}%|
574
575 \commande| {«point» or «number of line»}{«code before»}{«code after»}|\medskip
576
577 \subsection{With MetaPost}
578
579 We consider the case where the drawing engine is MetaPost (through the
580 \Verb+luamplib+ package).
581
582 We describe the feature taking one macro in example but the mechanism
583 and the possibilities are exactly the same for all the macros.
584
585 When we use the MetaPost drawing engine, the macros previously
586 described produced a code of the form
587 \begin{latexcode}
588 \begin{luamplib}
589 u:=<scale>;
590 beginfig(0);
591 <code for the drawing>
592 endfig;
593 \end{luamplib}
594 \end{latexcode}
595
596 Then, the arguments \meta{code before} and \meta{code after} are
597 inserted as follows:
598 \begin{latexcode}
599 \begin{luamplib}
600 u:=<scale>;
601 <<code before>>
602 <code for the drawing>
603 <<code after>>
604 \end{luamplib}
605 \end{latexcode}
606 \begin{warning}
607 With the \emph{inc} macros, the user has to add the \Verb+beginfig();+
608 and \Verb+endfig;+ commands to produce a picture. Indeed, this allows
609 to use the \Verb+\everymplib+ command from the \Verb+\luamplib+ package.
610 \end{warning}
611
612 \subsubsection{The \LaTeX{} Colors Inside the MetaPost Code}\label{sec:mpcolor}
613
614 The configurable colors
615 of the \LaTeX{} macro are accessible inside the MetaPost code. For
616 \Verb+\buildMeshBWinc+ and \Verb+\drawPointsMeshinc+, we have
617 \Verb+\luameshmpcolor+,
618 and \Verb+\luameshmpcolorBbox+.
619 For the macro \Verb+\meshAddPointBWinc+ we have three additional
620 colors : \Verb+\luameshmpcolorBack+, \Verb+\luameshmpcolorNew+, and
621 \Verb+\luameshmpcolorCircle+. Of course, we can define MetoPost
622 colors as well. Finally, the \Verb+luamplib+ mechanism of
623 \Verb+\mpcolor+ is also available.
624
625 \subsubsection{The Mesh Points}
626
627 At the beginning of the automatically generated code, a list of
628 MetaPost \Verb+pair+s are defined corresponding to all the vertices of
629 the mesh (when the option \Verb+bbox=show+, the last 4 points are the
630 \emph{bounding box points}). The points are available with the
631 \Verb+MeshPoints[]+ table of variables. The \Verb+MeshPoints[i]+ are
632 defined using the unit length \Verb+u+.
633
634 \subsubsection{Examples}
635
636 Here is three examples for the different macros.
637 \begin{Exemple}
638 \drawPointsMeshinc[
639 color = blue!50,
640 print = points,
641 meshpoint = x,
642 scale=0.8cm,
643 ]{(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)}%
644 {% code before
645 beginfig(0);
646 }%
647 {% code after
648 label(btex Mesh $\mathbb{T}$ etex, (0,2u)) withcolor \luameshmpcolor;
649 endfig;
650 }
651 \buildMeshBWinc[%
652 bbox = show,
653 color = red,
654 colorBbox = blue!30,
655 print = points,
656 meshpoint = x,
657 scale=0.8cm
658 ]{(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)}%
659 {% code before
660 beginfig(0);
661 }
662 {% code after
663 drawdblarrow MeshPoints[3] -- MeshPoints[9] withpen pencircle scaled 1pt
664 withcolor (0.3,0.7,0.2);
665 endfig;
666 }
667 \meshAddPointBWinc[
668 meshpoint = \alpha,
669 newpoint = y,
670 colorBack=red!10,
671 colorNew = green!50!red,
672 colorCircle = blue,
673 colorBbox = black!20,
674 bbox = show,
675 scale=0.8cm,
676 step=badtriangles]
677 {(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)}%
678 {%code before
679 picture drawing;
680 drawing := image(
681 }{%code after
682 );
683 beginfig(0);
684 fill MeshPoints[7]--MeshPoints[8]--MeshPoints[9]--MeshPoints[10]--cycle
685 withcolor \mpcolor{blue!10};
686 draw drawing;
687 endfig;
688 }
689 \end{Exemple}
690 \begin{warning}
691 The variables \Verb+MeshPoints[]+ are not defined for the argument
692 corresponding to the code to place before the code generated by
693 \luamesh. Hence, to use such variables, we have to define a
694 \Verb+picture+ as shown in the third example above.
695 \end{warning}
696
697
698 \subsection{With TikZ}
699
700 If we have chosen \Verb+tikz+ as the engine drawing, the added code
701 will be written in \Verb+tikz+. In that case, the two arguments
702 \meta{code before} and \meta{code after} will be inserted as follows:
703 \begin{latexcode}
704 \noindent
705 \begin{tikzpicture}[x=<scale>,y=<scale>]
706 <<code before>>
707 <generated code>
708 <<code after>>
709 \end{tikzpicture}
710 \end{latexcode}
711
712 Because the engine is \Verb+tikz+ their is no issue with colors, the
713 \LaTeX{} colors (e.g.: \Verb+xcolor+) can be directly used.
714
715 \subsubsection{The Mesh Points}
716
717 The points of the mesh are defined here as \Verb+tikz+
718 \Verb+\coordinate+ named as follows
719 \begin{latexcode}
720 \coordinate (MeshPoints1) at (...,...);
721 \coordinate (MeshPoints2) at (...,...);
722 \coordinate (MeshPoints3) at (...,...);
723 %etc.
724 \end{latexcode}
725
726 Once again these coordinates are not yet defined for the \meta{code
727 before} argument.
728
729 \subsubsection{Examples}
730
731 \begin{Exemple}
732 \drawPointsMeshinc[
733 tikz,
734 color = blue!50,
735 print = points,
736 meshpoint = x,
737 scale=0.8cm,
738 ]{(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)}%
739 {% code before
740 }%
741 {% code after
742 \node[color = blue!50] at (0,2) {Mesh $\mathbb{T}$} ;
743 }
744 \buildMeshBWinc[%
745 tikz,
746 bbox = show,
747 color = red,
748 colorBbox = blue!30,
749 print = points,
750 meshpoint = x,
751 scale=0.8cm
752 ]{(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)}%
753 {% code before
754 }
755 {% code after
756 \draw[<->,thick, color=green] (MeshPoints3) -- (MeshPoints9);
757 }
758 \end{Exemple}
759
760 \section{Voronio Diagrams}
761
762 Another interesting concept of Delaunay triangulation is that it is
763 \emph{dual} to it so-called Voronio diagram. For a finite set of
764 points $\{p_{1},\ldots, p_{n}\}$ in the Euclidean plane, for all
765 $p_{k}$, it corresponds a Voronoi cell $R_{k}$ consisting of
766 every point in the Euclidean plane whose distance to $p_{k}$ is less
767 than
768 or equal to its distance to any other $p_{k'}$.\bigskip
769
770
771 \commande|\buildVoronoiBW[«options»]{«list of points» or «file name»}|\medskip
772
773 This macro produce the Voronio diagram dual to the Delaunay
774 triangulation (computed by the Bowyer and Watson
775 algorithm) of the given \meta{list of points}. Once again, the
776 list of
777 points must be given in the following way :
778 \begin{center}
779 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
780 \end{center}
781
782 \begin{Exemple}
783 \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)}
784 \end{Exemple}
785
786 \subsection{The Options}\label{sec:voronoiOptions}
787
788
789 There are several options to customize the drawing.
790 \begin{optionsenum}
791 \item[mode = int (default) \textme{or} ext:] this option allows to
792 use either the previously described set of points in the argument, or
793 a file, containing, line by line (2 columns), the points. Such a
794 file looks like :
795 \begin{verbatim}
796 x1 y1
797 x2 y2
798 x3 y3
799 ...
800 xn yn
801 \end{verbatim}
802 \item[bbox = none (default) \textme{or} show:] this option allows to draw the
803 added points to form a \emph{bounding box}\footnote{The bounding
804 box is defined by four points place at 15\% around the box
805 defined by $(x_{\min},y_{\min})$, $(x_{\min},y_{\max})$,
806 $(x_{\max},y_{\max})$, and $(x_{\min},y_{\max})$. It is used by
807 the algorithm and will be computed in any case.} and the corresponding
808 triangulation. By default, these points are removed at the end of
809 the algorithm.
810 \item[color = \meta{value} (default: black):] The color of the
811 drawing.
812 \item[colorBbox = \meta{value} (default: black):] The color of the
813 drawing for the elements (points and triangles) belonging to the
814 bounding box.
815 \item[colorVoronoi = \meta{value} (default: black):] The color of the
816 drawing for the elements (points and polygons) belonging to the
817 Voronoi diagram.
818 \item[print = none (default) \textme{or} points:] To label the vertices of the
819 triangulation. Contrary to the previous macros, where
820 \Verb+print=none+, a \emph{dot} is produced at each vertex (of the
821 set of points and on the circumcircle center which are the nodes of
822 the Voronoi diagram).
823 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
824 label the vertices of the triangulation. It is included in the math
825 mode delimiters \Verb+$...$+. The bounding box points are labeled
826 with numbers 1 to 4 and with a star exponent.
827 \item[circumpoint = \meta{value} (default: P):] The letter(s) used to
828 label the vertices of the Voronoi diagram. It is included in the math
829 mode delimiters \Verb+$...$+.
830 \item[tikz (boolean, default:false):] By default, this boolean is set
831 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
832 the picture. With this option, \Verb+tikz+ becomes the \textit{drawing
833 engine}.
834 \item[scale = \meta{value} (default: 1cm):] The scale option defines
835 the scale at which the picture is drawn (the same for both
836 axes). It must contain the unit of length (cm,
837 pt, etc.).
838 \end{optionsenum}
839
840
841 \subsection{The \emph{inc} variant}
842
843 Once again, a variant of the macros is available allowing the user to
844 add code before and after the code produced by \luamesh. We refer to
845 the section~\ref{sec:inc} because it works the same way.
846
847 Let us note that:
848 \begin{itemize}
849 \item with MetaPost, the circumcenters are defined using
850 \Verb+pair CircumPoints[];+, and so, are accessible.
851 \item With \Verb+tikz+, there are new coordinates defined as follows
852 \begin{latexcode}
853 \coordinate (CircumPoints1) at (...,...);
854 \coordinate (CircumPoints2) at (...,...);
855 \coordinate (CircumPoints3) at (...,...);
856 % etc.
857 \end{latexcode}
858 \end{itemize}
859
860 Finally, when the MetaPost drawing engine is used, another color is
861 available (see~\ref{sec:mpcolor}): \Verb+\luameshmpcolorVoronoi+.
862
863
864 \section{With Gmsh}
865
866 Gmsh is a open source efficient software that produces meshes. The
867 exporting format is the \emph{MSH ASCII file format} and can be easily
868 read by a Lua program. \luamesh provides the user with dedicated
869 macros to read and draw meshes coming from a Gmsh exportation.\bigskip
870
871 \commande|\drawGmsh[«options»]{«file name»}|\medskip
872
873 This macro draw the triangulation produced by Gmsh and exported in the
874 \Verb+msh+ format. The argument is the name of the file to read
875 (e.g.: \Verb+maillage.msh+).
876
877 \begin{Exemple}
878 \drawGmsh{maillage.msh}
879 \end{Exemple}
880
881 There are several options to customize the drawing.
882 \begin{optionsenum}
883 \item[color = \meta{value} (default: black):] The color of the
884 drawing.
885 \item[print = none (default) \textme{or} points:] To label the vertices of the
886 triangulation. Contrary to the previous macros, where
887 \Verb+print=none+, a \emph{dot} is produced at each vertex (of the
888 set of points and on the circumcircle center which are the nodes of
889 the Voronoi diagram).
890 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
891 label the vertices of the triangulation. It is included in the math
892 mode delimiters \Verb+$...$+. The bounding box points are labeled
893 with numbers 1 to 4 and with a star exponent.
894 \item[tikz (boolean, default:false):] By default, this boolean is set
895 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
896 the picture. With this option, \Verb+tikz+ becomes the \textit{drawing
897 engine}.
898 \item[scale = \meta{value} (default: 1cm):] The scale option defines
899 the scale at which the picture is drawn (the same for both
900 axes). It must contain the unit of length (cm,
901 pt, etc.).
902 \end{optionsenum}
903 Here is an example:
904 \begin{Exemple}
905 \drawGmsh[scale=2cm,print=points, color=blue!30]{maillage.msh}
906 \end{Exemple}
907
908 \subsection{Gmsh and Voronoi Diagrams}
909
910 Because Gmsh generates Delaunay triangulations, we can plot the
911 Voronoi diagram associated. This is done by the following macro:\bigskip
912
913 \commande|\gmshVoronoi[«options»]{«file name»}|\medskip
914
915 \begin{Exemple}
916 \gmshVoronoi{maillage.msh}
917 \end{Exemple}
918
919 We refer to the section~\ref{sec:voronoiOptions} for the list of the options.
920
921 \subsection{The \emph{inc} variants}
922
923 Once again, there exists \emph{inc} variant macros:\bigskip
924
925 \commande|\drawGmshinc[«options»]{«file name»}{«code before»}{«code after»}|\medskip
926
927 \commande|\gmshVoronoiinc[«options»]{«file name»}{«code before»}{«code after»}|\medskip
928
929 We refer to the previous sections for explanations.
930
931 \section{Gallery}
932 \subsection{With Animate}
933
934 If you use \emph{adobe acrobat reader}, you can easily produce an
935 animation of the Bowyer and Watson algorithm with the package
936 \Verb+animate+.
937
938 For example, the following code (in a file name \Verb+animation.tex+):
939 \begin{latexcode}
940 \documentclass{article}
941 %% lualatex compilation
942 \usepackage[margin=2.5cm]{geometry}
943 \usepackage{luamesh}
944 \usepackage{fontspec}
945 \usepackage{multido}
946 \pagestyle{empty}
947
948 \def\drawPath{draw (-2,-2)*u--(8,-2)*u--(8,6)*u--(-2,6)*u--cycle withcolor 0.99white;}
949 \def\clipPath{clip currentpicture to (-2,-2)*u--(8,-2)*u--(8,6)*u--(-2,6)*u--cycle;}
950
951 \begin{document}
952
953 \drawPointsMeshinc[
954 mode=ext,
955 bbox = show,
956 colorBbox = blue!20,
957 print=points
958 ]
959 {mesh.txt}%
960 {%
961 beginfig(0);
962 \drawPath
963 }%
964 {%
965 \clipPath
966 endfig;
967 }
968 \newpage
969 \buildMeshBWinc[
970 mode=ext,
971 bbox = show,
972 colorBbox = blue!20,
973 print=points
974 ]
975 {meshInit.txt}%
976 {%
977 beginfig(0);
978 \drawPath
979 }%
980 {%
981 \clipPath
982 endfig;
983 }
984 \multido{\ii=5+1}{4}{%
985 \newpage
986 \meshAddPointBWinc[
987 mode=ext,step=badtriangles,
988 colorNew =green!20!red,
989 colorBack=red!10,
990 colorCircle = blue,
991 bbox = show,
992 colorBbox = blue!20
993 ]
994 {mesh.txt}{\ii}%
995 {%
996 beginfig(0);
997 \drawPath
998 }%
999 {%
1000 \clipPath
1001 endfig;
1002 } \newpage
1003 \meshAddPointBWinc[
1004 mode=ext,step=cavity,
1005 colorNew =green!20!red,
1006 colorBack=red!10,
1007 colorCircle = blue,
1008 bbox = show,
1009 colorBbox = blue!20
1010 ]
1011 {mesh.txt}{\ii}%
1012 {%
1013 beginfig(0);
1014 \drawPath
1015 }%
1016 {%
1017 \clipPath
1018 endfig;
1019 } \newpage
1020 \meshAddPointBWinc[
1021 mode=ext,step=newtriangles,
1022 colorNew =green!20!red,
1023 colorBack=red!10,
1024 colorCircle = blue,
1025 bbox = show,
1026 colorBbox = blue!20]
1027 {mesh.txt}{\ii}%
1028 {%
1029 beginfig(0);
1030 \drawPath
1031 }%
1032 {%
1033 \clipPath
1034 endfig;
1035 }
1036 }
1037 \newpage
1038 \buildMeshBWinc[
1039 mode=ext,
1040 bbox = show,
1041 colorBbox = blue!20,
1042 print=points
1043 ]
1044 {mesh.txt}%
1045 {%
1046 beginfig(0);
1047 \drawPath
1048 }%
1049 {%
1050 \clipPath
1051 endfig;
1052 }
1053 \newpage
1054 \buildMeshBWinc[
1055 mode=ext,
1056 print=points
1057 ]
1058 {mesh.txt}%
1059 {%
1060 beginfig(0);
1061 \drawPath
1062 }%
1063 {%
1064 \clipPath
1065 endfig;
1066 }
1067 \end{document}
1068 \end{latexcode}
1069 produces a PDF with multiple pages. Using the \Verb+pdfcrop+ program,
1070 we crop the pages to the material, and then we can animate the PDF
1071 using the \Verb+animate+ package.
1072
1073 %\begin{Exemple}
1074 %\animategraphics[controls]{1}{animation-crop}{}{}
1075 %\end{Exemple}
1076
1077 \input{dum.bbl}
1078
1079 \end{document}
1080
1081
1082
1083 %%% Local Variables:
1084 %%% flyspell-mode: 1
1085 %%% ispell-local-dictionary: "american"
1086 %%% 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.