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}
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.2,
29 novembre
2016\\
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. First, the
217 \Verb+luamesh.sty+ file must be in the directory:
219 \Verb+~/texmf/tex/latex/luamesh/+
221 and secondly, the
\Verb+luamesh.lua+ must be in the directory:
223 \Verb+~/texmf/scripts/luamesh/+
226 Once you have done this,
\luamesh can be included in your
document
232 \subsection{With Mik
\TeX{} and Windows
}
234 We do not know these two systems, so we refer to the
235 documentation for integrating local additions to Mik
\TeX:
237 \url{http://docs.miktex.org/manual/localadditions.html
}
241 \subsection{A
\lualatex package
}
243 If you want to use this package, you must compile your
document with
247 lualatex mylatexfile.tex
251 \subsection{Dependencies
}
253 This package is built upon two main existing packages to draw the
256 \item \Verb+luamplib+ to use MetaPost via the
\luatex library
258 \item and
\Verb+tikz+.
260 We will see how to choose between these two
\emph{drawing engines
}.
262 Moreover, the following packages are necessary:
264 \item \Verb+xkeyval+ to manage the optional arguments;
265 \item \Verb+xcolor+ to use colors (needed by
\Verb+luamplib+);
266 \item \Verb+ifthen+ to help the programming with
\TeX.
270 \section{The Basic Macros
}
272 Let us recall that this package provides macros to draw two
273 dimensional triangulations (or meshes).
275 \subsection{Draw a Complete Mesh
}\label{sec:buildMesh
}
277 \commande|
\buildMeshBW[«options»
]{«list of points» or «file name»
}|
\medskip
279 This macro produces the Delaunay triangulation (using the Bowyer and
280 Watson algorithm) of the given
\meta{list of points
}. The list of
281 points must be given in the following way :
283 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
287 \buildMeshBW{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}
290 \subsubsection{The Options
}
292 There are several options to customize the drawing.
294 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
295 use either the previously described set of points in the argument, or
296 a file, containing, line by line (
2 columns), the points. Such a
305 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
306 added points to form a
\emph{bounding box
}\footnote{The bounding
307 box is defined by four points place at
15\% around the box
308 defined by $(x_
{\min},y_
{\min})$, $(x_
{\min},y_
{\max})$,
309 $(x_
{\max},y_
{\max})$, and $(x_
{\min},y_
{\max})$. It is used by
310 the algorithm and will be computed in any case.
} and the corresponding
311 triangulation. By default, these triangles are removed at the end of
313 \item[color =
\meta{value
} (default: black):
] The
color of the
315 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
316 drawing for the elements (points and triangles) belonging to the
318 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
319 triangulation. This also adds a
\emph{dot
} at each vertex.
320 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
321 label the vertices of the triangulation. It is included in the math
322 mode delimiters
\Verb+$...$+. The bounding box points are labeled
323 with numbers
1 to
4 and with a star exponent.
324 \item[tikz (boolean, default:false):
] By default, this boolean is set
325 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
326 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
328 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
329 the scale at which the picture is drawn (the same for both
330 axes). It must contain the unit of length (cm,
334 To illustrate the options, let us show you an example. We consider a
335 file
\Verb+mesh.txt+:
359 The drawing engine is not very relevant here, but it is useful to
360 understand how the drawing is made. However, the engine will be
362 the so called
\emph{inc
} macros (section~
\ref{sec:inc
}), for adding
363 code before and after the one generated by
367 \subsection{Draw the Set of Points
}
369 \commande|
\drawPointsMesh[«options»
]{«list of points» or «file name»
}|
\medskip
371 With the
\Verb+
\drawPointsMesh+, we plot the set of (user chosen) points from
372 which the Bowyer and Watson algorithm computes the triangulation.
374 The use of this macro is quite similar to
375 \Verb+
\buildMeshBW+. Here is an example of the basic uses.
377 \drawPointsMesh{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}
381 \subsubsection{The Options
}
383 There are several options (exactly the same as for the
384 \Verb+
\buildMeshBW+) to customize the drawing.
386 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
387 use either the previously described set of points as the argument, or
388 a file, containing, line by line (
2 columns), the points. Such a
397 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
398 added points to form a
\emph{bounding box
} and the corresponding
399 triangulation. By default, these triangles are removed at the end of
400 the algorithm.
\emph{Here, because we plot only the vertices of the
401 mesh, there are no triangles, only dots.
}
402 \item[color =
\meta{value
} (default: black):
] The
color of the
404 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
405 drawing for the elements (points and triangles) belonging to the
407 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
408 triangulation. This also adds a
\emph{dot
} at each vertex. Without
409 label, there is still the dot.
410 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
411 label the vertices of the triangulation. It is included in the math
412 mode delimiters
\Verb+$...$+. The bounding box points are labeled
413 with numbers
1 to
4 and with a star exponent.
414 \item[tikz (boolean, default:false):
] By default, this boolean is set
415 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
416 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
418 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
419 the scale at which the picture is drawn (the same for both
420 axes). It must contain the unit of length (cm,
423 With the same external mesh point file presented in
424 section~
\ref{sec:buildMesh
}, we illustrate the different options.
440 \subsection{Draw a Step of the Bowyer and Watson Algorithm
}
442 \commande|
\meshAddPointBW[«options»
]{«list of points» or «file name»
}{«point» or «number of line»
}|
\medskip
444 This command allows to plot the steps within the addition of a
445 point in a Delaunay triangulation, by the Bowyer and Watson
448 This macro produces the Delaunay triangulation (using the Bowyer and
449 Watson algorithm) of the given
\meta{list of points
} and shows a step
450 of the algorithm when the
\meta{point
} is added. The list of
451 points must be given in the following way:
453 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
455 and the point is of the form
\verb+(x,y)+. The
\meta{file name
}
456 and
\meta{number of line
} will be explained in the option
459 One can use the macro as fallows:
461 \meshAddPointBW[step=badtriangles
]{(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}{(
2.2,
1.8)
}
462 \meshAddPointBW[step=cavity
]{(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}{(
2.2,
1.8)
}
463 \meshAddPointBW[step=newtriangles
]{(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}{(
2.2,
1.8)
}
465 The default value for
\Verb+step+ is
466 \Verb+badtriangles+. Consequently, the first
467 line is equivalent to
469 \meshAddPointBW{(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}{(
2.2,
1.8)
}
472 \subsubsection{The Options
}
474 There are several options (some of them are the same as for
475 \Verb+
\buildMeshBW+) to customize the drawing.
477 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
478 use either the previously described set of point in the first
480 a file containing, line by line (
2 columns), the points. Such a
489 For the second argument of the macro, if we are in the
490 \Verb+mode = ext+, the argument must be the
\emph{line number
} of the file
491 corresponding to the point we want to add. The algorithm will stop the
492 line before to build the initial triangulation for which it will add
493 the point corresponding to the line. The subsequent lines in the file are
495 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
496 added points to form a
\emph{bounding box
} and the corresponding
497 triangulation. By default, these triangles are removed at the end of
499 \item[color =
\meta{value
} (default: black):
] The
color of the
501 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
502 drawing for the elements (points and triangles) belonging to the
504 \item[colorNew =
\meta{value
} (default: red):
] The
color of the
505 drawing of the ``new'' elements which are the point to add, the
506 polygon of the cavity, and the new triangles.
507 \item[colorBack =
\meta{value
} (default: black!
20):
] The
color for the
508 filling of the region concerned by the addition of the new point.
509 \item[colorCircle =
\meta{value
} (default: green):
] The
color for
510 the circumcircle of the triangles containing the point to add.
511 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
512 label the vertices of the triangulation. It is included in the math
513 mode delimiters
\Verb+$...$+. The bounding box points are labeled
514 with numbers
1 to
4 and with a star exponent.
515 \item[step = badtriangles (default)
\textme{or
} cavity
\textme{or
}
516 newtriangles:
] To choose the step we want to draw, corresponding to
517 the steps of the Bowyer and Watson algorithm.
518 \item[newpoint =
\meta{value
} (default: P):
] The letter(s) used to
519 label the new point of the triangulation. It is include in the math
520 mode delimiters
\Verb+$...$+.
521 \item[tikz (boolean, default:false):
] By default, this boolean is set
522 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
523 the picture. With this option,
\Verb+tikz+ is the
\textit{drawing
525 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
526 the scale at which the picture is draw (the same for the two
527 axis). It must contain the unit of length (cm,
531 Here is an example of customizing the drawing. First, recall that
532 the external file
\Verb+mesh.txt+ is:
542 We draw the addition of the
6th point. The
7th line will be ignored.
551 colorNew = green!
50!red,
553 colorBbox = black!
20,
560 \section{The
\emph{inc
} Macros
}\label{sec:inc
}
562 The three macros presented in the above sections have complementary
563 macros, with the suffix
\Verb+inc+ that allow the user to add code
564 (MetaPost or
\Verb+tikz+, depending of the drawing engine) before and
565 after the code generated by
\luamesh.
567 The three macros are:
\medskip
570 \commande|
\buildMeshBWinc[«options»
]{«list of points» or «file name»
}{«code before»
}{«code after»
}|
\medskip
572 \commande|
\drawPointsMeshinc[«options»
]{«list of points» or «file name»
}{«code before»
}{«code after»
}|
\medskip
574 \commande|
\meshAddPointBWinc[«options»
]{«list of points» or «file name»
}%|
576 \commande|
{«point» or «number of line»
}{«code before»
}{«code after»
}|
\medskip
578 \subsection{With MetaPost
}
580 We consider the case where the drawing engine is MetaPost (through the
581 \Verb+luamplib+ package).
583 We describe the feature taking one macro in example but the mechanism
584 and the possibilities are exactly the same for all the macros.
586 When we use the MetaPost drawing engine, the macros previously
587 described produced a code of the form
592 <code for the drawing>
597 Then, the arguments
\meta{code before
} and
\meta{code after
} are
603 <code for the drawing>
608 With the
\emph{inc
} macros, the user has to add the
\Verb+beginfig();+
609 and
\Verb+endfig;+ commands to produce a picture. Indeed, this allows
610 to use the
\Verb+
\everymplib+ command from the
\Verb+
\luamplib+ package.
613 \subsubsection{The
\LaTeX{} Colors Inside the MetaPost Code
}\label{sec:mpcolor
}
615 The configurable colors
616 of the
\LaTeX{} macro are accessible inside the MetaPost code. For
617 \Verb+
\buildMeshBWinc+ and
\Verb+
\drawPointsMeshinc+, we have
618 \Verb+
\luameshmpcolor+,
619 and
\Verb+
\luameshmpcolorBbox+.
620 For the macro
\Verb+
\meshAddPointBWinc+ we have three additional
621 colors :
\Verb+
\luameshmpcolorBack+,
\Verb+
\luameshmpcolorNew+, and
622 \Verb+
\luameshmpcolorCircle+. Of course, we can define MetoPost
623 colors as well. Finally, the
\Verb+luamplib+ mechanism of
624 \Verb+
\mpcolor+ is also available.
626 \subsubsection{The Mesh Points
}
628 At the beginning of the automatically generated code, a list of
629 MetaPost
\Verb+pair+s are defined corresponding to all the vertices of
630 the mesh (when the option
\Verb+bbox=show+, the last
4 points are the
631 \emph{bounding box points
}). The points are available with the
632 \Verb+MeshPoints
[]+ table of variables. The
\Verb+MeshPoints
[i
]+ are
633 defined using the unit length
\Verb+u+.
635 \subsubsection{Examples
}
637 Here is three examples for the different macros.
644 ]{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}%
649 label(btex Mesh $
\mathbb{T
}$ etex, (
0,
2u)) withcolor
\luameshmpcolor;
659 ]{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}%
664 drawdblarrow MeshPoints
[3] -- MeshPoints
[9] withpen pencircle scaled
1pt
665 withcolor (
0.3,
0.7,
0.2);
672 colorNew = green!
50!red,
674 colorBbox = black!
20,
678 {(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5)
}{(
2.8,
1.5)
}%
685 fill MeshPoints
[7]--MeshPoints
[8]--MeshPoints
[9]--MeshPoints
[10]--cycle
686 withcolor
\mpcolor{blue!
10};
692 The variables
\Verb+MeshPoints
[]+ are not defined for the argument
693 corresponding to the code to place before the code generated by
694 \luamesh. Hence, to use such variables, we have to define a
695 \Verb+picture+ as shown in the third example above.
699 \subsection{With TikZ
}
701 If we have chosen
\Verb+tikz+ as the engine drawing, the added code
702 will be written in
\Verb+tikz+. In that case, the two arguments
703 \meta{code before
} and
\meta{code after
} will be inserted as follows:
706 \begin{tikzpicture
}[x=<scale>,y=<scale>
]
713 Because the engine is
\Verb+tikz+ their is no issue with colors, the
714 \LaTeX{} colors (e.g.:
\Verb+xcolor+) can be directly used.
716 \subsubsection{The Mesh Points
}
718 The points of the mesh are defined here as
\Verb+tikz+
719 \Verb+
\coordinate+ named as follows
721 \coordinate (MeshPoints1) at (...,...);
722 \coordinate (MeshPoints2) at (...,...);
723 \coordinate (MeshPoints3) at (...,...);
727 Once again these coordinates are not yet defined for the
\meta{code
730 \subsubsection{Examples
}
739 ]{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5)
}%
743 \node[color = blue!
50] at (
0,
2)
{Mesh $
\mathbb{T
}$
} ;
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)
}%
757 \draw[<->,thick,
color=green
] (MeshPoints3) -- (MeshPoints9);
761 \section{Voronio Diagrams
}
763 Another interesting concept of Delaunay triangulation is that it is
764 \emph{dual
} to it so-called Voronio diagram. For a finite set of
765 points $\
{p_
{1},
\ldots, p_
{n
}\
}$ in the Euclidean plane, for all
766 $p_
{k
}$, it corresponds a Voronoi cell $R_
{k
}$ consisting of
767 every point in the Euclidean plane whose distance to $p_
{k
}$ is less
769 or equal to its distance to any other $p_
{k'
}$.
\bigskip
772 \commande|
\buildVoronoiBW[«options»
]{«list of points» or «file name»
}|
\medskip
774 This macro produce the Voronio diagram dual to the Delaunay
775 triangulation (computed by the Bowyer and Watson
776 algorithm) of the given
\meta{list of points
}. Once again, the
778 points must be given in the following way :
780 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
784 \buildVoronoiBW{(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5);(
0.1,
2);(
1.5,-
0.3)
}
787 \subsection{The Options
}\label{sec:voronoiOptions
}
790 There are several options to customize the drawing.
792 \item[mode = int (default)
\textme{or
} ext:
] this option allows to
793 use either the previously described set of points in the argument, or
794 a file, containing, line by line (
2 columns), the points. Such a
803 \item[bbox = none (default)
\textme{or
} show:
] this option allows to draw the
804 added points to form a
\emph{bounding box
}\footnote{The bounding
805 box is defined by four points place at
15\% around the box
806 defined by $(x_
{\min},y_
{\min})$, $(x_
{\min},y_
{\max})$,
807 $(x_
{\max},y_
{\max})$, and $(x_
{\min},y_
{\max})$. It is used by
808 the algorithm and will be computed in any case.
} and the corresponding
809 triangulation. By default, these points are removed at the end of
811 \item[color =
\meta{value
} (default: black):
] The
color of the
813 \item[colorBbox =
\meta{value
} (default: black):
] The
color of the
814 drawing for the elements (points and triangles) belonging to the
816 \item[colorVoronoi =
\meta{value
} (default: black):
] The
color of the
817 drawing for the elements (points and polygons) belonging to the
819 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
820 triangulation. Contrary to the previous macros, where
821 \Verb+print=none+, a
\emph{dot
} is produced at each vertex (of the
822 set of points and on the circumcircle center which are the nodes of
823 the Voronoi diagram).
824 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
825 label the vertices of the triangulation. It is included in the math
826 mode delimiters
\Verb+$...$+. The bounding box points are labeled
827 with numbers
1 to
4 and with a star exponent.
828 \item[circumpoint =
\meta{value
} (default: P):
] The letter(s) used to
829 label the vertices of the Voronoi diagram. It is included in the math
830 mode delimiters
\Verb+$...$+.
831 \item[tikz (boolean, default:false):
] By default, this boolean is set
832 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
833 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
835 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
836 the scale at which the picture is drawn (the same for both
837 axes). It must contain the unit of length (cm,
839 \item[delaunay = none (default)
\textme{or
} show
] This option
840 allows to draw the Delaunay triangulation under the Voronoi diagram.
841 \item[styleDelaunay = none (default)
\textme{or
} dashed
] This option
842 allows to draw dashed lines for the Delaunay triangulation.
843 \item[styleVoronoi = none (default)
\textme{or
} dashed
] This option
844 allows to draw dashed lines for the Voronoi edges.
848 \buildVoronoiBW[tikz,delaunay=show,styleDelaunay=dashed
]
849 {(
0.3,
0.3);(
1.5,
1);(
4,
0);(
4.5,
2.5);(
1.81,
2.14);(
2.5,
0.5);(
2.8,
1.5);(
0.1,
2);(
1.5,-
0.3)
}
852 \subsection{The
\emph{inc
} variant
}
854 Once again, a variant of the macros is available allowing the user to
855 add code before and after the code produced by
\luamesh. We refer to
856 the section~
\ref{sec:inc
} because it works the same way.
860 \item with MetaPost, the circumcenters are defined using
861 \Verb+pair CircumPoints
[];+, and so, are accessible.
862 \item With
\Verb+tikz+, there are new coordinates defined as follows
864 \coordinate (CircumPoints1) at (...,...);
865 \coordinate (CircumPoints2) at (...,...);
866 \coordinate (CircumPoints3) at (...,...);
871 Finally, when the MetaPost drawing engine is used, another
color is
872 available (see~
\ref{sec:mpcolor
}):
\Verb+
\luameshmpcolorVoronoi+.
877 Gmsh is a open source efficient software that produces meshes. The
878 exporting format is the
\emph{MSH ASCII file format
} and can be easily
879 read by a Lua program.
\luamesh provides the user with dedicated
880 macros to read and draw meshes coming from a Gmsh exportation.
\bigskip
882 \commande|
\drawGmsh[«options»
]{«file name»
}|
\medskip
884 This macro draw the triangulation produced by Gmsh and exported in the
885 \Verb+msh+ format. The argument is the name of the file to read
886 (e.g.:
\Verb+maillage.msh+).
889 \drawGmsh{maillage.msh
}
892 There are several options to customize the drawing.
894 \item[color =
\meta{value
} (default: black):
] The
color of the
896 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
897 triangulation. Contrary to the previous macros, where
898 \Verb+print=none+, a
\emph{dot
} is produced at each vertex (of the
899 set of points and on the circumcircle center which are the nodes of
900 the Voronoi diagram).
901 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
902 label the vertices of the triangulation. It is included in the math
903 mode delimiters
\Verb+$...$+. The bounding box points are labeled
904 with numbers
1 to
4 and with a star exponent.
905 \item[tikz (boolean, default:false):
] By default, this boolean is set
906 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
907 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
909 \item[scale =
\meta{value
} (default:
1cm):
] The scale option defines
910 the scale at which the picture is drawn (the same for both
911 axes). It must contain the unit of length (cm,
916 \drawGmsh[scale=
2cm,print=points,
color=blue!
30]{maillage.msh
}
919 \subsection{Gmsh and Voronoi Diagrams
}
921 Because Gmsh generates Delaunay triangulations, we can plot the
922 Voronoi diagram associated. This is done by the following macro:
\bigskip
924 \commande|
\gmshVoronoi[«options»
]{«file name»
}|
\medskip
927 \gmshVoronoi{maillage.msh
}
931 \subsection{The Options
}\label{sec:voronoiOptions
}
934 There are several options to customize the drawing.
936 \item[color =
\meta{value
} (default: black):
] The
color of the
938 \item[colorVoronoi =
\meta{value
} (default: black):
] The
color of the
939 drawing for the elements (points and polygons) belonging to the
941 \item[print = none (default)
\textme{or
} points:
] To label the vertices of the
942 triangulation. Contrary to the previous macros, where
943 \Verb+print=none+, a
\emph{dot
} is produced at each vertex (of the
944 set of points and on the circumcircle center which are the nodes of
945 the Voronoi diagram).
946 \item[meshpoint =
\meta{value
} (default: P):
] The letter(s) used to
947 label the vertices of the triangulation. It is included in the math
948 mode delimiters
\Verb+$...$+. The bounding box points are labeled
949 with numbers
1 to
4 and with a star exponent.
950 \item[circumpoint =
\meta{value
} (default: P):
] The letter(s) used to
951 label the vertices of the Voronoi diagram. It is included in the math
952 mode delimiters
\Verb+$...$+.
953 \item[tikz (boolean, default:false):
] By default, this boolean is set
954 to
\Verb+false+, and MetaPost (with
\Verb+luamplib+) is used to draw
955 the picture. With this option,
\Verb+tikz+ becomes the
\textit{drawing
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 Voronoi diagram.
963 \item[styleDelaunay = none (default)
\textme{or
} dashed
] This option
964 allows to draw dashed lines for the Delaunay triangulation.
965 \item[styleVoronoi = none (default)
\textme{or
} dashed
] This option
966 allows to draw dashed lines for the Voronoi edges.
970 \gmshVoronoi[tikz,scale=
1.5cm, delaunay=show,styleVoronoi=dashed
]{maillage.msh
}
974 \subsection{The
\emph{inc
} variants
}
976 Once again, there exists
\emph{inc
} variant macros:
\bigskip
978 \commande|
\drawGmshinc[«options»
]{«file name»
}{«code before»
}{«code after»
}|
\medskip
980 \commande|
\gmshVoronoiinc[«options»
]{«file name»
}{«code before»
}{«code after»
}|
\medskip
982 We refer to the previous sections for explanations.
985 \subsection{With Animate
}
987 If you use
\emph{adobe acrobat reader
}, you can easily produce an
988 animation of the Bowyer and Watson algorithm with the package
991 For example, the following code (in a file name
\Verb+animation.tex+):
993 \documentclass{article
}
994 %% lualatex compilation
995 \usepackage[margin=
2.5cm
]{geometry
}
997 \usepackage{fontspec
}
1000 \def\drawPath{draw (-
2,-
2)*u--(
8,-
2)*u--(
8,
6)*u--(-
2,
6)*u--cycle withcolor
0.99white;
}
1001 \def\clipPath{clip currentpicture to (-
2,-
2)*u--(
8,-
2)*u--(
8,
6)*u--(-
2,
6)*u--cycle;
}
1003 \drawPointsMeshinc[mode=ext, bbox = show,colorBbox = blue!
20,print=points
]{mesh.txt
}%
1012 \newpage\buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!
20,print=points
]{meshInit.txt
}%
1021 \multido{\ii=
5+
1}{4}{%
1022 \newpage\meshAddPointBWinc[mode=ext,step=badtriangles,colorNew
1023 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1024 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1033 \meshAddPointBWinc[mode=ext,step=cavity,colorNew
1034 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1035 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1044 \meshAddPointBWinc[mode=ext,step=newtriangles,colorNew
1045 =green!
20!red,colorBack=red!
10,colorCircle = blue,bbox =
1046 show,colorBbox = blue!
20]{mesh.txt
}{\ii}%
1057 \buildMeshBWinc[mode=ext,bbox = show,colorBbox = blue!
20,print=points
]{mesh.txt
}%
1067 \buildMeshBWinc[mode=ext,print=points
]{mesh.txt
}%
1078 produces a PDF with multiple pages. Using the
\Verb+pdfcrop+ program,
1079 we crop the pages to the material, and then we can animate the PDF
1080 using the
\Verb+animate+ package.
1083 %\animategraphics[controls]{1}{animation-crop}{}{}
1092 %%% Local Variables:
1093 %%% flyspell-mode: 1
1094 %%% ispell-local-dictionary: "american"