X-Git-Url: https://melusine.eu.org/syracuse/G/git/?a=blobdiff_plain;f=luamesh-tex.lua;h=b035978b267f2b3ca13ddbc26e2ed8ce87fd2b1a;hb=8b4d19195c3a5346157172be57d3ac7c5b756220;hp=f3c06ab611621ed6d421a0e75b133d26c4002cd4;hpb=7bc85345ad42b4b24478accec113804862650422;p=delaunay.git diff --git a/luamesh-tex.lua b/luamesh-tex.lua index f3c06ab..b035978 100644 --- a/luamesh-tex.lua +++ b/luamesh-tex.lua @@ -140,9 +140,9 @@ end -- buildVoronoi with MP function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri,styleD,styleV) - listPoints = buildList(chaine, mode) - triangulation = BowyerWatson(listPoints,bbox) - listVoronoi = buildVoronoi(listPoints, triangulation) + local listPoints = buildList(chaine, mode) + local triangulation = BowyerWatson(listPoints,bbox) + local listVoronoi = buildVoronoi(listPoints, triangulation) output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV) output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" tex.sprint(output) @@ -151,9 +151,9 @@ end -- buildVoronoi with TikZ function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi,styleD,styleV) - listPoints = buildList(chaine, mode) - triangulation = BowyerWatson(listPoints,bbox) - listVoronoi = buildVoronoi(listPoints, triangulation) + local listPoints = buildList(chaine, mode) + local triangulation = BowyerWatson(listPoints,bbox) + local listVoronoi = buildVoronoi(listPoints, triangulation) output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV) output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output) end @@ -161,9 +161,9 @@ end -- buildVoronoi with MP function buildVoronoiMPBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,styleD,styleV) - listPoints = buildList(chaine, mode) - triangulation = BowyerWatson(listPoints,bbox) - listVoronoi = buildVoronoi(listPoints, triangulation) + local listPoints = buildList(chaine, mode) + local triangulation = BowyerWatson(listPoints,bbox) + local listVoronoi = buildVoronoi(listPoints, triangulation) output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV) output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" tex.sprint(output) @@ -172,9 +172,9 @@ end -- buildVoronoi with TikZ function buildVoronoiTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi) - listPoints = buildList(chaine, mode,styleD,styleV) - triangulation = BowyerWatson(listPoints,bbox) - listVoronoi = buildVoronoi(listPoints, triangulation) + local listPoints = buildList(chaine, mode,styleD,styleV) + local triangulation = BowyerWatson(listPoints,bbox) + local listVoronoi = buildVoronoi(listPoints, triangulation) output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV) output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}" tex.sprint(output) @@ -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 @@ -241,14 +252,25 @@ function traceMeshMP(listPoints, triangulation,points) end end end + if(points=="dotpoints") then + 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 + end return output end -- buildMesh with MP function buildMeshMPBW(chaine,mode,points,bbox,scale) - listPoints = buildList(chaine, mode) - triangulation = BowyerWatson(listPoints,bbox) + local listPoints = buildList(chaine, mode) + local triangulation = BowyerWatson(listPoints,bbox) output = traceMeshMP(listPoints, triangulation,points) output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" tex.sprint(output) @@ -256,8 +278,8 @@ end -- buildMesh with MP include code function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale) - listPoints = buildList(chaine, mode) - triangulation = BowyerWatson(listPoints,bbox) + local listPoints = buildList(chaine, mode) + local triangulation = BowyerWatson(listPoints,bbox) output = traceMeshMP(listPoints, triangulation,points) output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" tex.sprint(output) @@ -265,8 +287,8 @@ end -- buildMesh with TikZ function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox) - listPoints = buildList(chaine, mode) - triangulation = BowyerWatson(listPoints,bbox) + local listPoints = buildList(chaine, mode) + local 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) @@ -274,8 +296,8 @@ end -- buildMesh with TikZ function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox) - listPoints = buildList(chaine, mode) - triangulation = BowyerWatson(listPoints,bbox) + local listPoints = buildList(chaine, mode) + local 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) @@ -341,7 +363,7 @@ end -- print points to mesh function printPointsMP(chaine,mode,points,bbox,scale) - listPoints = buildList(chaine, mode) + local listPoints = buildList(chaine, mode) if(bbox == "bbox" ) then listPoints = buildBoundingBox(listPoints) end @@ -353,7 +375,7 @@ end -- print points to mesh function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale) - listPoints = buildList(chaine, mode) + local listPoints = buildList(chaine, mode) if(bbox == "bbox" ) then listPoints = buildBoundingBox(listPoints) end @@ -364,7 +386,7 @@ end -- print points to mesh function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox) - listPoints = buildList(chaine, mode) + local listPoints = buildList(chaine, mode) if(bbox == "bbox" ) then listPoints = buildBoundingBox(listPoints) end @@ -376,7 +398,7 @@ end -- print points to mesh function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox) - listPoints = buildList(chaine, mode) + local listPoints = buildList(chaine, mode) if(bbox == "bbox" ) then listPoints = buildBoundingBox(listPoints) end @@ -388,8 +410,8 @@ end -- buildMesh function buildRect(largeur,a,b,nbrA, nbrB) - listPoints = rectangleList(a,b,nbrA,nbrB) - triangulation = BowyerWatson(listPoints,"none") + local listPoints = rectangleList(a,b,nbrA,nbrB) + local triangulation = BowyerWatson(listPoints,"none") traceTikZ(listPoints, triangulation,largeur,"none") end @@ -398,8 +420,8 @@ end function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox) output = "" -- build the triangulation - triangulation = BowyerWatson(listPoints,bbox) - badTriangles = buildBadTriangles(P,triangulation) + local triangulation = BowyerWatson(listPoints,bbox) + local badTriangles = buildBadTriangles(P,triangulation,listPoints) for i=1,#listPoints do output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");" end @@ -530,8 +552,10 @@ function TeXaddOnePointMPBW(listPoints,P,step,bbox) output = ""; output = output .. "pair MeshPoints[];" -- build the triangulation + local triangulation = {} + local badTriangles = {} triangulation = BowyerWatson(listPoints,bbox) - badTriangles = buildBadTriangles(P,triangulation) + badTriangles = buildBadTriangles(P,triangulation,listPoints) for i=1,#listPoints do output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;" end @@ -662,6 +686,7 @@ end function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox) + local listPoints = {} if(mode=="int") then Sx,Sy=string.match(point,"%((.+),(.+)%)") P = {x=Sx, y=Sy} @@ -676,6 +701,7 @@ function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,col end function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox) + local listPoints = {} if(mode=="int") then Sx,Sy=string.match(point,"%((.+),(.+)%)") P = {x=Sx, y=Sy} @@ -690,6 +716,7 @@ function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbo end function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox) + local listPoints = {} if(mode=="int") then Sx,Sy=string.match(point,"%((.+),(.+)%)") P = {x=Sx, y=Sy} @@ -704,6 +731,7 @@ function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox) end function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox) + local listPoints = {} if(mode=="int") then Sx,Sy=string.match(point,"%((.+),(.+)%)") P = {x=Sx, y=Sy} @@ -719,14 +747,14 @@ end function drawGmshMP(file,points,scale) - listPoints,triangulation = readGmsh(file) + local 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) + local listPoints,triangulation = readGmsh(file) output = traceMeshMP(listPoints,triangulation,points) output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" tex.sprint(output) @@ -736,7 +764,7 @@ end -- function drawGmshTikZ(file,points,scale,color) - listPoints,triangulation = readGmsh(file) + local 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) @@ -744,7 +772,7 @@ end -- function drawGmshTikZinc(file,beginning, ending,points,scale,color) - listPoints,triangulation = readGmsh(file) + local 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) @@ -753,8 +781,8 @@ end -- buildVoronoi with MP function gmshVoronoiMP(file,points,scale,tri,styleD,styleV) - listPoints,triangulation = readGmsh(file) - listVoronoi = buildVoronoi(listPoints, triangulation) + local listPoints,triangulation = readGmsh(file) + local listVoronoi = buildVoronoi(listPoints, triangulation) output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV) output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" tex.sprint(output) @@ -763,8 +791,8 @@ end -- buildVoronoi with TikZ function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV) - listPoints,triangulation = readGmsh(file) - listVoronoi = buildVoronoi(listPoints, triangulation) + local listPoints,triangulation = readGmsh(file) + local listVoronoi = buildVoronoi(listPoints, triangulation) output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV) output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output) end @@ -772,8 +800,8 @@ end -- buildVoronoi with MP function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV) - listPoints,triangulation = readGmsh(file) - listVoronoi = buildVoronoi(listPoints, triangulation) + local listPoints,triangulation = readGmsh(file) + local listVoronoi = buildVoronoi(listPoints, triangulation) output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV) output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" tex.sprint(output) @@ -782,9 +810,189 @@ end -- buildVoronoi with TikZ function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV) - listPoints,triangulation = readGmsh(file) - listVoronoi = buildVoronoi(listPoints, triangulation) + local listPoints,triangulation = readGmsh(file) + local listVoronoi = buildVoronoi(listPoints, triangulation) output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV) output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}" tex.sprint(output) end + + +-------------------------------------------------- +-- Meshing of a polygon -- +-------------------------------------------------- + +function tracePolygonMP(polygon,points) + output = ""; + output = output .. "pair polygon[];" + for i=1,#polygon do + output = output .. "polygon[".. i .. "] = (" .. polygon[i].x .. "," .. polygon[i].y .. ")*u;" + end + output = output .. "draw " + for i=1,#polygon do + output = output .. "(" .. polygon[i].x .. "," .. polygon[i].y .. ")*u -- " + end + output = output .. "cycle withcolor \\luameshmpcolorPoly withpen pencircle scaled 1pt;" + if(points=="points") then + for i=1,#polygon do + output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. polygon[i].x ..",".. polygon[i].y .. ")*u ) withcolor \\luameshmpcolorPoly ;" + end + end + if(points=="dotpoints") then + for i=1,#polygon do + output = output .. "drawdot (" .. polygon[i].x ..",".. polygon[i].y .. ")*u withcolor \\luameshmpcolorPoly withpen pencircle scaled 3;" + end + end + return output +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) + 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 = tracePolygonMP(polygon,points) + end + if(step=="grid") then + -- polygon + grid + output = tracePointsMP(grid,points) + output = output .. tracePolygonMP(polygon,points) + end + if(step=="points") then + -- polygon + only grid points inside the polygon + output = tracePointsMP(listPoints,points) + output = output .. tracePolygonMP(polygon,points) + end + if(step=="mesh") then + -- polygon + mesh + triangulation = BowyerWatson(listPoints,"none") -- no bbox + output = traceMeshMP(listPoints,triangulation,points) + output = output .. tracePolygonMP(polygon,points) + end + + 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 + +function drawMeshPolygonMPinc(chaine,beginning,ending,mode,h,step, + points,scale) + 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 = tracePolygonMP(polygon,points) + end + if(step=="grid") then + -- polygon + grid + output = tracePointsMP(grid,points) + output = output .. tracePolygonMP(polygon,points) + end + if(step=="points") then + -- polygon + only grid points inside the polygon + output = tracePointsMP(listPoints,points) + output = output .. tracePolygonMP(polygon,points) + end + if(step=="mesh") then + -- polygon + mesh + triangulation = BowyerWatson(listPoints,"none") -- no bbox + output = traceMeshMP(listPoints,triangulation,points) + output = output .. tracePolygonMP(polygon,points) + end + output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" + tex.sprint(output) +end + + + +function drawMeshPolygonTikZinc(chaine,beginning,ending,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.."]".. beginning..output ..ending.. "\\end{tikzpicture}" + tex.sprint(output) +end