From: Maxime Chupin (escudo) Date: Tue, 29 Nov 2016 16:31:12 +0000 (+0100) Subject: Voronoi en TikZ X-Git-Url: https://melusine.eu.org/syracuse/G/git/?a=commitdiff_plain;h=81576bf772cf5a397a9a380eb6f30b97270710c5;p=delaunay.git Voronoi en TikZ --- diff --git a/luamesh.lua b/luamesh.lua index 4d255a1..af3da31 100644 --- a/luamesh.lua +++ b/luamesh.lua @@ -389,6 +389,66 @@ function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri) end +-- trace Voronoi with TikZ +function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi) + listCircumC = listCircumCenter(listPoints,triangulation) + output = "" + for i=1,#listPoints do + output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");" + end + for i=1,#listCircumC do + output = output .. "\\coordinate (CircumPoints".. i .. ") at (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ");" + end + if(tri=="show") then + for i=1,#triangulation do + PointI = listPoints[triangulation[i][1]] + PointJ = listPoints[triangulation[i][2]] + PointK = listPoints[triangulation[i][3]] + if(triangulation[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + else + output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + end + end + end + for i=1,#listVoronoi do + PointI = listCircumC[listVoronoi[i][1]] + PointJ = listCircumC[listVoronoi[i][2]] + output = output .. "\\draw[color="..colorVoronoi.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..");" + end + if(points=="points") then + j=1 + for i=1,#listPoints do + if(listPoints[i].type == "bbox") then + if(listPoints[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};" + j=j+1 + else + output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" + end + end + end + for i=1,#listCircumC do + output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\CircumPoint_{" .. i .. "}$};" + end + else + 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 + for i=1,#listCircumC do + output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$};" + end + end + return output +end + + -- buildVoronoi with MP function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri) @@ -401,6 +461,16 @@ function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri) end +-- buildVoronoi with TikZ +function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi) + listPoints = buildList(chaine, mode) + triangulation = BowyerWatson(listPoints,bbox) + listVoronoi = buildVoronoi(listPoints, triangulation) + output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi) + output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output) +end + + -- trace a triangulation with TikZ function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox) diff --git a/luamesh.sty b/luamesh.sty index de6d9e7..7d13961 100644 --- a/luamesh.sty +++ b/luamesh.sty @@ -273,7 +273,7 @@ \def\CircumPoint{\luameshval@bv@circumpoint}% \ifKV@buildVoronoi@tikz% if we are using tikz \directlua{% - buildVoronoiTikZBW("#2","\luameshval@bv@mode","\luameshval@bv@print","\luameshval@bv@bbox","\luameshval@bv@scale","\luameshval@bv@color","\luameshval@bv@colorbbox")% + buildVoronoiTikZBW("#2","\luameshval@bv@mode","\luameshval@bv@print","\luameshval@bv@bbox","\luameshval@bv@scale","\luameshval@bv@delaunay","\luameshval@bv@color","\luameshval@bv@colorbbox","\luameshval@bv@colorVoronoi")% }% \else % we are using MP \mplibcolor{\luameshmpcolor}{\luameshval@bv@color}% diff --git a/test/delaunay.pdf b/test/delaunay.pdf index f208943..a20e09e 100644 Binary files a/test/delaunay.pdf and b/test/delaunay.pdf differ diff --git a/test/delaunay.tex b/test/delaunay.tex index d79b5b7..242e08b 100644 --- a/test/delaunay.tex +++ b/test/delaunay.tex @@ -146,7 +146,12 @@ colorBbox = black % buildVoronoiMP("mesh.txt","ext","points","","1cm","show") % } \buildVoronoiBW[mode=ext]{mesh.txt} -\buildVoronoiBW[mode=ext,delaunay=show]{mesh.txt}\par -\buildVoronoiBW[mode=ext,print=points,delaunay=show,bbox=show]{mesh.txt} +\buildVoronoiBW[mode=ext,delaunay=show,colorVoronoi=green!60!blue]{mesh.txt}\par +\buildVoronoiBW[mode=ext,print=points,delaunay=show,bbox=show,meshpoint=x,circumpoint=y]{mesh.txt} + + +\buildVoronoiBW[tikz,mode=ext]{mesh.txt} +\buildVoronoiBW[tikz,mode=ext,delaunay=show,colorVoronoi=green!60!blue]{mesh.txt}\par +\buildVoronoiBW[tikz,mode=ext,print=points,delaunay=show,bbox=show,meshpoint=x,circumpoint=y]{mesh.txt} \end{document}