Mise à jour archive v0.2 et liens index.md
[delaunay.git] / luamesh.lua
index ad6ec6f..bc961b7 100644 (file)
@@ -207,6 +207,81 @@ function circoncircle(M, N, P)
    return Out, rad  -- (center [Point], R [float])
 end
 
+-- compute the list of the circumcircle of a triangulation
+function listCircumCenter(listPoints,triangulation)
+   list = {}
+   for j=1,#triangulation do
+      A = listPoints[triangulation[j][1]]
+      B = listPoints[triangulation[j][2]]
+      C = listPoints[triangulation[j][3]]
+      center, radius = circoncircle(A,B,C)
+      table.insert(list,{x=center.x,y=center.y,r=radius})
+   end
+   return list
+end
+
+-- find the three neighbour triangles of T
+function findNeighbour(T,i,triangulation)
+   -- T : triangle
+   -- i : index of T in triangualation
+   -- triangulation
+
+   list = {}
+   -- define the three edge
+   e1 = {T[1],T[2]}
+   e2 = {T[2],T[3]}
+   e3 = {T[3],T[1]}
+   for j=1,#triangulation do
+      if j~= i then
+         if(edgeInTriangle(e1,triangulation[j])) then
+            table.insert(list,j)
+         end
+         if(edgeInTriangle(e2,triangulation[j])) then
+            table.insert(list,j)
+         end
+         if(edgeInTriangle(e3,triangulation[j])) then
+            table.insert(list,j)
+         end
+      end
+   end
+   return list
+end
+
+-- test if edge are the same (reverse)
+function equalEdge(e1,e2)
+   if(((e1[1] == e2[1]) and (e1[2] == e2[2])) or ((e1[1] == e2[2]) and (e1[2] == e2[1]))) then
+      return true
+   else
+      return false
+   end
+end
+
+-- test if the edge belongs to the list
+function edgeInList(e,listE)
+   output = false
+   for i=1,#listE do
+      if(equalEdge(e,listE[i])) then
+         output = true
+      end
+   end
+   return output
+end
+
+-- build the edges of the Voronoi diagram with a given triangulation
+function buildVoronoi(listPoints, triangulation)
+   listCircumCircle = listCircumCenter(listPoints, triangulation)
+   listVoronoi = {}
+   for i=1,#listCircumCircle do
+      listN = findNeighbour(triangulation[i],i,triangulation)
+      for j=1,#listN do
+         edge = {i,listN[j]}
+         if( not edgeInList(edge, listVoronoi)) then
+            table.insert(listVoronoi, edge)
+         end
+      end
+   end
+   return listVoronoi
+end
 
 -------------------------- TeX
 -- build the list of points
@@ -252,18 +327,196 @@ function rectangleList(a,b,nbrA,nbrB)
    return listPoints
 end
 
