From 7bc85345ad42b4b24478accec113804862650422 Mon Sep 17 00:00:00 2001 From: "Maxime Chupin (escudo)" Date: Tue, 7 Feb 2017 23:33:43 +0100 Subject: [PATCH] =?utf8?q?S=C3=A9paration=20en=20trois=20fichiers=20lua,?= =?utf8?q?=20et=20fonction=20d'ajout=20de=20points=20d'une=20grille=20?= =?utf8?q?=C3=A0=20l'int=C3=A9rieur=20d'un=20polygone?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- doc/luamesh-doc.pdf | Bin 157293 -> 157293 bytes polygon-luamesh.lua => luamesh-polygon.lua | 1 - luamesh-tex.lua | 790 +++++++++++++++++++ luamesh.lua | 869 ++------------------- test/delaunay.pdf | Bin 86165 -> 86165 bytes test/luamesh-polygon.lua | 1 + test/luamesh-tex.lua | 1 + test/polygon-luamesh.lua | 1 - test/test.lua | 17 +- 9 files changed, 877 insertions(+), 803 deletions(-) rename polygon-luamesh.lua => luamesh-polygon.lua (99%) create mode 100644 luamesh-tex.lua create mode 120000 test/luamesh-polygon.lua create mode 120000 test/luamesh-tex.lua delete mode 120000 test/polygon-luamesh.lua diff --git a/doc/luamesh-doc.pdf b/doc/luamesh-doc.pdf index f0cb2d5d493bef3fe593ab9609763ed554a9e734..0a56ba03fc4f9eec5aee4946df746d07a703f312 100644 GIT binary patch delta 3949 zcmajVWmFS@qXqDd5(c8u>5xu=5u>G3I;ES@Jy2qVARSVpC*3U!K_#RHNFyLEFj_iA z-toM5&i|bMmv??&?z#6Kj1V1+5H;jc0>#q8>)8+orlTHqZKTU%`d9cxap@IcCV`YW z?{GMD@NnJ3lUfNHa<9Y{dm}xNl%}O~#!Q1JBlBJ@?$1?hkuo?`a=UkIMlKvWcyCd%hC?~n0A+5icJYu?!#0@iCUhD3wU`F@uf#2Orxw!M2>aS`K z7b0?ATxT;NWWe{gHyTsJw!Ofj6Pr}J1V{@gDloWVwv2VeYRo@<@~1{>a=BZm2ssyblUq4QAEY|JpNem& z%I)3g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nEu2|zCc|z^Au=+;Xyps0JaM_okS4tr@gGT-^lj|CcQ%{>K zN(i-#$`in+W|lLF%p?QUDh^9v^M}j@4|#(*XaJH2PJzHzml=U;ddjOg*v7s~$MM##zTsexKCrNqNCz-Cwn5-sl8+_S0p^LuV8CcX)3RVbNS}{z5kb%rX&yhQ zH>5^e8Mv}_qUo|6+MxY@H4M|bA0GDMNcr}9#wKaWIiw)_YsMdv4YEl__WbFvDl+~4 z{TD?oyMbTfudZeTlWr;`UbLsP#h7!PUf5TjEbX9=HfK^-0Q5o?7?V`%=z1YLhUwjs zlelAfzxs)~nV(FxE3r#nk3;f(HxX{3LZ z&?^DMc`!+X>Evf!Ku|}xHOwNa^e2p`9wBzI=*C;J%DpdtB3y<+IeCOT47_MD&UElI zNN$r~aZAu<%XXx&Gg6F>QPPrLRw3>*3sk7voP1bgGm~(I0Gz@U5QJ3{48bBQPHp$~ zb&3Fvx^gH+8WNh%sM+mYiww_81^@$Wzcah&&M$}&M(S8lCQb~bC%+i{-9FG4*|u|1 zYK9z(VW6gk48Pao@8Aj?~_+Vpc|qrm{DF> z;bDX+|^$R}d0-Y}^grP6sEQ`&XhL;^MWUQiVS8f45Cl~HF~WuG?}cAXoE13X)1 zSt570Qe7rPbm77iMt8emP2ZJww|>b@YL2`ipCZ!O)%4wy`M zMCh!~o+#dQ@;lhj`R56o@ICl$5q;1~CB7Nn`q8RtrRWBY4S|foqp$iKoY^n(zwq5| zvhpz*_^s#o2G0+lG#cqmz!$vFa&N%vvUEqJx@W6- xmax) then + xmax = listPoints[i].x + end + if (listPoints[i].y < ymin) then + ymin = listPoints[i].y + end + if (listPoints[i].y > ymax) then + ymax = listPoints[i].y + end + end + eps = math.max(math.abs(xmax-xmin),math.abs(ymax-ymin))*0.15 + xmin = xmin - eps + xmax = xmax + eps + ymin = ymin - eps + ymax = ymax + eps + return xmin, xmax, ymin, ymax +end + function removeBoundingBox(triangulation,lgth) -- build the four bounding box edge point1 = lgth+1 @@ -84,7 +115,7 @@ function removeBoundingBox(triangulation,lgth) point3 = lgth+3 point4 = lgth+4 -- for all triangle - newTriangulation = {} + local newTriangulation = {} for i=1,#triangulation do boolE1 = pointInTriangle(point1,triangulation[i]) boolE2 = pointInTriangle(point2,triangulation[i]) @@ -99,7 +130,7 @@ end function buildBadTriangles(point, triangulation) - badTriangles = {} + local badTriangles = {} for j=1,#triangulation do -- for all triangles A = listPoints[triangulation[j][1]] B = listPoints[triangulation[j][2]] @@ -115,7 +146,7 @@ end -- construction of the cavity composed by the bad triangles around the point to add function buildCavity(badTriangles, triangulation) - polygon = {} + local polygon = {} for j=1,#badTriangles do -- for all bad triangles ind = badTriangles[j] for k=1,3 do -- for all edges @@ -211,7 +242,7 @@ end -- compute the list of the circumcircle of a triangulation function listCircumCenter(listPoints,triangulation) - list = {} + local list = {} for j=1,#triangulation do A = listPoints[triangulation[j][1]] B = listPoints[triangulation[j][2]] @@ -271,8 +302,8 @@ end -- build the edges of the Voronoi diagram with a given triangulation function buildVoronoi(listPoints, triangulation) - listCircumCircle = listCircumCenter(listPoints, triangulation) - listVoronoi = {} + local listCircumCircle = listCircumCenter(listPoints, triangulation) + local listVoronoi = {} for i=1,#listCircumCircle do listN = findNeighbour(triangulation[i],i,triangulation) for j=1,#listN do @@ -290,7 +321,7 @@ end function buildList(chaine, mode) -- if mode = int : the list is given in the chaine string (x1,y1);(x2,y2);...;(xn,yn) -- if mode = ext : the list is given in a file line by line with space separation - listPoints = {} + local listPoints = {} if mode == "int" then local points = string.explode(chaine, ";") local lgth=#points @@ -314,417 +345,49 @@ function buildList(chaine, mode) end --- -function rectangleList(a,b,nbrA,nbrB) - stepA = a/nbrA - stepB = b/nbrB - listPoints = {} - k=1 - for i=1,(nbrA+1) do - for j=1,(nbrB+1) do - listPoints[k] = {x = (i-1)*stepA, y=(j-1)*stepB} - k=k+1 - end - end - return listPoints -end - - --- trace Voronoi with MP -function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri,styleD,styleV) - if(styleD == "dashed") then - sDelaunay = "dashed evenly" - else - sDelaunay = "" - end - if(styleV == "dashed") then - sVoronoi = "dashed evenly" - else - sVoronoi = "" - end - 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 "..sDelaunay.." withcolor \\luameshmpcolorBbox;" - else - output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." 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 "..sVoronoi.." 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 +-- function to build a gridpoints from the bounding box +-- with a prescribed +function buildGrid(listPoints,h) + -- listPoints : list of the points of the polygon, ordered + -- h : parameter for the grid + xmin, xmax, ymin, ymax = BoundingBox(listPoints) - return output + local grid = rectangleList(xmin,xmax,ymin,ymax,h) + return grid end - --- trace Voronoi with TikZ -function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi,styleD,styleV) - if(styleD == "dashed") then - sDelaunay = ",dashed" - else - sDelaunay = "" - end - if(styleV == "dashed") then - sVoronoi = ",dashed" - else - sVoronoi = "" - end - 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..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" - else - output = output .. "\\draw[color="..color..sDelaunay.."] (".. 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..sVoronoi.."] (".. 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,styleD,styleV) - listPoints = buildList(chaine, mode) - triangulation = BowyerWatson(listPoints,bbox) - 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) -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) - 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 - - --- 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) - output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV) - 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,styleD,styleV) - triangulation = BowyerWatson(listPoints,bbox) - 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 - - - --- trace a triangulation with TikZ -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]] - 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 - 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 -end - - --- trace a triangulation with MP -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 .. ")*u;" - end - 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 - 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 +-- function to build the list of points in the rectangle +function rectangleList(xmin,xmax,ymin,ymax,h) + nbrX = math.floor(math.abs(xmax-xmin)/h) + nbrY = math.floor(math.abs(ymax-ymin)/h) + local listPoints = {} + k=1 + for i=1,(nbrX+1) do + for j=1,(nbrY+1) do + listPoints[k] = {x = xmin+(i-1)*h, y=ymin+(j-1)*h} + k=k+1 end end - return 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) -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) + return listPoints 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 .. ")*u;" - 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 - else - 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;" - else - output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;" - end - end - end - return output -end - --- 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 - 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 +-- function to add points from a grid to the interior of a polygon +function addGridPoints(polygon, grid) + local listPoints = polygon + k = #polygon + for i=1, #grid do + --print(grid[i].x,grid[i].y) + --print(isInside(polygon,grid[i])) + if(isInside(polygon,grid[i])) then + k=k+1 + listPoints[k] = grid[i] end end - return output -end - --- print points to mesh -function printPointsMP(chaine,mode,points,bbox,scale) - listPoints = buildList(chaine, mode) - if(bbox == "bbox" ) then - listPoints = buildBoundingBox(listPoints) - end - output = tracePointsMP(listPoints,points) - output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" - tex.sprint(output) -end - - --- print points to mesh -function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale) - listPoints = buildList(chaine, mode) - if(bbox == "bbox" ) then - listPoints = buildBoundingBox(listPoints) - end - output = tracePointsMP(listPoints,points) - 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 - - --- print points to mesh -function printPointsTikZinc(chaine,beginning, ending, 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 .."]" ..beginning.. output..ending .."\\end{tikzpicture}" - tex.sprint(output) + return listPoints end --- buildMesh -function buildRect(largeur,a,b,nbrA, nbrB) - listPoints = rectangleList(a,b,nbrA,nbrB) - triangulation = BowyerWatson(listPoints,"none") - traceTikZ(listPoints, triangulation,largeur,"none") -end - local function shallowCopy(original) local copy = {} for key, value in pairs(original) do @@ -768,271 +431,6 @@ function cleanPoly(polygon) return polyNew end --- -function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox) - output = "" - -- build the triangulation - 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]] - 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 - PointI = listPoints[triangulation[badTriangles[i]][1]] - PointJ = listPoints[triangulation[badTriangles[i]][2]] - PointK = listPoints[triangulation[badTriangles[i]][3]] - output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" - end - -- draw the circoncircle - for i=1,#badTriangles do - PointI = listPoints[triangulation[badTriangles[i]][1]] - PointJ = listPoints[triangulation[badTriangles[i]][2]] - PointK = listPoints[triangulation[badTriangles[i]][3]] - center, radius = circoncircle(PointI, PointJ, PointK) - output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");" - end - -- mark the points - 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 - -- mark the point to add - output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};" - elseif(step == "cavity") then - polygon = buildCavity(badTriangles, triangulation) - polyNew = cleanPoly(polygon) - -- remove the bad triangles - for j=1,#badTriangles do - table.remove(triangulation,badTriangles[j]-(j-1)) - end - -- draw the triangles - 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 - -- fill and draw the cavity - path = "" - for i=1,#polyNew do - PointI = listPoints[polyNew[i]] - path = path .. "(".. PointI.x ..",".. PointI.y ..")--" - end - output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;" - -- mark the points of the mesh - 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 - -- mark the adding point - output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};" - elseif(step == "newT") then - polygon = buildCavity(badTriangles, triangulation) - polyNew = cleanPoly(polygon) - -- remove the bad triangles - for j=1,#badTriangles do - table.remove(triangulation,badTriangles[j]-(j-1)) - end - -- draw the triangle of the triangulation - 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 - -- fill and draw the cavity - path = "" - for i=1,#polyNew do - PointI = listPoints[polyNew[i]] - path = path .. "(".. PointI.x ..",".. PointI.y ..")--" - end - output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;" - -- draw the new triangles composed by the edges of the polygon and the added point - for i=1,#polygon do - output = output .. "\\draw[color=TeXCluaMeshNewTikZ, thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y ..");" - output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");" - 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 - 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$};" - end - return output -end - -function TeXaddOnePointMPBW(listPoints,P,step,bbox) - output = ""; - output = output .. "pair MeshPoints[];" - -- build the triangulation - triangulation = BowyerWatson(listPoints,bbox) - badTriangles = buildBadTriangles(P,triangulation) - for i=1,#listPoints do - output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;" - 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]] - 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 - -- draw and fill the bad triangle - for i=1,#badTriangles do - PointI = listPoints[triangulation[badTriangles[i]][1]] - PointJ = listPoints[triangulation[badTriangles[i]][2]] - PointK = listPoints[triangulation[badTriangles[i]][3]] - output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;" - output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;" - end - -- draw the circoncircle - for i=1,#badTriangles do - PointI = listPoints[triangulation[badTriangles[i]][1]] - PointJ = listPoints[triangulation[badTriangles[i]][2]] - PointK = listPoints[triangulation[badTriangles[i]][3]] - center, radius = circoncircle(PointI, PointJ, PointK) - output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;" - end - -- mark the points - 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 - -- mark the point to add - output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;" - elseif(step == "cavity") then - polygon = buildCavity(badTriangles, triangulation) - polyNew = cleanPoly(polygon) - -- remove the bad triangles - for j=1,#badTriangles do - table.remove(triangulation,badTriangles[j]-(j-1)) - end - -- draw the triangles - 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 - -- fill and draw the cavity - path = "" - for i=1,#polyNew do - PointI = listPoints[polyNew[i]] - path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--" - end - output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;" - output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;" - -- mark the points of the mesh - 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 - -- mark the adding point - output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;" - elseif(step == "newT") then - polygon = buildCavity(badTriangles, triangulation) - polyNew = cleanPoly(polygon) - -- remove the bad triangles - for j=1,#badTriangles do - table.remove(triangulation,badTriangles[j]-(j-1)) - end - -- draw the triangle of the triangulation - 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 - -- fill the cavity - path = "" - for i=1,#polyNew do - PointI = listPoints[polyNew[i]] - path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--" - end - output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;" - -- draw the new triangles composed by the edges of the polygon and the added point - for i=1,#polygon do - output = output .. "draw".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ")*u -- (" .. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y ..")*u withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;" - output = output .. "draw".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ")*u -- (" .. P.x .. "," .. P.y ..")*u withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;" - output = output .. "draw".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ")*u -- (" .. P.x .. "," .. P.y ..")*u withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;" - end - -- mark points - 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 - -- mark the added point - output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;" - end - return output -end -- build the list of points extern and stop at nbr @@ -1050,64 +448,6 @@ function buildListExt(chaine, stop) return point, listPoints end - -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,"%((.+),(.+)%)") - P = {x=Sx, y=Sy} - listPoints = buildList(chaine, mode) - else - -- point is a number - P, listPoints = buildListExt(chaine,tonumber(point)) - end - output = TeXaddOnePointMPBW(listPoints,P,step,bbox) - output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}" - tex.sprint(output) -end - -function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox) - 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 = TeXaddOnePointMPBW(listPoints,P,step,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 @@ -1171,74 +511,3 @@ function readGmsh(file) 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,styleD,styleV) - listPoints,triangulation = readGmsh(file) - 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) -end - - --- buildVoronoi with TikZ -function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV) - listPoints,triangulation = readGmsh(file) - 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 - - --- buildVoronoi with MP -function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV) - listPoints,triangulation = readGmsh(file) - 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) -end - - --- buildVoronoi with TikZ -function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV) - listPoints,triangulation = readGmsh(file) - 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 diff --git a/test/delaunay.pdf b/test/delaunay.pdf index 0a399f90670fcaa0390f159d5a52eda3472503b2..14a41b656a710b8f809b00d1eba57dc87dc5b4ed 100644 GIT binary patch delta 137 zcmbQbkag-p)`l&NN}k;221W+vM#e@!a=NZ3qd2m_c7IRC2dsgnW@e_AhR()@md?gT zPKK^7<|fWAjxNSd1{MY;X6BZ53N{3l#OnK`=B1ZpC>R+SDNJ6dtU7(EKjQ}gC%hvL delta 137 zcmbQbkag-p)`l&NN}k+ihK5F#Mg|5ZhQ`x%JsHK31-AQpGCp7pG