Voronoi en TikZ
authorMaxime Chupin (escudo) <chupin@fougeriens.org>
Tue, 29 Nov 2016 16:31:12 +0000 (17:31 +0100)
committerMaxime Chupin (escudo) <chupin@fougeriens.org>
Tue, 29 Nov 2016 16:31:12 +0000 (17:31 +0100)
luamesh.lua
luamesh.sty
test/delaunay.pdf
test/delaunay.tex

index 4d255a1..af3da31 100644 (file)
@@ -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)
index de6d9e7..7d13961 100644 (file)
   \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}%
index f208943..a20e09e 100644 (file)
Binary files a/test/delaunay.pdf and b/test/delaunay.pdf differ
index d79b5b7..242e08b 100644 (file)
@@ -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}

Licence Creative Commons Les fichiers de Syracuse sont mis à disposition (sauf mention contraire) selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.