+
+-- trace Voronoi with MP
+function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri)
+   listCircumC = listCircumCenter(listPoints,triangulation)
+   output = "";
+   output = output .. " pair MeshPoints[];"
+   for i=1,#listPoints do
+      output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
+   end
+   output = output .. " pair CircumCenters[];"
+   for i=1,#listCircumC do
+      output = output .. "CircumCenters[".. i .. "] = (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ")*u;"
+   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 (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
+         else
+            output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
+         end
+      end
+   end
+   for i=1,#listVoronoi do
+      PointI = listCircumC[listVoronoi[i][1]]
+      PointJ = listCircumC[listVoronoi[i][2]]
+      output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u withcolor \\luameshmpcolorVoronoi;"
+   end
+   if(points=="points") then
+      j=1
+      for i=1,#listPoints do
+         if(listPoints[i].type == "bbox") then
+            output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+            j=j+1
+         else
+            output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
+         end
+      end
+      for i=1,#listCircumC do
+         output = output .. "dotlabel.llft (btex $\\CircumPoint_{" .. i .. "}$ etex, (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u ) withcolor \\luameshmpcolorVoronoi ;"
+      end
+   else
+      j=1
+      for i=1,#listPoints do
+         if(listPoints[i].type == "bbox") then
+            output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
+            j=j+1
+         else
+            output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolor withpen pencircle scaled 3;"
+         end
+      end
+      for i=1,#listCircumC do
+         output = output .. "drawdot  (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u  withcolor \\luameshmpcolorVoronoi withpen pencircle scaled 3;"
+      end
+   end
+
+   return output
+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
+            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
+      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)
+   listPoints = buildList(chaine, mode)
+   triangulation = BowyerWatson(listPoints,bbox)
+   listVoronoi = buildVoronoi(listPoints, triangulation)
+   output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
+   output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
+   tex.sprint(output)
+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
+
+
+-- buildVoronoi with MP
+function buildVoronoiMPBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri)
+   listPoints = buildList(chaine, mode)
+   triangulation = BowyerWatson(listPoints,bbox)
+   listVoronoi = buildVoronoi(listPoints, triangulation)
+   output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
+   output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
+   tex.sprint(output)
+end
+
+
+-- buildVoronoi with TikZ
+function buildVoronoiTikZBWinc(chaine,beginning, ending,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 .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
+   tex.sprint(output)
+end
+
+
+
 -- trace a triangulation with TikZ
-function traceMeshTikZ(listPoints, triangulation,points,color)
+function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
    output = ""
+   for i=1,#listPoints do
+      output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
+   end
    for i=1,#triangulation do
       PointI = listPoints[triangulation[i][1]]
       PointJ = listPoints[triangulation[i][2]]
       PointK = listPoints[triangulation[i][3]]
-      output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
+      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
    if(points=="points") then
+      j=1
       for i=1,#listPoints do
-         output = output .. "\\draw[color=".."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
+         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
    return output
@@ -275,9 +528,8 @@ function traceMeshMP(listPoints, triangulation,points)
    output = "";
    output = output .. " pair MeshPoints[];"
    for i=1,#listPoints do
-      output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
+      output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
    end
-
    for i=1,#triangulation do
       PointI = listPoints[triangulation[i][1]]
       PointJ = listPoints[triangulation[i][2]]
@@ -303,12 +555,49 @@ function traceMeshMP(listPoints, triangulation,points)
 end
 
 
+-- buildMesh with MP
+function buildMeshMPBW(chaine,mode,points,bbox,scale)
+   listPoints = buildList(chaine, mode)
+   triangulation = BowyerWatson(listPoints,bbox)
+   output = traceMeshMP(listPoints, triangulation,points)
+   output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
+   tex.sprint(output)
+end
+
+-- buildMesh with MP include code
+function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
+   listPoints = buildList(chaine, mode)
+   triangulation = BowyerWatson(listPoints,bbox)
+   output = traceMeshMP(listPoints, triangulation,points)
+   output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
+   tex.sprint(output)
+end
+
+-- buildMesh with TikZ
+function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
+   listPoints = buildList(chaine, mode)
+   triangulation = BowyerWatson(listPoints,bbox)
+   output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
+   output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
+   tex.sprint(output)
+end
+
+-- buildMesh with TikZ
+function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
+   listPoints = buildList(chaine, mode)
+   triangulation = BowyerWatson(listPoints,bbox)
+   output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
+   output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
+   tex.sprint(output)
+end
+
+
 -- print points of the mesh
 function tracePointsMP(listPoints,points)
    output = "";
    output = output .. " pair MeshPoints[];"
    for i=1,#listPoints do
-      output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
+      output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
    end
    if(points=="points") then
       j=1
@@ -323,36 +612,41 @@ function tracePointsMP(listPoints,points)
    else
       for i=1,#listPoints do
          if(listPoints[i].type == "bbox") then
-            output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+            output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
          else
-            output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
+            output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolor withpen pencircle scaled 3;"
          end
       end
    end
    return output
 end
 
-
-
--- buildMesh with TikZ
-function buildMeshTikZ(chaine,mode,points,bbox,full,scale,color)
-   listPoints = buildList(chaine, mode)
-   triangulation = BowyerWatson(listPoints,bbox)
-   output = traceMeshTikZ(listPoints, triangulation,points,color)
-   if(full=="full") then
-      output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
+-- print points of the mesh
+function tracePointsTikZ(listPoints,points,color,colorBbox)
+   output = "";
+   for i=1,#listPoints do
+      output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
    end
-   tex.sprint(output)
-end
-
-
--- buildMesh with MP
-function buildMeshMPBW(chaine,mode,points,bbox,scale)
-   listPoints = buildList(chaine, mode)
-   triangulation = BowyerWatson(listPoints,bbox)
-   output = traceMeshMP(listPoints, triangulation,points)
-   output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
-   tex.sprint(output)
+   if(points=="points") 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$} 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
+   else
+      for i=1,#listPoints do
+         if(listPoints[i].type == "bbox") then
+            output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
+         else
+            output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
+         end
+      end
+   end
+   return output
 end
 
 -- print points to mesh
@@ -374,20 +668,34 @@ function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
       listPoints = buildBoundingBox(listPoints)
    end
    output = tracePointsMP(listPoints,points)
