From: Maxime Chupin (Ceremade) Date: Thu, 9 Feb 2017 17:07:39 +0000 (+0100) Subject: meshPolygon avec TikZ et ajout dotpoints comme option à tracePoints(TikZ et MP) X-Git-Url: https://melusine.eu.org/syracuse/G/git/?a=commitdiff_plain;h=69d738f58952eaf2e69da5817f9c7ab8c81a68c1;p=delaunay.git meshPolygon avec TikZ et ajout dotpoints comme option à tracePoints(TikZ et MP) --- diff --git a/luamesh-tex.lua b/luamesh-tex.lua index 56b635c..528b6a4 100644 --- a/luamesh-tex.lua +++ b/luamesh-tex.lua @@ -209,6 +209,17 @@ function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox) 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 @@ -811,11 +822,6 @@ end -- Meshing of a polygon -- -------------------------------------------------- - -function TeXMeshPolygonMP(polygon,listPoints, grid, step) - -end - function tracePolygonMP(polygon,points) output = ""; output = output .. "pair polygon[];" @@ -841,6 +847,30 @@ function tracePolygonMP(polygon,points) 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) @@ -872,3 +902,35 @@ function drawMeshPolygonMP(chaine,mode,h,step, 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 diff --git a/luamesh.sty b/luamesh.sty index 363d085..80c0c0f 100644 --- a/luamesh.sty +++ b/luamesh.sty @@ -875,7 +875,7 @@ \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 @@ -885,7 +885,7 @@ \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}% diff --git a/test/delaunay.pdf b/test/delaunay.pdf index c7e8051..2f1ba3e 100644 Binary files a/test/delaunay.pdf and b/test/delaunay.pdf differ diff --git a/test/delaunay.tex b/test/delaunay.tex index 1837942..44965e4 100644 --- a/test/delaunay.tex +++ b/test/delaunay.tex @@ -14,7 +14,7 @@ %\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} @@ -91,7 +91,7 @@ endfig; \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} @@ -175,6 +175,11 @@ colorBbox = black \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}