+
+
+--------------------------------------------------
+-- 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