-   output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
+   output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
    tex.sprint(output)
 end
 
+-- print points to mesh
+function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
+   listPoints = buildList(chaine, mode)
+   if(bbox == "bbox" ) then
+      listPoints = buildBoundingBox(listPoints)
+   end
+   output = tracePointsTikZ(listPoints,points,color,colorBbox)
+   output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
+   tex.sprint(output)
+end
 
--- buildMesh with MP include code
-function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
+
+-- print points to mesh
+function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
    listPoints = buildList(chaine, mode)
-   triangulation = BowyerWatson(listPoints,bbox)
-   output = traceMeshMP(listPoints, triangulation,points)
-   output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
+   if(bbox == "bbox" ) then
+      listPoints = buildBoundingBox(listPoints)
+   end
+   output = tracePointsTikZ(listPoints,points,color,colorBbox)
+   output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
    tex.sprint(output)
 end
 
+
 -- buildMesh
 function buildRect(largeur,a,b,nbrA, nbrB)
    listPoints = rectangleList(a,b,nbrA,nbrB)
@@ -417,7 +725,6 @@ function cleanPoly(polygon)
       i=1
       find = false
       while (i<=#polyCopy and find==false) do
-         i = i+1
          bool1 = (polyCopy[i][1] == polyNew[j])
          bool2 = (polyCopy[i][2] == polyNew[j])
          if(bool1 or bool2) then -- the edge has a common point with polyNew[j]
@@ -433,27 +740,32 @@ function cleanPoly(polygon)
                j = j+1
             end
          end
+         i=i+1
       end
    end
    return polyNew
 end
 
 --
-function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCircle)
-   Sx,Sy=string.match(point,"%((.+),(.+)%)")
-   P = {x=Sx, y=Sy}
+function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
    output = ""
-   listPoints = buildList(chaine, "int")
    -- build the triangulation
-   triangulation = BowyerWatson(listPoints,"none")
+   triangulation = BowyerWatson(listPoints,bbox)
    badTriangles = buildBadTriangles(P,triangulation)
+   for i=1,#listPoints do
+      output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
+   end
    if(step == "badT") then
       -- draw all triangle
       for i=1,#triangulation do
          PointI = listPoints[triangulation[i][1]]
          PointJ = listPoints[triangulation[i][2]]
          PointK = listPoints[triangulation[i][3]]
-         output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
+         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
       -- draw and fill the bad triangle
       for i=1,#badTriangles do
@@ -471,8 +783,14 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi
          output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
       end
       -- mark the points
+      j=1
       for i=1,#listPoints do
-         output = output .. "\\draw[color ="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
+         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
       -- mark the point to add
       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
@@ -488,7 +806,11 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi
          PointI = listPoints[triangulation[i][1]]
          PointJ = listPoints[triangulation[i][2]]
          PointK = listPoints[triangulation[i][3]]
-         output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
+         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
       -- fill and draw the cavity
       path = ""
@@ -498,8 +820,14 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi
       end
       output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
       -- mark the points of the mesh
+      j=1
       for i=1,#listPoints do
-         output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
+         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
       -- mark the adding point
       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
@@ -515,7 +843,11 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi
          PointI = listPoints[triangulation[i][1]]
          PointJ = listPoints[triangulation[i][2]]
          PointK = listPoints[triangulation[i][3]]
-         output = output .. "\\draw[color ="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
+         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
       -- fill and draw the cavity
       path = ""
@@ -531,8 +863,14 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi
          output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
       end
       -- mark points
+      j=1
       for i=1,#listPoints do
-         output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
+         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
       -- mark the added point
       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
@@ -547,7 +885,7 @@ function TeXaddOnePointMPBW(listPoints,P,step,bbox)
    triangulation = BowyerWatson(listPoints,bbox)
    badTriangles = buildBadTriangles(P,triangulation)
    for i=1,#listPoints do
-      output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
+      output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
    end
    if(step == "badT") then
       -- draw all triangle
@@ -691,12 +1029,34 @@ function buildListExt(chaine, stop)
 end
 
 
-function TeXOnePointTikZ(chaine,point,step,color,colorBack,colorNew,colorCircle,scale)
-   output = TeXaddOnePointTikZ(chaine,point,step,color,colorBack,colorNew,colorCircle)
+function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
+   if(mode=="int") then
+      Sx,Sy=string.match(point,"%((.+),(.+)%)")
+      P = {x=Sx, y=Sy}
+      listPoints = buildList(chaine, mode)
+   else
+      -- point is a number
+      P, listPoints = buildListExt(chaine,tonumber(point))
+   end
+   output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
    output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
    tex.sprint(output)
 end
 
