\documentclass{lltxdoc}
\usepackage{tcolorbox}
-\usepackage{xargs}
\usepackage{enumitem}
\usepackage[tikz]{bclogo}
\usepackage{wrapfig}
+\usepackage{animate}
+
\title{\Verb+luamesh+: compute and draw meshes with \lualatex}
\author{Maxime Chupin \email{mc@melusine.eu.org}}
\date{\today}
\lstset{moredelim=*[s][\color{red}\rmfamily\itshape]{<}{>}}
\lstset{moredelim=*[s][\color{blue}\rmfamily\itshape]{<<}{>>}}
-
+\usepackage[colorlinks=true]{hyperref}
\begin{document}
%% === Page de garde ===================================================
\thispagestyle{empty}
}
\vfill
\begin{center}
- Version 0.1, 25 novembre 2016\\
+ Version 0.2, 29 novembre 2016\\
\url{http://melusine.eu.org/syracuse/G/delaunay/}
\end{center}
%% == Page de garde ====================================================
I would also like to thank the first user, an intensive
\emph{test} user, and a very kind English corrector: Nicole Spillane.
+\tableofcontents
+
\section{Installation}
(MetaPost or \Verb+tikz+, depending of the drawing engine) before and
after the code generated by \luamesh.
-The three macros are:
+The three macros are:\medskip
+
\commande|\buildMeshBWinc[«options»]{«list of points» or «file name»}{«code before»}{«code after»}|\medskip
to use the \Verb+\everymplib+ command from the \Verb+\luamplib+ package.
\end{warning}
-\subsubsection{The \LaTeX{} Colors Inside the MetaPost Code}
+\subsubsection{The \LaTeX{} Colors Inside the MetaPost Code}\label{sec:mpcolor}
The configurable colors
of the \LaTeX{} macro are accessible inside the MetaPost code. For
colors as well. Finally, the \Verb+luamplib+ mechanism of
\Verb+\mpcolor+ is also available.
-\subsubsection{The Mesh Points with MetaPost}
+\subsubsection{The Mesh Points}
At the beginning of the automatically generated code, a list of
MetaPost \Verb+pair+s are defined corresponding to all the vertices of
\subsection{With TikZ}
+If we have chosen \Verb+tikz+ as the engine drawing, the added code
+will be written in \Verb+tikz+. In that case, the two arguments
+\meta{code before} and \meta{code after} will be inserted as follows:
+\begin{latexcode}
+\noindent
+\begin{tikzpicture}[x=<scale>,y=<scale>]
+ <<code before>>
+ <generated code>
+ <<code after>>
+\end{tikzpicture}
+\end{latexcode}
+
+Because the engine is \Verb+tikz+ their is no issue with colors, the
+\LaTeX{} colors (e.g.: \Verb+xcolor+) can be directly used.
+
+\subsubsection{The Mesh Points}
+
+The points of the mesh are defined here as \Verb+tikz+
+\Verb+\coordinate+ named as follows
+\begin{latexcode}
+\coordinate (MeshPoints1) at (...,...);
+\coordinate (MeshPoints2) at (...,...);
+\coordinate (MeshPoints3) at (...,...);
+%etc.
+\end{latexcode}
+
+Once again these coordinates are not yet defined for the \meta{code
+ before} argument.
+
+\subsubsection{Examples}
+
+\begin{Exemple}
+ \drawPointsMeshinc[
+ tikz,
+ color = blue!50,
+ print = points,
+ meshpoint = x,
+ scale=0.8cm,
+ ]{(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)}%
+ {% code before
+ }%
+ {% code after
+ \node[color = blue!50] at (0,2) {Mesh $\mathbb{T}$} ;
+ }
+ \buildMeshBWinc[%
+ tikz,
+ bbox = show,
+ color = red,
+ colorBbox = blue!30,
+ print = points,
+ meshpoint = x,
+ scale=0.8cm
+ ]{(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)}%
+ {% code before
+ }
+ {% code after
+ \draw[<->,thick, color=green] (MeshPoints3) -- (MeshPoints9);
+ }
+\end{Exemple}
+
+\section{Voronio Diagrams}
+
+Another interesting concept of Delaunay triangulation is that it is
+\emph{dual} to it so-called Voronio diagram. For a finite set of
+points $\{p_{1},\ldots, p_{n}\}$ in the Euclidean plane, for all
+$p_{k}$, it corresponds a Voronoi cell $R_{k}$ consisting of
+every point in the Euclidean plane whose distance to $p_{k}$ is less
+than
+or equal to its distance to any other $p_{k'}$.\bigskip
+
+
+\commande|\buildVoronoiBW[«options»]{«list of points» or «file name»}|\medskip
+
+This macro produce the Voronio diagram dual to the Delaunay
+triangulation (computed by the Bowyer and Watson
+algorithm) of the given \meta{list of points}. Once again, the
+list of
+points must be given in the following way :
+\begin{center}
+ \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
+\end{center}
+
+\begin{Exemple}
+ \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)}
+\end{Exemple}
+
+\subsection{The Options}\label{sec:voronoiOptions}
+
+
+There are several options to customize the drawing.
+\begin{optionsenum}
+\item[mode = int (default) \textme{or} ext:] this option allows to
+ use either the previously described set of points in the argument, or
+ a file, containing, line by line (2 columns), the points. Such a
+ file looks like :
+\begin{verbatim}
+x1 y1
+x2 y2
+x3 y3
+...
+xn yn
+\end{verbatim}
+\item[bbox = none (default) \textme{or} show:] this option allows to draw the
+ added points to form a \emph{bounding box}\footnote{The bounding
+ box is defined by four points place at 15\% around the box
+ defined by $(x_{\min},y_{\min})$, $(x_{\min},y_{\max})$,
+ $(x_{\max},y_{\max})$, and $(x_{\min},y_{\max})$. It is used by
+ the algorithm and will be computed in any case.} and the corresponding
+ triangulation. By default, these points are removed at the end of
+ the algorithm.
+\item[color = \meta{value} (default: black):] The color of the
+ drawing.
+\item[colorBbox = \meta{value} (default: black):] The color of the
+ drawing for the elements (points and triangles) belonging to the
+ bounding box.
+\item[colorVoronoi = \meta{value} (default: black):] The color of the
+ drawing for the elements (points and polygons) belonging to the
+ Voronoi diagram.
+\item[print = none (default) \textme{or} points:] To label the vertices of the
+ triangulation. Contrary to the previous macros, where
+ \Verb+print=none+, a \emph{dot} is produced at each vertex (of the
+ set of points and on the circumcircle center which are the nodes of
+ the Voronoi diagram).
+\item[meshpoint = \meta{value} (default: P):] The letter(s) used to
+ label the vertices of the triangulation. It is included in the math
+ mode delimiters \Verb+$...$+. The bounding box points are labeled
+ with numbers 1 to 4 and with a star exponent.
+\item[circumpoint = \meta{value} (default: P):] The letter(s) used to
+ label the vertices of the Voronoi diagram. It is included in the math
+ mode delimiters \Verb+$...$+.
+\item[tikz (boolean, default:false):] By default, this boolean is set
+ to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
+ the picture. With this option, \Verb+tikz+ becomes the \textit{drawing
+ engine}.
+\item[scale = \meta{value} (default: 1cm):] The scale option defines
+ the scale at which the picture is drawn (the same for both
+ axes). It must contain the unit of length (cm,
+ pt, etc.).
+\end{optionsenum}
+
+
+\subsection{The \emph{inc} variant}
+
+Once again, a variant of the macros is available allowing the user to
+add code before and after the code produced by \luamesh. We refer to
+the section~\ref{sec:inc} because it works the same way.
+
+Let us note that:
+\begin{itemize}
+\item with MetaPost, the circumcenters are defined using
+ \Verb+pair CircumPoints[];+, and so, are accessible.
+\item With \Verb+tikz+, there are new coordinates defined as follows
+ \begin{latexcode}
+ \coordinate (CircumPoints1) at (...,...);
+ \coordinate (CircumPoints2) at (...,...);
+ \coordinate (CircumPoints3) at (...,...);
+ % etc.
+ \end{latexcode}
+\end{itemize}
+
+Finally, when the MetaPost drawing engine is used, another color is
+available (see~\ref{sec:mpcolor}): \Verb+\luameshmpcolorVoronoi+.
+
+
+\section{With Gmsh}
+
+Gmsh is a open source efficient software that produces meshes. The
+exporting format is the \emph{MSH ASCII file format} and can be easily
+read by a Lua program. \luamesh provides the user with dedicated
+macros to read and draw meshes coming from a Gmsh exportation.\bigskip
+
+\commande|\drawGmsh[«options»]{«file name»}|\medskip
+
+This macro draw the triangulation produced by Gmsh and exported in the
+\Verb+msh+ format. The argument is the name of the file to read
+(e.g.: \Verb+maillage.msh+).
+
+\begin{Exemple}
+\drawGmsh{maillage.msh}
+\end{Exemple}
+
+There are several options to customize the drawing.
+\begin{optionsenum}
+\item[color = \meta{value} (default: black):] The color of the
+ drawing.
+\item[print = none (default) \textme{or} points:] To label the vertices of the
+ triangulation. Contrary to the previous macros, where
+ \Verb+print=none+, a \emph{dot} is produced at each vertex (of the
+ set of points and on the circumcircle center which are the nodes of
+ the Voronoi diagram).
+\item[meshpoint = \meta{value} (default: P):] The letter(s) used to
+ label the vertices of the triangulation. It is included in the math
+ mode delimiters \Verb+$...$+. The bounding box points are labeled
+ with numbers 1 to 4 and with a star exponent.
+\item[tikz (boolean, default:false):] By default, this boolean is set
+ to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
+ the picture. With this option, \Verb+tikz+ becomes the \textit{drawing
+ engine}.
+\item[scale = \meta{value} (default: 1cm):] The scale option defines
+ the scale at which the picture is drawn (the same for both
+ axes). It must contain the unit of length (cm,
+ pt, etc.).
+\end{optionsenum}
+Here is an example:
+\begin{Exemple}
+ \drawGmsh[scale=2cm,print=points, color=blue!30]{maillage.msh}
+\end{Exemple}
+
+\subsection{Gmsh and Voronoi Diagrams}
+
+Because Gmsh generates Delaunay triangulations, we can plot the
+Voronoi diagram associated. This is done by the following macro:\bigskip
+
+\commande|\gmshVoronoi[«options»]{«file name»}|\medskip
+
+\begin{Exemple}
+ \gmshVoronoi{maillage.msh}
+\end{Exemple}
+
+We refer to the section~\ref{sec:voronoiOptions} for the list of the options.
+
+\subsection{The \emph{inc} variants}
+
+Once again, there exists \emph{inc} variant macros:\bigskip
+
+\commande|\drawGmshinc[«options»]{«file name»}{«code before»}{«code after»}|\medskip
+
+\commande|\gmshVoronoiinc[«options»]{«file name»}{«code before»}{«code after»}|\medskip
+
+We refer to the previous sections for explanations.
+
+\section{Gallery}
+\subsection{With Animate}
+
+If you use \emph{adobe acrobat reader}, you can easily produce an
+animation of the Bowyer and Watson algorithm with the package
+\Verb+animate+.
+
+For example, the following code (in a file name \Verb+animation.tex+):
+\begin{latexcode}
+ \documentclass{article}
+ %% lualatex compilation
+ \usepackage[margin=2.5cm]{geometry}
+ \usepackage{luamesh}
+ \usepackage{fontspec}
+ \usepackage{multido}
+ \pagestyle{empty}
+
+ \def\drawPath{draw (-2,-2)*u--(8,-2)*u--(8,6)*u--(-2,6)*u--cycle withcolor 0.99white;}
+ \def\clipPath{clip currentpicture to (-2,-2)*u--(8,-2)*u--(8,6)*u--(-2,6)*u--cycle;}
+
+ \begin{document}
+
+ \drawPointsMeshinc[
+ mode=ext,
+ bbox = show,
+ colorBbox = blue!20,
+ print=points
+ ]
+ {mesh.txt}%
+ {%
+ beginfig(0);
+ \drawPath
+ }%
+ {%
+ \clipPath
+ endfig;
+ }
+ \newpage
+ \buildMeshBWinc[
+ mode=ext,
+ bbox = show,
+ colorBbox = blue!20,
+ print=points
+ ]
+ {meshInit.txt}%
+ {%
+ beginfig(0);
+ \drawPath
+ }%
+ {%
+ \clipPath
+ endfig;
+ }
+ \multido{\ii=5+1}{4}{%
+ \newpage
+ \meshAddPointBWinc[
+ mode=ext,step=badtriangles,
+ colorNew =green!20!red,
+ colorBack=red!10,
+ colorCircle = blue,
+ bbox = show,
+ colorBbox = blue!20
+ ]
+ {mesh.txt}{\ii}%
+ {%
+ beginfig(0);
+ \drawPath
+ }%
+ {%
+ \clipPath
+ endfig;
+ } \newpage
+ \meshAddPointBWinc[
+ mode=ext,step=cavity,
+ colorNew =green!20!red,
+ colorBack=red!10,
+ colorCircle = blue,
+ bbox = show,
+ colorBbox = blue!20
+ ]
+ {mesh.txt}{\ii}%
+ {%
+ beginfig(0);
+ \drawPath
+ }%
+ {%
+ \clipPath
+ endfig;
+ } \newpage
+ \meshAddPointBWinc[
+ mode=ext,step=newtriangles,
+ colorNew =green!20!red,
+ colorBack=red!10,
+ colorCircle = blue,
+ bbox = show,
+ colorBbox = blue!20]
+ {mesh.txt}{\ii}%
+ {%
+ beginfig(0);
+ \drawPath
+ }%
+ {%
+ \clipPath
+ endfig;
+ }
+ }
+ \newpage
+ \buildMeshBWinc[
+ mode=ext,
+ bbox = show,
+ colorBbox = blue!20,
+ print=points
+ ]
+ {mesh.txt}%
+ {%
+ beginfig(0);
+ \drawPath
+ }%
+ {%
+ \clipPath
+ endfig;
+ }
+ \newpage
+ \buildMeshBWinc[
+ mode=ext,
+ print=points
+ ]
+ {mesh.txt}%
+ {%
+ beginfig(0);
+ \drawPath
+ }%
+ {%
+ \clipPath
+ endfig;
+ }
+\end{document}
+\end{latexcode}
+produces a PDF with multiple pages. Using the \Verb+pdfcrop+ program,
+we crop the pages to the material, and then we can animate the PDF
+using the \Verb+animate+ package.
+%\begin{Exemple}
+%\animategraphics[controls]{1}{animation-crop}{}{}
+%\end{Exemple}
-\section{Gallery of Examples}
+\input{dum.bbl}
\end{document}