end
end
end
+ if(points=="dotpoints") then
+ j=1
+ for i=1,#listPoints do
+ if(listPoints[i].type == "bbox") then
+ output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$};"
+ j=j+1
+ else
+ output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$};"
+ end
+ end
+ end
return output
end
-- Meshing of a polygon --
--------------------------------------------------
-
-function TeXMeshPolygonMP(polygon,listPoints, grid, step)
-
-end
-
function tracePolygonMP(polygon,points)
output = "";
output = output .. "pair polygon[];"
end
+function tracePolygonTikZ(polygon,points, colorPoly)
+ output = "";
+ for i=1,#polygon do
+ output = output .. "\\coordinate (polygon".. i .. ") at (" .. polygon[i].x .. "," .. polygon[i].y .. ");"
+ end
+ output = output .. "\\draw[color=".. colorPoly .. ", thick]"
+ for i=1,#polygon do
+ output = output .. "(" .. polygon[i].x .. "," .. polygon[i].y .. ") -- "
+ end
+ output = output .. "cycle;"
+ if(points=="points") then
+ for i=1,#polygon do
+ output = output .. "\\draw[color="..colorPoly.."] (" .. polygon[i].x ..",".. polygon[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
+ end
+ end
+ if(points=="dotpoints") then
+ for i=1,#polygon do
+ output = output .. "\\draw[color="..colorPoly.."] (" .. polygon[i].x ..",".. polygon[i].y .. ") node {$\\bullet$};"
+ end
+ end
+ return output
+end
+
+
function drawMeshPolygonMP(chaine,mode,h,step,
points,scale)
output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
tex.sprint(output)
end
+
+
+
+function drawMeshPolygonTikZ(chaine,mode,h,step,
+ points,scale,color,colorPoly)
+ local polygon = buildList(chaine, mode)
+ polygon = addPointsPolygon(polygon,h)
+ local grid = buildGrid(polygon,h)
+ local listPoints = addGridPoints(polygon,grid,h)
+ if(step=="polygon") then
+ -- the polygon
+ output = tracePolygonTikZ(polygon,points,colorPoly)
+ end
+ if(step=="grid") then
+ -- polygon + grid
+ output = tracePointsTikZ(grid,points,color,"none") -- none for colorBbox
+ output = output .. tracePolygonTikZ(polygon,points,colorPoly)
+ end
+ if(step=="points") then
+ -- polygon + only grid points inside the polygon
+ output = tracePointsTikZ(listPoints,points,color,"none")
+ output = output .. tracePolygonTikZ(polygon,points,colorPoly)
+ end
+ if(step=="mesh") then
+ -- polygon + mesh
+ triangulation = BowyerWatson(listPoints,"none") -- no bbox
+ output = traceMeshTikZ(listPoints,triangulation,points,color,"none")
+ output = output .. tracePolygonTikZ(polygon,points,colorPoly)
+ end
+ output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
+ tex.sprint(output)
+end
\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}{}%
+\presetkeys{meshPolygon}{tikz=false,scale,mode=int,step=mesh,print=none,color,colorPolygon,h,meshpoint}{}%
%
\newcommand{\meshPolygon}[2][]{%
% #1 : optionnal arguments
\def\MeshPoint{\luameshval@mp@meshpoint}%
\ifKV@meshPolygon@tikz% if we are using tikz
\directlua{%
- drawMeshPolygonTikZBW("#2","\luameshval@mp@mode","\luameshval@mp@print","\luameshval@mp@bbox","\luameshval@mp@scale","\luameshval@mp@delaunay","\luameshval@mp@color","\luameshval@mp@colorbbox","\luameshval@mp@colorVoronoi","\luameshval@mp@styleDelaunay","\luameshval@mp@styleVoronoi")%
+ drawMeshPolygonTikZ("#2","\luameshval@mp@mode","\luameshval@mp@h","\luameshval@mp@step","\luameshval@mp@print","\luameshval@mp@scale","\luameshval@mp@color","\luameshval@mp@colorPolygon")%
}%
\else % we are using MP
\mplibcolor{\luameshmpcolor}{\luameshval@mp@color}%
%\buildMeshBW[tikz, bbox = show]{(0,0);(3.5,3);(7,0);(7.5,5);(1.61,3.14);(3,1);(6,1.5)}
-\buildMeshBW[mode=ext,bbox = show, color=red,colorBbox = blue]{mesh.txt}
+\buildMeshBW[mode=ext,bbox = show, color=red,colorBbox = blue,print=dotpoints]{mesh.txt}
\drawPointsMesh[mode=ext,bbox = show, color=red,print=points]{mesh.txt}
\buildMeshBW[tikz,print=points, meshpoint = I,
color=red]{(0,0);(3.5,3);(7,0);(7.5,5);(1.61,3.14);(3,1);(6,1.5)}
-\buildMeshBW[tikz,mode=ext, color=red]{mesh.txt}
+\buildMeshBW[tikz,mode=ext, color=red,print=dotpoints]{mesh.txt}
\drawPointsMesh[tikz,mode=ext,bbox = show,
color=red,print=points]{mesh.txt}
\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]{(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[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)}
+\meshPolygon[tikz,step=points,scale=3cm,print=points]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
+\meshPolygon[tikz,step=mesh,scale=3cm,print=dotpoints]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
\end{document}