1 % luamesh: compute and draw meshes with lua, luamplib and tikz
3 % Originally written by Maxime Chupin <mc@melusine.eu.org>,
6 % Distributed under the terms of the GNU free documentation licence:
7 % http://www.gnu.org/licenses/fdl.html
8 % without any invariant section or cover text.
10 \documentclass{lltxdoc
}
11 \usepackage{tcolorbox
}
13 \usepackage[tikz
]{bclogo
}
17 \title{\Verb+luamesh+: compute and draw meshes with
\lualatex}
18 \author{Maxime Chupin
\email{mc@melusine.eu.org
}}
22 \definecolor{darkred
}{rgb
}{0.8,
0.1,
0.1}
25 \newcommand*
\commande{\noindent\hspace{-
30pt
}%
26 \SaveVerb[aftersave=
{%
31 \newcommand*
\textme[1]{\textcolor{black
}{\rmfamily\textit{#1}}}
32 \newcommand*
\meta[1]{% % meta
33 \textme{\ensuremath{\langle}#1\ensuremath{\rangle}}}
34 \newcommand*
\optstar{% % optional star
35 \meta{\ensuremath{*
}}\xspace}
37 \newcommand\R{\mathbf{R
}}
38 \setlength{\fboxsep}{2pt
}
40 codes=
{\catcode`\«
\active \catcode`\×
\active },
41 defineactive=
{\makefancyog\makefancytimes},
42 formatcom=
\color{darkred
},
45 % rendre «...» équivalent à \meta{...}
47 \newcommandx\makefancyog[0][addprefix=
\global]{%
48 \def«#
#1»
{\meta{#
#1}}}}
49 % rendre × équivalent à \optstar
51 \newcommandx\makefancytimes[0][addprefix=
\global]{%
55 \tcbuselibrary{listings,breakable
}
57 \definecolor{vert
}{rgb
}{0.1,
0.4,
0.1}
58 \definecolor{bleu
}{rgb
}{0.1,
0.1,
0.4}
60 numberstyle=
\footnotesize\color{vert
},
61 keywordstyle=
\ttfamily\bfseries\color{blue
},
62 basicstyle=
\ttfamily\footnotesize,
63 commentstyle=
\itshape\color{vert
},
64 stringstyle=
\ttfamily,
65 showstringspaces=false,
69 defaultdialect=
[LaTeX
]TeX,
70 morekeywords=
{buildMeshBW,buildMeshBWinc,drawPointsMesh,buildVoronoiBW,buildVoronoiBWinc,
71 drawPointsMeshinc, meshAddPointBW,
72 meshAddPointBWinc,drawGmsh,drawGmshinc,gmshVoronoi,gmshVoronoiinc
}% frame=tb
75 \lstdefinelanguage{lua
}
76 {morekeywords=
{for,end,function,do,if,else,elseif,then,
77 tex.print,tex.sprint,io.read,io.open,string.find,string.explode,require
},
79 morecomment=
[s
]{--
[[}{]]},
83 \newtcblisting{Exemple
}{%
84 arc=
0pt,outer arc=
0pt,
86 colframe=red!
75!black,
88 boxsep=
0pt,left=
5pt,right=
5pt,top=
5pt,bottom=
5pt, bottomtitle =
90 boxrule=
0pt,bottomrule=
0.5pt,toprule=
0.5pt, toprule at break =
91 0pt, bottomrule at break =
0pt,
92 listing options=
{breaklines
},
95 \newtcblisting{commandshell
}{colback=black,colupper=white,colframe=black,
97 listing only,boxsep=
0pt,listing
98 options=
{style=tcblatex,language=sh
},
99 every listing line=
{\textcolor{red
}{\small\ttfamily\bfseries user \$>
}}}
101 \newtcblisting{latexcode
}{
102 arc=
0pt,outer arc=
0pt,
104 colframe=red!
75!black,
106 boxsep=
0pt,left=
5pt,right=
5pt,top=
5pt,bottom=
5pt, bottomtitle =
108 boxrule=
0pt,bottomrule=
0.5pt,toprule=
0.5pt, toprule at break =
109 0pt, bottomrule at break =
0pt,
110 listing only,boxsep=
0pt,listing
115 \newcommand\luamesh{\Verb+luamesh+
\xspace}
117 \newenvironment{optionsenum
}[1][]
118 {\begin{description
}[font=
\color{darkred
}\ttfamily]}
121 \newenvironment{warning
}{%
122 \setlength{\logowidth}{24pt
}
124 arc=
0pt,outer arc=
0pt,colback=gray!
10!white,colframe=gray!
60!white,
125 boxsep=
0pt,left=
5pt,right=
5pt,top=
5pt,bottom=
5pt, bottomtitle =
3pt, toptitle=
3pt,
126 boxrule=
0pt,bottomrule=
0.5pt,toprule=
0.5pt
}
129 \begin{wrapfigure
}[2]{L
}{17pt
}%
136 {\end{tcolorbox
}\medskip}
138 \lstset{moredelim=*
[s
][\color{red
}\rmfamily\itshape]{<
}{>
}}
139 \lstset{moredelim=*
[s
][\color{blue
}\rmfamily\itshape]{<<
}{>>
}}
140 \usepackage[colorlinks=true
]{hyperref
}
142 %% === Page de garde ===================================================
143 \thispagestyle{empty
}
144 \begin{tikzpicture
}[remember picture, overlay
]
145 \node[below right, shift=
{(-
4pt,
4pt)
}] at (current page.north west)
{%
146 \includegraphics{fond.pdf
}%
151 \includegraphics{luamesh-title
}\\
152 {\large compute and draw meshes with
\lualatex}\\
[1cm
]
153 \parbox{0.6\textwidth}{
155 mode=ext,step=badtriangles,
156 colorNew =green!
20!red,
164 \parbox{0.4\textwidth}{\Large\raggedleft
165 \textbf{Contributor
}\\
166 Maxime
\textsc{Chupin
}
170 Version
0.5,
2017, February,
9th \\
171 \url{http://melusine.eu.org/syracuse/G/delaunay/
}
173 %% == Page de garde ====================================================
179 The package
\Verb|luamesh| allows to compute and draw
2D Delaunay
180 triangulation. The algorithm is written with lua, and depending on the
181 choice of the ``engine'', the drawing is done by MetaPost (with
182 \Verb|luamplib|) or by
\Verb|tikz|.
184 The Delaunay triangulation algorithm is the Bowyer and Watson
185 algorithm. Several macros are provided to draw the global mesh, the
186 set of points, or a particular step of the algorithm.
189 I would like to thank Jean-Michel Sarlat, who hosts the development
190 with a git project on the
\Verb+melusine+ machine:
192 \url{https://melusine.eu.org/syracuse/G/delaunay/
}
194 I would also like to thank the first user, an intensive
195 \emph{test
} user, and a very kind English corrector: Nicole Spillane.
199 \section{Installation
}
202 Of course, you can just put the two files
\Verb+luamesh.lua+ and
203 \Verb+luamesh.sty+ in the working directory but this is not
207 \subsection{With
\TeX live and Linux or Mac OSX
}
209 To install
\luamesh with
\TeX live, you have to create the local
210 \Verb+texmf+ directory in your
\Verb+home+.
216 Then place the files in the correct directories. The
217 \Verb+luamesh.sty+ file must be in directory:
219 \Verb+~/texmf/tex/latex/luamesh/+
221 and the
\Verb+luamesh.lua+, the
\Verb+luamesh-tex.lua+ and the
222 \Verb-luamesh-polygon.lua+ files must be in directory:
224 \Verb+~/texmf/scripts/luamesh/+
227 Once you have done this,
\luamesh can be included in your
document
233 \subsection{With Mik
\TeX{} and Windows
}
235 As these two systems are unknown to the contributor, we refer to the
236 documentation for integrating local additions to Mik
\TeX:
238 \url{http://docs.miktex.org/manual/localadditions.html
}
242 \subsection{A
\lualatex package
}
244 If you want to use this package, you must compile your
document with
248 lualatex mylatexfile.tex
252 \subsection{Dependencies
}
254 This package is built upon two main existing packages that one used to
258 \item \Verb+luamplib+ to use MetaPost via the
\luatex library
262 We will see how to choose between these two
\emph{drawing engines
}.
263 Moreover, the following packages are necessary:
265 \item \Verb+xkeyval+ to manage the optional arguments;
266 \item \Verb+xcolor+ to use colors (required by
\Verb+luamplib+);
267 \item \Verb+ifthen+ to help programming with
\TeX.
271 \section{The Basic Macros
}
273 This package provides macros to draw two
274 dimensional triangulations (or meshes).
276 \subsection{Draw a Complete Mesh
}\label{sec:buildMesh
}
278 \commande|
\buildMeshBW[«options»
]{«list of points» or «file name»
}|
\medskip
280 This macro produces the Delaunay triangulation (using the Bowyer and
281 Watson algorithm) of the given
\meta{list of points
}. The list of
282 points must be given in the following way :
284 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
288 \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)
}
291 \subsubsection{The Options
}
293 There are several options to customize the drawing.
295 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
296 use either the previously described set of points in the argument, or
297 a file containing the points line by line (in
2 columns). Such a
306 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
307 points added to form the
\emph{bounding box
}\footnote{The bounding
308 box is defined by four points place at
15\% around the box
309 defined by $(x_
{\min},y_
{\min})$, $(x_
{\min},y_
{\max})$,
310 $(x_
{\max},y_
{\max})$, and $(x_
{\min},y_
{\max})$. It is used by
311 the algorithm and will be computed in any case.
} and the
312 triangles attached. By default, these triangles are removed at the end of
314 \item[color =
\meta{value
} (default: black):
] The
color of the
316 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
317 drawing for the elements (points and triangles) belonging to the
319 \item[print = none (default)
\textme{or
} points
\textme{or
}
320 dotpoints:
] The
\Verb+point+ value allows to label the vertices of the
321 triangulation. This also adds a
\emph{dot
} at each vertex. The
322 \Verb+dotpoints+ value only add a dot without the labeling.
323 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
324 label the vertices of the triangulation. It is included in the math
325 mode delimiters
\Verb+$...$+. The bounding box points are labeled
326 with numbers
1 to
4 and with a star exponent.
327 \item[tikz (boolean, default:false):
] By default, this boolean is set
328 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
329 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
331 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
332 the scale at which the picture is drawn (the same for both
333 axes). It must contain the unit of length (cm,
337 To illustrate the options, let us show you an example. We consider a
338 file
\Verb+mesh.txt+:
362 The drawing engine is not very relevant here, although it is useful to
363 understand how the drawing is produced. However, the engine will be
365 the so called
\emph{inc
} macros (section~
\ref{sec:inc
}) for adding
366 code before and after the one generated by
370 \subsection{Draw the Set of Points
}
372 \commande|
\drawPointsMesh[«options»
]{«list of points» or «file name»
}|
\medskip
374 With the
\Verb+
\drawPointsMesh+, we plot the set of (user chosen) points from
375 which the Bowyer and Watson algorithm computes the triangulation.
377 The use of this macro is quite similar to
378 \Verb+
\buildMeshBW+. Here is an example of the basic uses.
380 \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)
}
384 \subsubsection{The Options
}
386 There are several options (exactly the same as for the
387 \Verb+
\buildMeshBW+) to customize the drawing.
389 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
390 use either the previously described set of points as the argument, or
391 a file containing the points line by line (in
2 columns). Such a
400 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
401 points added to form the
\emph{bounding box
}\footnote{The bounding
402 box is defined by four points place at
15\% around the box
403 defined by $(x_
{\min},y_
{\min})$, $(x_
{\min},y_
{\max})$,
404 $(x_
{\max},y_
{\max})$, and $(x_
{\min},y_
{\max})$. It is used by
405 the algorithm and will be computed in any case.
} and the
406 triangles attached. By default, these triangles are removed at the end of
407 the algorithm.
\emph{Here, because we plot only the vertices of the
408 mesh, there are no triangles, only dots.
}
409 \item[color =
\meta{value
} (default: black):
] The
color of the
411 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
412 drawing for the elements (points and triangles) belonging to the
414 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
415 triangulation. This also adds a
\emph{dot
} at each vertex. With no
416 label, the dot remains.
417 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
418 label the vertices of the triangulation. This is included in the math
419 mode delimiters
\Verb+$...$+. The bounding box points are labeled
420 with numbers
1 to
4 and with a star exponent.
421 \item[tikz (boolean, default:false):
] By default, this boolean is set
422 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
423 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
425 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
426 the scale at which the picture is drawn (the same for both
427 axes). It must contain the unit of length (cm,
430 With the same external mesh point file presented in
431 section~
\ref{sec:buildMesh
}, we illustrate the different options.
447 \subsection{Draw a Step of the Bowyer and Watson Algorithm
}
449 \commande|
\meshAddPointBW[«options»
]{«list of points» or «file name»
}{«point» or «number of line»
}|
\medskip
451 This command allows to plot the steps within the addition of a
452 point in a Delaunay triangulation by the Bowyer and Watson
455 This macro produces the Delaunay triangulation (using the Bowyer and
456 Watson algorithm) of the given
\meta{list of points
} and shows a step
457 of the algorithm when the
\meta{point
} is added. The list of
458 points must be given in the following way:
460 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
462 and the point is of the form
\verb+(x,y)+. The
\meta{file name
}
463 and
\meta{number of line
} will be explained in the option
466 One can use the macro as follows:
468 \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)
}
469 \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)
}
470 \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)
}
472 The default value for
\Verb+step+ is
473 \Verb+badtriangles+. Consequently, the first
474 line is equivalent to
476 \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)
}
479 \subsubsection{The Options
}
481 There are several options (some of them are the same as for
482 \Verb+
\buildMeshBW+) to customize the drawing.
484 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
485 use either the previously described set of points as the argument, or
486 a file containing the points line by line (in
2 columns). Such a
495 For the second argument of the macro, if we are in
496 \Verb+mode = ext+, the argument must be the
\emph{line number
} of the file
497 corresponding to the point we want to add. The algorithm will stop at the
498 previous line to build the initial triangulation and proceed to add
499 the point corresponding to the line requested. The subsequent lines in
502 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
503 added points that form the
\emph{bounding box
} and the triangles
504 attached. Although they are always computed, by default, these
505 triangles are removed at the end of
507 \item[color =
\meta{value
} (default: black):
] The
color of the
509 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
510 drawing for the elements (points and triangles) belonging to the
512 \item[colorNew =
\meta{value
} (default: red):
] The
color of the
513 drawing of the ``new'' elements which are the point to add, the
514 polygon delimiting the cavity, and the new triangles.
515 \item[colorBack =
\meta{value
} (default: black!
20):
] The
color for the
516 filling of the region concerned by the addition of the new point.
517 \item[colorCircle =
\meta{value
} (default: green):
] The
color for
518 the circumcircle of the triangles containing the point to add.
519 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
520 label the vertices of the triangulation. It is included in the math
521 mode delimiters
\Verb+$...$+. The bounding box points are labeled
522 with numbers
1 to
4 and with a star exponent.
523 \item[step = badtriangles (default)
\textme{or
} cavity
\textme{or
}
524 newtriangles:
] To choose the step we want to draw, corresponding to
525 the steps of the Bowyer and Watson algorithm.
526 \item[newpoint =
\meta{value
} (default: P):
] The letter(s) used to
527 label the new point of the triangulation. It is include in the math
528 mode delimiters
\Verb+$...$+.
529 \item[tikz (boolean, default:false):
] By default, this boolean is set
530 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
531 the picture. With this option,
\Verb+tikz+ is the
\textit{drawing
533 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
534 the scale at which the picture is drawn (the same for both
535 axis). It must contain the unit of length (cm,
539 Here is an example of customizing the drawing. First, recall that
540 the external file
\Verb+mesh.txt+ is:
550 We draw the addition of the
6th point. The
7th line will be ignored.
559 colorNew = green!
50!red,
561 colorBbox = black!
20,
568 \subsection{Mesh a Polygon
}
570 \commande|
\meshPolygon[«options»
]{«list of points» or «file name»
}|
\medskip
573 With
\luamesh, it is possible to mesh an object giving the
574 \emph{border
},
\emph{i.e.
}, one closed polygon. The polygon is given
575 as a list of points as above:
577 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
579 Once again we can also give a file of points using the
\Verb+mode+
582 This command allows to plot the steps within the building of a complete
583 mesh. The followed method is, given a parameter $h$:
585 \item to build a squared grid of points with a unit distance equal to
587 \item to keep the grid points inside the polygon;
588 \item if necessary to add points along the polygon to respect the
590 \item to mesh the complete set of points (using the Bowyer and Watson
594 One can use the macro as follows:
596 \meshPolygon[step=polygon,scale=
2cm
]{(
0,
0);(
1,
0);(
1,
0.5);(
0,
0.5);(-
0.20,
0.35);(-
0.25,
0.25);(-
0.20,
0.15)
}
597 \meshPolygon[step=grid,scale=
2cm
]{(
0,
0);(
1,
0);(
1,
0.5);(
0,
0.5);(-
0.20,
0.35);(-
0.25,
0.25);(-
0.20,
0.15)
}
598 \meshPolygon[step=points,scale=
2cm
]{(
0,
0);(
1,
0);(
1,
0.5);(
0,
0.5);(-
0.20,
0.35);(-
0.25,
0.25);(-
0.20,
0.15)
}
599 \meshPolygon[step=mesh,scale=
2cm
]{(
0,
0);(
1,
0);(
1,
0.5);(
0,
0.5);(-
0.20,
0.35);(-
0.25,
0.25);(-
0.20,
0.15)
}
602 Note that if the points of the grid are too closed to the points of
603 the refined boundary, they are ejected.
605 \subsubsection{The Options
}
607 There are several options (some of them are the same as for
608 \Verb+
\buildMeshBW+) to customize the drawing.
610 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
611 use either the previously described set of points as the argument, or
612 a file containing the points line by line (in
2 columns). Such a
621 \item[h =
\meta{value
} (default:
0.2):
] The mesh parameter, it is the
622 unit distance for the grid. If necessary, the boundary is refined to
623 get points which respect the distance constrain.
624 \item[color =
\meta{value
} (default: black):
] The
color of the
625 drawing (the grid point and the mesh).
626 \item[colorPolygon =
\meta{value
} (default: red):
] The
color of the
627 drawing for the boundary polygon.
628 \item[print = none (default)
\textme{or
} points
\textme{or
}
629 dotpoints:
] The
\Verb+point+ value allows to label the vertices of the
630 triangulation. This also adds a
\emph{dot
} at each vertex. The
631 \Verb+dotpoints+ value only add a dot without the labeling.
632 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
633 label the vertices of the triangulation. It is included in the math
634 mode delimiters
\Verb+$...$+.
635 \item[step = polyqon
\textme{or
} grid
\textme{or
}
636 points
\textme{or
} mesh (default):
] To choose the step we want to draw,
637 see the description above.
638 \item[tikz (boolean, default:false):
] By default, this boolean is set
639 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
640 the picture. With this option,
\Verb+tikz+ is the
\textit{drawing
642 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
643 the scale at which the picture is drawn (the same for both
644 axis). It must contain the unit of length (cm,
648 Here is an example of customizing the drawing.
654 colorPolygon=red!
120,
658 {(
0,
0);(
1,
0);(
1,
0.5);(
0,
0.5);(-
0.20,
0.35);(-
0.25,
0.25);(-
0.20,
0.15)
}
662 \section{The
\emph{inc
} Macros
}\label{sec:inc
}
664 The three macros presented in the above sections have complementary
665 macros, with the suffix
\Verb+inc+ that allow the user to add code
666 (MetaPost or
\Verb+tikz+, depending of the drawing engine) before and
667 after the code generated by
\luamesh.
669 The three macros are:
\medskip
672 \commande|
\buildMeshBWinc[«options»
]{«list of points» or «file name»
}{«code before»
}{«code after»
}|
\medskip
674 \commande|
\drawPointsMeshinc[«options»
]{«list of points» or «file name»
}{«code before»
}{«code after»
}|
\medskip
676 \commande|
\meshAddPointBWinc[«options»
]{«list of points» or «file name»
}%|
678 \commande|
{«point» or «number of line»
}{«code before»
}{«code after»
}|
\medskip
680 \subsection{With MetaPost
}
682 We consider the case where the drawing engine is MetaPost (through the
683 \Verb+luamplib+ package).
685 The feature is described for the
\Verb+
\buildMeshBWinc+ but the mechanism
686 and possibilities are exactly the same for all three macros.
688 When we use the MetaPost drawing engine, the macros previously
689 described produce a code of the form
694 <code for the drawing>
699 Then, the arguments
\meta{code before
} and
\meta{code after
} are
705 <code for the drawing>
710 With the
\emph{inc
} macros, the user has to add the
\Verb+beginfig();+
711 and
\Verb+endfig;+ commands to produce a picture. Indeed, this allows
712 to use the
\Verb+
\everymplib+ command from the
\Verb+
\luamplib+ package.
715 \subsubsection{The
\LaTeX{} Colors Inside the MetaPost Code
}\label{sec:mpcolor
}
717 The configurable colors
718 of the
\LaTeX{} macro are accessible inside the MetaPost code. For
719 \Verb+
\buildMeshBWinc+ and
\Verb+
\drawPointsMeshinc+,
720 \Verb+
\luameshmpcolor+,
721 and
\Verb+
\luameshmpcolorBbox+ have been defined.
722 For the macro
\Verb+
\meshAddPointBWinc+ three additional
723 colors are present:
\Verb+
\luameshmpcolorBack+,
724 \Verb+
\luameshmpcolorNew+, and
725 \Verb+
\luameshmpcolorCircle+. For the macro
\Verb+
\meshPolygon+, the
726 color \Verb+
\luameshmpcolorPoly+ is defined. Of course, MetaPost
727 colors can be defined as well. Finally, the
\Verb+luamplib+ mechanism
728 \Verb+
\mpcolor+ is also available.
730 \subsubsection{The Mesh Points
}
732 At the beginning of the automatically generated code, a list of
733 MetaPost
\Verb+pair+s are defined corresponding to all the vertices in
734 the mesh (when the option
\Verb+bbox=show+, the last
4 points are the
735 \emph{bounding box points
}). The points are available with the
736 \Verb+MeshPoints
[]+ table of variables. The
\Verb+pair+s ($
\R^
{2}$ points)
737 \Verb+MeshPoints
[i
]+ are
738 defined using the unit length
\Verb+u+.
740 With the
\Verb+
\meshPolygon+ macro, we have the points of the polygon
741 (refined) that are available with the
742 \Verb+polygon
[]+ table of variables.
744 \subsubsection{Examples
}
746 Here is three examples for the different macros.
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)
}%
758 label(btex Mesh $
\mathbb{T
}$ etex, (
0,
2u)) withcolor
\luameshmpcolor;
768 ]{(
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)
}%
773 drawdblarrow MeshPoints
[3] -- MeshPoints
[9] withpen pencircle scaled
1pt
774 withcolor (
0.3,
0.7,
0.2);
781 colorNew = green!
50!red,
783 colorBbox = black!
20,
787 {(
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)
}%
794 fill MeshPoints
[7]--MeshPoints
[8]--MeshPoints
[9]--MeshPoints
[10]--cycle
795 withcolor
\mpcolor{blue!
10};
801 The variables
\Verb+MeshPoints
[]+ are not defined for the argument
802 corresponding to the code placed
\textbf{before
} the code generated by
803 \luamesh. Hence, to use such variables, we have to define a
804 \Verb+picture+ as shown in the third example above.
808 \subsection{With TikZ
}
810 If we have chosen
\Verb+tikz+ as the drawing engine, the added code
811 will be written in
\Verb+tikz+. In that case, the two arguments
812 \meta{code before
} and
\meta{code after
} will be inserted as follows:
815 \begin{tikzpicture
}[x=<scale>,y=<scale>
]
822 Because the engine is
\Verb+tikz+ their is no issue with colors, the
823 \LaTeX{} colors (e.g.:
\Verb+xcolor+) can be used directly.
825 \subsubsection{The Mesh Points
}
827 The mesh points are defined here as
\Verb+tikz+
828 \Verb+
\coordinate+ and named as follows
830 \coordinate (MeshPoints1) at (...,...);
831 \coordinate (MeshPoints2) at (...,...);
832 \coordinate (MeshPoints3) at (...,...);
836 With the
\Verb+
\meshPolygon+ we have also the polygon points coordinates:
838 \coordinate (polygon1) at (...,...);
842 Once again these coordinates are not yet defined to be used in the
843 code given by
\meta{code
846 \subsubsection{Examples
}
855 ]{(
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)
}%
859 \node[color = blue!
50] at (
0,
2)
{Mesh $
\mathbb{T
}$
} ;
869 ]{(
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)
}%
873 \draw[<->,thick,
color=green
] (MeshPoints3) -- (MeshPoints9);
877 \section{Voronoï Diagrams
}
879 Another interesting feature of b Delaunay triangulation is that its
880 \emph{dual
} is the so-called Voronoï diagram. More precisely, for a
882 points $\
{p_
{1},
\ldots, p_
{n
}\
}$ in the Euclidean plane, the Voronoï
883 cell $R_
{k
}$ corresponding to $p_
{k
}$ is the set of
884 all points in the Euclidean plane $
\R^
{2}$ whose distance to $p_
{k
}$ is less
886 or equal to its distance to any other $p_
{k'
}$.
\bigskip
889 \commande|
\buildVoronoiBW[«options»
]{«list of points» or «file name»
}|
\medskip
891 This macro produce the Voronoï diagram of the given
\meta{list of
892 points
}. Once again, the
894 points must be given in the following way :
896 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
900 \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)
}
903 \subsection{The Options
}\label{sec:voronoiOptions
}
906 There are several options to customize the drawing.
908 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
909 use either the previously described set of points in the argument, or
910 a file containing the points line by line (in
2 columns). Such a
919 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
920 added points to form a
\emph{bounding box
}\footnote{The bounding
921 box is defined by four points place at
15\% around the box
922 defined by $(x_
{\min},y_
{\min})$, $(x_
{\min},y_
{\max})$,
923 $(x_
{\max},y_
{\max})$, and $(x_
{\min},y_
{\max})$. It is used by
924 the algorithm and will be computed in any case.
} and the corresponding
925 triangulation. By default, these points are removed at the end of
927 \item[color =
\meta{value
} (default: black):
] The
color of the
929 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
930 drawing for the elements (points and triangles) belonging to the
932 \item[colorVoronoi =
\meta{value
} (default: black):
] The
color of the
933 drawing for the elements (points and polygons) belonging to the
935 \item[print = none (default)
\textme{or
} points:
] To label the
937 triangulation. Contrary to the previous macros, where
938 \Verb+print=none+, a
\emph{dot
} is produced at each vertex of the
939 set of points and at the circumcircle centers which are the nodes of
941 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
942 label the vertices of the triangulation. This is included in the math
943 mode delimiters
\Verb+$...$+. The bounding box points are labelled
944 with numbers
1 to
4 and with a star exponent.
945 \item[circumpoint =
\meta{value
} (default: P):
] The letter(s) used to
946 label the vertices of the Voronoï diagram. This is included in the math
947 mode delimiters
\Verb+$...$+.
948 \item[tikz (boolean, default:false):
] By default, this boolean is set
949 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
950 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
952 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
953 the scale at which the picture is drawn (the same for both
954 axes). It must contain the unit of length (cm,
956 \item[delaunay = none (default)
\textme{or
} show:
] This option
957 allows to draw the Delaunay triangulation under the Voronoï diagram.
958 \item[styleDelaunay = none (default)
\textme{or
} dashed:
] This option
959 allows to draw the Delaunay triangulation in dashed lines.
960 \item[styleVoronoi = none (default)
\textme{or
} dashed:
] This option
961 allows to draw the Voronoï edges in dashed lines.
965 \buildVoronoiBW[tikz,delaunay=show,styleDelaunay=dashed
]
966 {(
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)
}
969 \subsection{The
\emph{inc
} variant
}
971 Once again, a variant of the macros is available allowing the user to
972 add code before and after the code produced by
\luamesh. We refer to
973 section~
\ref{sec:inc
} because it works the same way.
977 \item with MetaPost, the circumcenters are defined using
978 \Verb+pair CircumPoints
[];+ and so they are accessible.
979 \item With
\Verb+tikz+, there are new coordinates defined as follows
981 \coordinate (CircumPoints1) at (...,...);
982 \coordinate (CircumPoints2) at (...,...);
983 \coordinate (CircumPoints3) at (...,...);
988 Finally, when the MetaPost drawing engine is used another
color is
989 available (see~
\ref{sec:mpcolor
}):
\Verb+
\luameshmpcolorVoronoi+.
993 Gmsh is an open source efficient software that produces meshes. The
994 exporting format is the
\emph{MSH ASCII file format
} and can be easily
995 read by a Lua program.
\luamesh provides the user with dedicated
996 macros to read and draw meshes coming from a Gmsh exportation.
\bigskip
998 \commande|
\drawGmsh[«options»
]{«file name»
}|
\medskip
1000 This macro draws the triangulation produced by Gmsh and exported in the
1001 \Verb+msh+ format. The argument is the name of the file to be read
1002 (e.g.:
\Verb+maillage.msh+).
1005 \drawGmsh{maillage.msh
}
1008 There are several options to customize the drawing.
1010 \item[color =
\meta{value
} (default: black):
] The
color of the
1012 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
1013 triangulation. Contrary to some previous macros, when
1014 \Verb+print=none+ a
\emph{dot
} is produced at each vertex of the
1015 set of points and at the circumcircle centers (these are the nodes of
1016 the Voronoï diagram).
1017 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
1018 label the vertices of the triangulation. This is included in the math
1019 mode delimiters
\Verb+$...$+. The bounding box points are labeled
1020 with numbers
1 to
4 and with a star exponent.
1021 \item[tikz (boolean, default:false):
] By default, this boolean is set
1022 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
1023 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
1025 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
1026 the scale at which the picture is drawn (the same for both
1027 axes). It must contain the unit of length (cm,
1032 \drawGmsh[scale=
2cm,print=points,
color=blue!
30]{maillage.msh
}
1035 \subsection{Gmsh and Voronoï Diagrams
}
1037 Because Gmsh generates Delaunay triangulations, we can plot the associated
1038 Voronoï diagram. This is done by the following macro:
\bigskip
1040 \commande|
\gmshVoronoi[«options»
]{«file name»
}|
\medskip
1043 \gmshVoronoi{maillage.msh
}
1047 \subsection{The Options
}\label{sec:voronoiOptions
}
1050 There are several options to customize the drawing.
1052 \item[color =
\meta{value
} (default: black):
] The
color of the
1054 \item[colorVoronoi =
\meta{value
} (default: black):
] The
color of the
1055 drawing for the elements (points and polygons) belonging to the
1057 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
1058 triangulation. Contrary to some previous macros, when
1059 \Verb+print=none+, a
\emph{dot
} is produced at each vertex of the
1060 set of points and at the circumcircle centers (these are the nodes of
1061 the Voronoï diagram).
1062 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
1063 label the vertices of the triangulation. It is included in the math
1064 mode delimiters
\Verb+$...$+. The bounding box points are labeled
1065 with numbers
1 to
4 and with a star exponent.
1066 \item[circumpoint =
\meta{value
} (default: P):
] The letter(s) used to
1067 label the vertices of the Voronoï diagram. This is included in the math
1068 mode delimiters
\Verb+$...$+.
1069 \item[tikz (boolean, default:false):
] By default, this boolean is set
1070 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
1071 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
1073 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
1074 the scale at which the picture is drawn (the same for both
1075 axes). It must contain the unit of length (cm,
1077 \item[delaunay = none (default)
\textme{or
} show
] This option
1078 allows to draw the Delaunay triangulation overlapped with the
1080 \item[styleDelaunay = none (default)
\textme{or
} dashed
] This option
1081 allows to draw the Delaunay triangulation in dashed lines.
1082 \item[styleVoronoi = none (default)
\textme{or
} dashed
] This option
1083 allows to draw the Voronoï edges in dashed lines.
1087 \gmshVoronoi[tikz,scale=
1.5cm, delaunay=show,styleVoronoi=dashed
]{maillage.msh
}
1091 \subsection{The
\emph{inc
} variants
}
1093 Once again, there exist
\emph{inc
} variant macros:
\bigskip
1095 \commande|
\drawGmshinc[«options»
]{«file name»
}{«code before»
}{«code after»
}|
\medskip
1097 \commande|
\gmshVoronoiinc[«options»
]{«file name»
}{«code before»
}{«code after»
}|
\medskip
1099 We refer to the previous sections for explanations.
1104 \subsection{With Animate
}
1106 If you use
\emph{Adobe Acrobat reader
}, you can easily produce an
1107 animation of the Bowyer and Watson algorithm with the package
1110 For example, the following code (in a file name
\Verb+animation.tex+):
1112 \documentclass{article
}
1113 %% lualatex compilation
1114 \usepackage[margin=
2.5cm
]{geometry
}
1115 \usepackage{luamesh
}
1116 \usepackage{fontspec
}
1117 \usepackage{multido
}
1119 \def\drawPath{draw (-
2,-
2)*u--(
8,-
2)*u--(
8,
6)*u--(-
2,
6)*u--cycle withcolor
0.99white;
}
1120 \def\clipPath{clip currentpicture to (-
2,-
2)*u--(
8,-
2)*u--(
8,
6)*u--(-
2,
6)*u--cycle;
}
1122 \drawPointsMeshinc[mode=ext, bbox = show,colorBbox = blue!
20,print=points
]{mesh.txt
}%
1131 \newpage\buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!
20,print=points
]{meshInit.txt
}%
1140 \multido{\ii=
5+
1}{4}{%
1141 \newpage\meshAddPointBWinc[mode=ext,step=badtriangles,colorNew
1142 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1143 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1152 \meshAddPointBWinc[mode=ext,step=cavity,colorNew
1153 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1154 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1163 \meshAddPointBWinc[mode=ext,step=newtriangles,colorNew
1164 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1165 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1176 \buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!
20,print=points
]{mesh.txt
}%
1186 \buildMeshBWinc[mode=ext,print=points
]{mesh.txt
}%
1197 produces a PDF with multiple pages. Using the
\Verb+pdfcrop+ program,
1198 we crop the pages to the material, and then we can animate the PDF
1199 using the
\Verb+animate+ package.
1202 %\animategraphics[controls]{1}{animation-crop}{}{}
1211 %%% Local Variables:
1212 %%% flyspell-mode: 1
1213 %%% ispell-local-dictionary: "american"