+function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
+   if(mode=="int") then
+      Sx,Sy=string.match(point,"%((.+),(.+)%)")
+      P = {x=Sx, y=Sy}
+      listPoints = buildList(chaine, mode)
+   else
+      -- point is a number
+      P, listPoints = buildListExt(chaine,tonumber(point))
+   end
+   output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
+   output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
+   tex.sprint(output)
+end
+
 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
    if(mode=="int") then
       Sx,Sy=string.match(point,"%((.+),(.+)%)")
@@ -724,3 +1084,139 @@ function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
    output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
    tex.sprint(output)
 end
+
+
+function split(pString, pPattern)
+   local Table = {}  -- NOTE: use {n = 0} in Lua-5.0
+   local fpat = "(.-)" .. pPattern
+   local last_end = 1
+   local s, e, cap = pString:find(fpat, 1)
+   while s do
+      if s ~= 1 or cap ~= "" then
+         table.insert(Table,cap)
+      end
+      last_end = e+1
+      s, e, cap = pString:find(fpat, last_end)
+   end
+   if last_end <= #pString then
+      cap = pString:sub(last_end)
+      table.insert(Table, cap)
+   end
+   return Table
+end
+
+function readGmsh(file)
+   io.input(file) -- open the file
+   text=io.read("*all")
+   local lines = split(text,"\n+") -- all the lines
+   listPoints={}
+   triangulation ={}
+   boolNodes = false
+   Jnodes = 0
+   boolElements = false
+   Jelements = 0
+   J=0
+   for i=1,#lines-J do
+      if(lines[i+J] == "$EndNodes") then
+         boolNodes = false
+         -- go to the next line
+      end
+      if(boolNodes) then -- we are in the Nodes environment
+         xy=split(lines[i+J]," +")
+         table.insert(listPoints,{x=tonumber(xy[2]),y=tonumber(xy[3])})
+      end
+      if(lines[i+J] == "$Nodes") then
+         boolNodes = true
+         -- go to the next line
+         J=J+1
+      end
+      if(lines[i+J] == "$EndElements") then
+         boolElements = false
+         -- go to the next line
+      end
+      if(boolElements) then -- we are in the Nodes environment
+         xy=split(lines[i+J]," +")
+         if(tonumber(xy[2]) == 2) then -- if the element is a triangle
+            nbrTags = xy[3]+1
+            table.insert(triangulation,{tonumber(xy[2+nbrTags+1]),tonumber(xy[2+nbrTags+2]),tonumber(xy[2+nbrTags+3])})
+         end
+      end
+      if(lines[i+J] == "$Elements") then
+         boolElements = true
+         -- go to the next line
+         J=J+1
+      end
+   end
+   return listPoints, triangulation
+end
+
+function drawGmshMP(file,points,scale)
+   listPoints,triangulation = readGmsh(file)
+   output = traceMeshMP(listPoints,triangulation,points)
+   output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
+   tex.sprint(output)
+end
+
+function drawGmshMPinc(file,beginning,ending,points,scale)
+   listPoints,triangulation = readGmsh(file)
+   output = traceMeshMP(listPoints,triangulation,points)
+   output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
+   tex.sprint(output)
+end
+
+
+
+--
+function drawGmshTikZ(file,points,scale,color)
+   listPoints,triangulation = readGmsh(file)
+   output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
+   output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
+   tex.sprint(output)
+end
+
+--
+function drawGmshTikZinc(file,beginning, ending,points,scale,color)
+   listPoints,triangulation = readGmsh(file)
+   output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
+   output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
+   tex.sprint(output)
+end
+
+
+-- buildVoronoi with MP
+function gmshVoronoiMP(file,points,scale,tri)
+   listPoints,triangulation = readGmsh(file)
+   listVoronoi = buildVoronoi(listPoints, triangulation)
+   output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
+   output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
+   tex.sprint(output)
+end
+
+
+-- buildVoronoi with TikZ
+function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi)
+   listPoints,triangulation = readGmsh(file)
+   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
+
+
+-- buildVoronoi with MP
+function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri)
+   listPoints,triangulation = readGmsh(file)
+   listVoronoi = buildVoronoi(listPoints, triangulation)
+   output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
+   output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
+   tex.sprint(output)
+end
+
+
+-- buildVoronoi with TikZ
+function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi)
+   listPoints,triangulation = readGmsh(file)
+   listVoronoi = buildVoronoi(listPoints, triangulation)
+   output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi)
+   output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
+   tex.sprint(output)
+end

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.