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 = polygon
\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,
646 \item[gridpoints = rect (default)
\textme{or
} perturb:
] This option
647 allows to specify the mode of generation of the grid points. The
648 value
\Verb+rect+ produces a simple rectangular grid, and the value
649 \Verb+pertub+ randomly perturbs the rectangular grid.
652 Here is an example of customizing the drawing.
658 colorPolygon=red!
120,
663 {(
0,
0);(
1,
0);(
1,
0.5);(
0,
0.5);(-
0.20,
0.35);(-
0.25,
0.25);(-
0.20,
0.15)
}
667 \section{The
\emph{inc
} Macros
}\label{sec:inc
}
669 The three macros presented in the above sections have complementary
670 macros, with the suffix
\Verb+inc+ that allow the user to add code
671 (MetaPost or
\Verb+tikz+, depending of the drawing engine) before and
672 after the code generated by
\luamesh.
674 The three macros are:
\medskip
677 \commande|
\buildMeshBWinc[«options»
]{«list of points» or «file name»
}{«code before»
}{«code after»
}|
\medskip
679 \commande|
\drawPointsMeshinc[«options»
]{«list of points» or «file name»
}{«code before»
}{«code after»
}|
\medskip
681 \commande|
\meshAddPointBWinc[«options»
]{«list of points» or «file name»
}%|
683 \commande|
{«point» or «number of line»
}{«code before»
}{«code after»
}|
\medskip
685 \subsection{With MetaPost
}
687 We consider the case where the drawing engine is MetaPost (through the
688 \Verb+luamplib+ package).
690 The feature is described for the
\Verb+
\buildMeshBWinc+ but the mechanism
691 and possibilities are exactly the same for all three macros.
693 When we use the MetaPost drawing engine, the macros previously
694 described produce a code of the form
699 <code for the drawing>
704 Then, the arguments
\meta{code before
} and
\meta{code after
} are
710 <code for the drawing>
715 With the
\emph{inc
} macros, the user has to add the
\Verb+beginfig();+
716 and
\Verb+endfig;+ commands to produce a picture. Indeed, this allows
717 to use the
\Verb+
\everymplib+ command from the
\Verb+
\luamplib+ package.
720 \subsubsection{The
\LaTeX{} Colors Inside the MetaPost Code
}\label{sec:mpcolor
}
722 The configurable colors
723 of the
\LaTeX{} macro are accessible inside the MetaPost code. For
724 \Verb+
\buildMeshBWinc+ and
\Verb+
\drawPointsMeshinc+,
725 \Verb+
\luameshmpcolor+,
726 and
\Verb+
\luameshmpcolorBbox+ have been defined.
727 For the macro
\Verb+
\meshAddPointBWinc+ three additional
728 colors are present:
\Verb+
\luameshmpcolorBack+,
729 \Verb+
\luameshmpcolorNew+, and
730 \Verb+
\luameshmpcolorCircle+. For the macro
\Verb+
\meshPolygon+, the
731 color \Verb+
\luameshmpcolorPoly+ is defined. Of course, MetaPost
732 colors can be defined as well. Finally, the
\Verb+luamplib+ mechanism
733 \Verb+
\mpcolor+ is also available.
735 \subsubsection{The Mesh Points
}
737 At the beginning of the automatically generated code, a list of
738 MetaPost
\Verb+pair+s are defined corresponding to all the vertices in
739 the mesh (when the option
\Verb+bbox=show+, the last
4 points are the
740 \emph{bounding box points
}). The points are available with the
741 \Verb+MeshPoints
[]+ table of variables. The
\Verb+pair+s ($
\R^
{2}$ points)
742 \Verb+MeshPoints
[i
]+ are
743 defined using the unit length
\Verb+u+.
745 With the
\Verb+
\meshPolygon+ macro, we have the points of the polygon
746 (refined) that are available with the
747 \Verb+polygon
[]+ table of variables.
749 \subsubsection{Examples
}
751 Here is three examples for the different macros.
758 ]{(
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)
}%
763 label(btex Mesh $
\mathbb{T
}$ etex, (
0,
2u)) withcolor
\luameshmpcolor;
773 ]{(
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)
}%
778 drawdblarrow MeshPoints
[3] -- MeshPoints
[9] withpen pencircle scaled
1pt
779 withcolor (
0.3,
0.7,
0.2);
786 colorNew = green!
50!red,
788 colorBbox = black!
20,
792 {(
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)
}%
799 fill MeshPoints
[7]--MeshPoints
[8]--MeshPoints
[9]--MeshPoints
[10]--cycle
800 withcolor
\mpcolor{blue!
10};
806 The variables
\Verb+MeshPoints
[]+ are not defined for the argument
807 corresponding to the code placed
\textbf{before
} the code generated by
808 \luamesh. Hence, to use such variables, we have to define a
809 \Verb+picture+ as shown in the third example above.
813 \subsection{With TikZ
}
815 If we have chosen
\Verb+tikz+ as the drawing engine, the added code
816 will be written in
\Verb+tikz+. In that case, the two arguments
817 \meta{code before
} and
\meta{code after
} will be inserted as follows:
820 \begin{tikzpicture
}[x=<scale>,y=<scale>
]
827 Because the engine is
\Verb+tikz+ their is no issue with colors, the
828 \LaTeX{} colors (e.g.:
\Verb+xcolor+) can be used directly.
830 \subsubsection{The Mesh Points
}
832 The mesh points are defined here as
\Verb+tikz+
833 \Verb+
\coordinate+ and named as follows
835 \coordinate (MeshPoints1) at (...,...);
836 \coordinate (MeshPoints2) at (...,...);
837 \coordinate (MeshPoints3) at (...,...);
841 With the
\Verb+
\meshPolygon+ we have also the polygon points coordinates:
843 \coordinate (polygon1) at (...,...);
847 Once again these coordinates are not yet defined to be used in the
848 code given by
\meta{code
851 \subsubsection{Examples
}
860 ]{(
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)
}%
864 \node[color = blue!
50] at (
0,
2)
{Mesh $
\mathbb{T
}$
} ;
874 ]{(
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)
}%
878 \draw[<->,thick,
color=green
] (MeshPoints3) -- (MeshPoints9);
882 \section{Voronoï Diagrams
}
884 Another interesting feature of b Delaunay triangulation is that its
885 \emph{dual
} is the so-called Voronoï diagram. More precisely, for a
887 points $\
{p_
{1},
\ldots, p_
{n
}\
}$ in the Euclidean plane, the Voronoï
888 cell $R_
{k
}$ corresponding to $p_
{k
}$ is the set of
889 all points in the Euclidean plane $
\R^
{2}$ whose distance to $p_
{k
}$ is less
891 or equal to its distance to any other $p_
{k'
}$.
\bigskip
894 \commande|
\buildVoronoiBW[«options»
]{«list of points» or «file name»
}|
\medskip
896 This macro produce the Voronoï diagram of the given
\meta{list of
897 points
}. Once again, the
899 points must be given in the following way :
901 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
905 \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)
}
908 \subsection{The Options
}\label{sec:voronoiOptions
}
911 There are several options to customize the drawing.
913 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
914 use either the previously described set of points in the argument, or
915 a file containing the points line by line (in
2 columns). Such a
924 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
925 added points to form a
\emph{bounding box
}\footnote{The bounding
926 box is defined by four points place at
15\% around the box
927 defined by $(x_
{\min},y_
{\min})$, $(x_
{\min},y_
{\max})$,
928 $(x_
{\max},y_
{\max})$, and $(x_
{\min},y_
{\max})$. It is used by
929 the algorithm and will be computed in any case.
} and the corresponding
930 triangulation. By default, these points are removed at the end of
932 \item[color =
\meta{value
} (default: black):
] The
color of the
934 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
935 drawing for the elements (points and triangles) belonging to the
937 \item[colorVoronoi =
\meta{value
} (default: black):
] The
color of the
938 drawing for the elements (points and polygons) belonging to the
940 \item[print = none (default)
\textme{or
} points:
] To label 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 at the circumcircle centers which are the nodes of
946 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
947 label the vertices of the triangulation. This is included in the math
948 mode delimiters
\Verb+$...$+. The bounding box points are labelled
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 Voronoï diagram. This 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
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,
961 \item[delaunay = none (default)
\textme{or
} show:
] This option
962 allows to draw the Delaunay triangulation under the Voronoï diagram.
963 \item[styleDelaunay = none (default)
\textme{or
} dashed:
] This option
964 allows to draw the Delaunay triangulation in dashed lines.
965 \item[styleVoronoi = none (default)
\textme{or
} dashed:
] This option
966 allows to draw the Voronoï edges in dashed lines.
970 \buildVoronoiBW[tikz,delaunay=show,styleDelaunay=dashed
]
971 {(
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)
}
974 \subsection{The
\emph{inc
} variant
}
976 Once again, a variant of the macros is available allowing the user to
977 add code before and after the code produced by
\luamesh. We refer to
978 section~
\ref{sec:inc
} because it works the same way.
982 \item with MetaPost, the circumcenters are defined using
983 \Verb+pair CircumPoints
[];+ and so they are accessible.
984 \item With
\Verb+tikz+, there are new coordinates defined as follows
986 \coordinate (CircumPoints1) at (...,...);
987 \coordinate (CircumPoints2) at (...,...);
988 \coordinate (CircumPoints3) at (...,...);
993 Finally, when the MetaPost drawing engine is used another
color is
994 available (see~
\ref{sec:mpcolor
}):
\Verb+
\luameshmpcolorVoronoi+.
998 Gmsh is an open source efficient software that produces meshes. The
999 exporting format is the
\emph{MSH ASCII file format
} and can be easily
1000 read by a Lua program.
\luamesh provides the user with dedicated
1001 macros to read and draw meshes coming from a Gmsh exportation.
\bigskip
1003 \commande|
\drawGmsh[«options»
]{«file name»
}|
\medskip
1005 This macro draws the triangulation produced by Gmsh and exported in the
1006 \Verb+msh+ format. The argument is the name of the file to be read
1007 (e.g.:
\Verb+maillage.msh+).
1010 \drawGmsh{maillage.msh
}
1013 There are several options to customize the drawing.
1015 \item[color =
\meta{value
} (default: black):
] The
color of the
1017 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
1018 triangulation. Contrary to some previous macros, when
1019 \Verb+print=none+ a
\emph{dot
} is produced at each vertex of the
1020 set of points and at the circumcircle centers (these are the nodes of
1021 the Voronoï diagram).
1022 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
1023 label the vertices of the triangulation. This is included in the math
1024 mode delimiters
\Verb+$...$+. The bounding box points are labeled
1025 with numbers
1 to
4 and with a star exponent.
1026 \item[tikz (boolean, default:false):
] By default, this boolean is set
1027 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
1028 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
1030 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
1031 the scale at which the picture is drawn (the same for both
1032 axes). It must contain the unit of length (cm,
1037 \drawGmsh[scale=
2cm,print=points,
color=blue!
30]{maillage.msh
}
1040 \subsection{Gmsh and Voronoï Diagrams
}
1042 Because Gmsh generates Delaunay triangulations, we can plot the associated
1043 Voronoï diagram. This is done by the following macro:
\bigskip
1045 \commande|
\gmshVoronoi[«options»
]{«file name»
}|
\medskip
1048 \gmshVoronoi{maillage.msh
}
1052 \subsection{The Options
}\label{sec:voronoiOptions
}
1055 There are several options to customize the drawing.
1057 \item[color =
\meta{value
} (default: black):
] The
color of the
1059 \item[colorVoronoi =
\meta{value
} (default: black):
] The
color of the
1060 drawing for the elements (points and polygons) belonging to the
1062 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
1063 triangulation. Contrary to some previous macros, when
1064 \Verb+print=none+, a
\emph{dot
} is produced at each vertex of the
1065 set of points and at the circumcircle centers (these are the nodes of
1066 the Voronoï diagram).
1067 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
1068 label the vertices of the triangulation. It is included in the math
1069 mode delimiters
\Verb+$...$+. The bounding box points are labeled
1070 with numbers
1 to
4 and with a star exponent.
1071 \item[circumpoint =
\meta{value
} (default: P):
] The letter(s) used to
1072 label the vertices of the Voronoï diagram. This is included in the math
1073 mode delimiters
\Verb+$...$+.
1074 \item[tikz (boolean, default:false):
] By default, this boolean is set
1075 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
1076 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
1078 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
1079 the scale at which the picture is drawn (the same for both
1080 axes). It must contain the unit of length (cm,
1082 \item[delaunay = none (default)
\textme{or
} show
] This option
1083 allows to draw the Delaunay triangulation overlapped with the
1085 \item[styleDelaunay = none (default)
\textme{or
} dashed
] This option
1086 allows to draw the Delaunay triangulation in dashed lines.
1087 \item[styleVoronoi = none (default)
\textme{or
} dashed
] This option
1088 allows to draw the Voronoï edges in dashed lines.
1092 \gmshVoronoi[tikz,scale=
1.5cm, delaunay=show,styleVoronoi=dashed
]{maillage.msh
}
1096 \subsection{The
\emph{inc
} variants
}
1098 Once again, there exist
\emph{inc
} variant macros:
\bigskip
1100 \commande|
\drawGmshinc[«options»
]{«file name»
}{«code before»
}{«code after»
}|
\medskip
1102 \commande|
\gmshVoronoiinc[«options»
]{«file name»
}{«code before»
}{«code after»
}|
\medskip
1104 We refer to the previous sections for explanations.
1109 \subsection{With Animate
}
1111 If you use
\emph{Adobe Acrobat reader
}, you can easily produce an
1112 animation of the Bowyer and Watson algorithm with the package
1115 For example, the following code (in a file name
\Verb+animation.tex+):
1117 \documentclass{article
}
1118 %% lualatex compilation
1119 \usepackage[margin=
2.5cm
]{geometry
}
1120 \usepackage{luamesh
}
1121 \usepackage{fontspec
}
1122 \usepackage{multido
}
1124 \def\drawPath{draw (-
2,-
2)*u--(
8,-
2)*u--(
8,
6)*u--(-
2,
6)*u--cycle withcolor
0.99white;
}
1125 \def\clipPath{clip currentpicture to (-
2,-
2)*u--(
8,-
2)*u--(
8,
6)*u--(-
2,
6)*u--cycle;
}
1127 \drawPointsMeshinc[mode=ext, bbox = show,colorBbox = blue!
20,print=points
]{mesh.txt
}%
1136 \newpage\buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!
20,print=points
]{meshInit.txt
}%
1145 \multido{\ii=
5+
1}{4}{%
1146 \newpage\meshAddPointBWinc[mode=ext,step=badtriangles,colorNew
1147 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1148 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1157 \meshAddPointBWinc[mode=ext,step=cavity,colorNew
1158 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1159 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1168 \meshAddPointBWinc[mode=ext,step=newtriangles,colorNew
1169 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1170 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1181 \buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!
20,print=points
]{mesh.txt
}%
1191 \buildMeshBWinc[mode=ext,print=points
]{mesh.txt
}%
1202 produces a PDF with multiple pages. Using the
\Verb+pdfcrop+ program,
1203 we crop the pages to the material, and then we can animate the PDF
1204 using the
\Verb+animate+ package.
1207 %\animategraphics[controls]{1}{animation-crop}{}{}
1216 %%% Local Variables:
1217 %%% flyspell-mode: 1
1218 %%% ispell-local-dictionary: "american"