\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+$...$+.
-\item[step = polyqon \textme{or} grid \textme{or}
+\item[step = polygon \textme{or} grid \textme{or}
points \textme{or} mesh (default):] To choose the step we want to draw,
see the description above.
\item[tikz (boolean, default:false):] By default, this boolean is set
the scale at which the picture is drawn (the same for both
axis). It must contain the unit of length (cm,
pt, etc.).
+\item[gridpoints = rect (default) \textme{or} perturb:] This option
+ allows to specify the mode of generation of the grid points. The
+ value \Verb+rect+ produces a simple rectangular grid, and the value
+ \Verb+pertub+ randomly perturbs the rectangular grid.
\end{optionsenum}
Here is an example of customizing the drawing.
colorPolygon=red!120,
scale=4cm,
step=mesh,
- print=points]
+ print=points,
+ gridpoints=perturb]
{(0,0);(1,0);(1,0.5);(0,0.5);(-0.20,0.35);(-0.25,0.25);(-0.20,0.15)}
\end{Exemple}
\contentsline {subsection}{\numberline {2.4}Mesh a Polygon}{11}{subsection.2.4}
\contentsline {subsubsection}{\numberline {2.4.1}The Options}{12}{subsubsection.2.4.1}
\contentsline {section}{\numberline {3}The \emph {inc} Macros}{13}{section.3}
-\contentsline {subsection}{\numberline {3.1}With MetaPost}{13}{subsection.3.1}
+\contentsline {subsection}{\numberline {3.1}With MetaPost}{14}{subsection.3.1}
\contentsline {subsubsection}{\numberline {3.1.1}The \LaTeX {} Colors Inside the MetaPost Code}{14}{subsubsection.3.1.1}
\contentsline {subsubsection}{\numberline {3.1.2}The Mesh Points}{14}{subsubsection.3.1.2}
-\contentsline {subsubsection}{\numberline {3.1.3}Examples}{14}{subsubsection.3.1.3}
+\contentsline {subsubsection}{\numberline {3.1.3}Examples}{15}{subsubsection.3.1.3}
\contentsline {subsection}{\numberline {3.2}With TikZ}{16}{subsection.3.2}
\contentsline {subsubsection}{\numberline {3.2.1}The Mesh Points}{16}{subsubsection.3.2.1}
\contentsline {subsubsection}{\numberline {3.2.2}Examples}{17}{subsubsection.3.2.2}
function drawMeshPolygonMP(chaine,mode,h,step,
- points,scale)
+ points,scale,random)
local polygon = buildList(chaine, mode)
polygon = addPointsPolygon(polygon,h)
- local grid = buildGrid(polygon,h)
+ local grid = buildGrid(polygon,h,random)
local listPoints = addGridPoints(polygon,grid,h)
if(step=="polygon") then
-- the polygon
function drawMeshPolygonTikZ(chaine,mode,h,step,
- points,scale,color,colorPoly)
+ points,scale,color,colorPoly,random)
local polygon = buildList(chaine, mode)
polygon = addPointsPolygon(polygon,h)
- local grid = buildGrid(polygon,h)
+ local grid = buildGrid(polygon,h,random)
local listPoints = addGridPoints(polygon,grid,h)
if(step=="polygon") then
-- the polygon
end
function drawMeshPolygonMPinc(chaine,beginning,ending,mode,h,step,
- points,scale)
+ points,scale,random)
local polygon = buildList(chaine, mode)
polygon = addPointsPolygon(polygon,h)
- local grid = buildGrid(polygon,h)
+ local grid = buildGrid(polygon,h,random)
local listPoints = addGridPoints(polygon,grid,h)
if(step=="polygon") then
-- the polygon
function drawMeshPolygonTikZinc(chaine,beginning,ending,mode,h,step,
- points,scale,color,colorPoly)
+ points,scale,color,colorPoly,random)
local polygon = buildList(chaine, mode)
polygon = addPointsPolygon(polygon,h)
- local grid = buildGrid(polygon,h)
+ local grid = buildGrid(polygon,h,random)
local listPoints = addGridPoints(polygon,grid,h)
if(step=="polygon") then
-- the polygon
-- function to build a gridpoints from the bounding box
-- with a prescribed
-function buildGrid(listPoints,h)
+function buildGrid(listPoints,h,random)
-- listPoints : list of the points of the polygon, ordered
-- h : parameter for the grid
xmin, xmax, ymin, ymax = BoundingBox(listPoints)
- local grid = rectangleList(xmin,xmax,ymin,ymax,h)
+ local grid = rectangleList(xmin,xmax,ymin,ymax,h,random)
return grid
end
-- function to build the list of points in the rectangle
-function rectangleList(xmin,xmax,ymin,ymax,h)
+function rectangleList(xmin,xmax,ymin,ymax,h,random)
+ -- for the random
+ math.randomseed( os.time() )
nbrX = math.floor(math.abs(xmax-xmin)/h)
nbrY = math.floor(math.abs(ymax-ymin)/h)
local listPoints = {}
k=1
for i=1,(nbrX+1) do
for j=1,(nbrY+1) do
- listPoints[k] = {x = xmin+(i-1)*h, y=ymin+(j-1)*h}
+ rd = math.random()
+ if(random=="perturb") then
+ fact = 0.3*h
+ --print(fact)
+ else
+ fact = 0.0
+ end
+ listPoints[k] = {x = xmin+(i-1)*h+rd*fact, y=ymin+(j-1)*h+rd*fact}
k=k+1
end
end
\def\luameshval@mp@mode{ext}%
\fi%
}%
+%% the mode for the generation of gridpoints
+\define@choicekey*{meshPolygon}{gridpoints}[\val\nr]{rect, perturb}{%
+ \ifcase\nr\relax%
+ \def\luameshval@mp@gridpoints{rect}%
+ \or%
+ \def\luameshval@mp@gridpoints{perturb}%
+ \fi%
+}%
%% the different steps of the meshing
\define@choicekey*{meshPolygon}{step}[\val\nr]{polygon, grid, points, mesh}{%
\ifcase\nr\relax%
\define@key{meshPolygon}{colorPolygon}[red]{\def\luameshval@mp@colorPolygon{#1}}%
%% the name of the color of drawing the bbox
%
-\presetkeys{meshPolygon}{tikz=false,scale,mode=int,step=mesh,print=none,color,colorPolygon,h,meshpoint}{}%
+\presetkeys{meshPolygon}{tikz=false,scale,mode=int,step=mesh,print=none,color,colorPolygon,h,meshpoint,gridpoints=rect}{}%
%
\newcommand{\meshPolygon}[2][]{%
% #1 : optionnal arguments
\def\MeshPoint{\luameshval@mp@meshpoint}%
\ifKV@meshPolygon@tikz% if we are using tikz
\directlua{%
- drawMeshPolygonTikZ("#2","\luameshval@mp@mode","\luameshval@mp@h","\luameshval@mp@step","\luameshval@mp@print","\luameshval@mp@scale","\luameshval@mp@color","\luameshval@mp@colorPolygon")%
+ drawMeshPolygonTikZ("#2","\luameshval@mp@mode","\luameshval@mp@h","\luameshval@mp@step","\luameshval@mp@print","\luameshval@mp@scale","\luameshval@mp@color","\luameshval@mp@colorPolygon","\luameshval@mp@gridpoints")%
}%
\else % we are using MP
\mplibcolor{\luameshmpcolor}{\luameshval@mp@color}%
\mplibcolor{\luameshmpcolorPoly}{\luameshval@mp@colorPolygon}%
\directlua{%
- drawMeshPolygonMP("#2","\luameshval@mp@mode","\luameshval@mp@h","\luameshval@mp@step","\luameshval@mp@print","\luameshval@mp@scale")%
+ drawMeshPolygonMP("#2","\luameshval@mp@mode","\luameshval@mp@h","\luameshval@mp@step","\luameshval@mp@print","\luameshval@mp@scale","\luameshval@mp@gridpoints")%
}%
%
\fi%
\def\luameshval@mpi@print{dotpoints}%
\fi%
}%
+%% the mode for the generation of gridpoints
+\define@choicekey*{meshPolygonInc}{gridpoints}[\val\nr]{rect, perturb}{%
+ \ifcase\nr\relax%
+ \def\luameshval@mpi@gridpoints{rect}%
+ \or%
+ \def\luameshval@mpi@gridpoints{perturb}%
+ \fi%
+}%
%% the name of the point
\define@key{meshPolygonInc}{meshpoint}[P]{\def\luameshval@mpi@meshpoint{#1}}%
%% the grid parameter
\define@key{meshPolygonInc}{colorPolygon}[red]{\def\luameshval@mpi@colorPolygon{#1}}%
%% the name of the color of drawing the bbox
%
-\presetkeys{meshPolygonInc}{tikz=false,scale,mode=int,step=mesh,print=none,color,colorPolygon,h,meshpoint}{}%
+\presetkeys{meshPolygonInc}{tikz=false,scale,mode=int,step=mesh,print=none,color,colorPolygon,h,meshpoint,gridpoints=rect}{}%
%
\newcommand{\meshPolygonInc}[4][]{%
% #1 : optionnal arguments
\def\MeshPoint{\luameshval@mpi@meshpoint}%
\ifKV@meshPolygonInc@tikz% if we are using tikz
\directlua{%
- drawMeshPolygonTikZinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@mpi@mode","\luameshval@mpi@h","\luameshval@mpi@step","\luameshval@mpi@print","\luameshval@mpi@scale","\luameshval@mpi@color","\luameshval@mpi@colorPolygon")%
+ drawMeshPolygonTikZinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@mpi@mode","\luameshval@mpi@h","\luameshval@mpi@step","\luameshval@mpi@print","\luameshval@mpi@scale","\luameshval@mpi@color","\luameshval@mpi@colorPolygon","\luameshval@mpi@gridpoints")%
}%
\else % we are using MP
\mplibcolor{\luameshmpcolor}{\luameshval@mpi@color}%
\mplibcolor{\luameshmpcolorPoly}{\luameshval@mpi@colorPolygon}%
\directlua{%
- drawMeshPolygonMPinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@mpi@mode","\luameshval@mpi@h","\luameshval@mpi@step","\luameshval@mpi@print","\luameshval@mpi@scale")%
+ drawMeshPolygonMPinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@mpi@mode","\luameshval@mpi@h","\luameshval@mpi@step","\luameshval@mpi@print","\luameshval@mpi@scale","\luameshval@mpi@gridpoints")%
}%
%
\fi%
\meshPolygon[step=polygon,scale=3cm]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
\meshPolygon[step=grid,scale=3cm]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
\meshPolygon[step=points,scale=3cm,print=points]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
-\meshPolygon[step=mesh,scale=3cm,print=dotpoints]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
+\meshPolygon[step=mesh,scale=3cm,print=dotpoints,gridpoints=perturb]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
\meshPolygon[tikz,step=polygon,scale=3cm]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
\meshPolygon[tikz,step=grid,scale=3cm]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}