1 -- trace Voronoi with MP
2 function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri,styleD,styleV)
3 if(styleD == "dashed") then
4 sDelaunay = "dashed evenly"
8 if(styleV == "dashed") then
9 sVoronoi = "dashed evenly"
13 listCircumC = listCircumCenter(listPoints,triangulation)
15 output = output .. " pair MeshPoints[];"
16 for i=1,#listPoints do
17 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
19 output = output .. " pair CircumCenters[];"
20 for i=1,#listCircumC do
21 output = output .. "CircumCenters[".. i .. "] = (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ")*u;"
24 for i=1,#triangulation do
25 PointI = listPoints[triangulation[i][1]]
26 PointJ = listPoints[triangulation[i][2]]
27 PointK = listPoints[triangulation[i][3]]
28 if(triangulation[i].type == "bbox") then
29 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolorBbox;"
31 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolor;"
35 for i=1,#listVoronoi do
36 PointI = listCircumC[listVoronoi[i][1]]
37 PointJ = listCircumC[listVoronoi[i][2]]
38 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u "..sVoronoi.." withcolor \\luameshmpcolorVoronoi;"
40 if(points=="points") then
42 for i=1,#listPoints do
43 if(listPoints[i].type == "bbox") then
44 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
47 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
50 for i=1,#listCircumC do
51 output = output .. "dotlabel.llft (btex $\\CircumPoint_{" .. i .. "}$ etex, (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u ) withcolor \\luameshmpcolorVoronoi ;"
55 for i=1,#listPoints do
56 if(listPoints[i].type == "bbox") then
57 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
60 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
63 for i=1,#listCircumC do
64 output = output .. "drawdot (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u withcolor \\luameshmpcolorVoronoi withpen pencircle scaled 3;"
72 -- trace Voronoi with TikZ
73 function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi,styleD,styleV)
74 if(styleD == "dashed") then
79 if(styleV == "dashed") then
84 listCircumC = listCircumCenter(listPoints,triangulation)
86 for i=1,#listPoints do
87 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
89 for i=1,#listCircumC do
90 output = output .. "\\coordinate (CircumPoints".. i .. ") at (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ");"
93 for i=1,#triangulation do
94 PointI = listPoints[triangulation[i][1]]
95 PointJ = listPoints[triangulation[i][2]]
96 PointK = listPoints[triangulation[i][3]]
97 if(triangulation[i].type == "bbox") then
98 output = output .. "\\draw[color="..colorBbox..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
100 output = output .. "\\draw[color="..color..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
104 for i=1,#listVoronoi do
105 PointI = listCircumC[listVoronoi[i][1]]
106 PointJ = listCircumC[listVoronoi[i][2]]
107 output = output .. "\\draw[color="..colorVoronoi..sVoronoi.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..");"
109 if(points=="points") then
111 for i=1,#listPoints do
112 if(listPoints[i].type == "bbox") then
113 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
116 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
119 for i=1,#listCircumC do
120 output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\CircumPoint_{" .. i .. "}$};"
124 for i=1,#listPoints do
125 if(listPoints[i].type == "bbox") then
126 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
129 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
132 for i=1,#listCircumC do
133 output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$};"
141 -- buildVoronoi with MP
142 function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri,styleD,styleV)
143 listPoints = buildList(chaine, mode)
144 triangulation = BowyerWatson(listPoints,bbox)
145 listVoronoi = buildVoronoi(listPoints, triangulation)
146 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
147 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
152 -- buildVoronoi with TikZ
153 function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi,styleD,styleV)
154 listPoints = buildList(chaine, mode)
155 triangulation = BowyerWatson(listPoints,bbox)
156 listVoronoi = buildVoronoi(listPoints, triangulation)
157 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
158 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
162 -- buildVoronoi with MP
163 function buildVoronoiMPBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,styleD,styleV)
164 listPoints = buildList(chaine, mode)
165 triangulation = BowyerWatson(listPoints,bbox)
166 listVoronoi = buildVoronoi(listPoints, triangulation)
167 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
168 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
173 -- buildVoronoi with TikZ
174 function buildVoronoiTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi)
175 listPoints = buildList(chaine, mode,styleD,styleV)
176 triangulation = BowyerWatson(listPoints,bbox)
177 listVoronoi = buildVoronoi(listPoints, triangulation)
178 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
179 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
185 -- trace a triangulation with TikZ
186 function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
188 for i=1,#listPoints do
189 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
191 for i=1,#triangulation do
192 PointI = listPoints[triangulation[i][1]]
193 PointJ = listPoints[triangulation[i][2]]
194 PointK = listPoints[triangulation[i][3]]
195 if(triangulation[i].type == "bbox") then
196 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
198 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
201 if(points=="points") then
203 for i=1,#listPoints do
204 if(listPoints[i].type == "bbox") then
205 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
208 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
216 -- trace a triangulation with MP
217 function traceMeshMP(listPoints, triangulation,points)
219 output = output .. " pair MeshPoints[];"
220 for i=1,#listPoints do
221 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
223 for i=1,#triangulation do
224 PointI = listPoints[triangulation[i][1]]
225 PointJ = listPoints[triangulation[i][2]]
226 PointK = listPoints[triangulation[i][3]]
227 if(triangulation[i].type == "bbox") then
228 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
230 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
233 if(points=="points") then
235 for i=1,#listPoints do
236 if(listPoints[i].type == "bbox") then
237 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
240 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
244 if(points=="dotpoints") then
246 for i=1,#listPoints do
247 if(listPoints[i].type == "bbox") then
248 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
251 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
260 function buildMeshMPBW(chaine,mode,points,bbox,scale)
261 listPoints = buildList(chaine, mode)
262 triangulation = BowyerWatson(listPoints,bbox)
263 output = traceMeshMP(listPoints, triangulation,points)
264 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
268 -- buildMesh with MP include code
269 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
270 listPoints = buildList(chaine, mode)
271 triangulation = BowyerWatson(listPoints,bbox)
272 output = traceMeshMP(listPoints, triangulation,points)
273 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
277 -- buildMesh with TikZ
278 function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
279 listPoints = buildList(chaine, mode)
280 triangulation = BowyerWatson(listPoints,bbox)
281 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
282 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
286 -- buildMesh with TikZ
287 function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
288 listPoints = buildList(chaine, mode)
289 triangulation = BowyerWatson(listPoints,bbox)
290 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
291 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
296 -- print points of the mesh
297 function tracePointsMP(listPoints,points)
299 output = output .. " pair MeshPoints[];"
300 for i=1,#listPoints do
301 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
303 if(points=="points") then
305 for i=1,#listPoints do
306 if(listPoints[i].type == "bbox") then
307 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
310 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
314 for i=1,#listPoints do
315 if(listPoints[i].type == "bbox") then
316 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
318 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
325 -- print points of the mesh
326 function tracePointsTikZ(listPoints,points,color,colorBbox)
328 for i=1,#listPoints do
329 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
331 if(points=="points") then
333 for i=1,#listPoints do
334 if(listPoints[i].type == "bbox") then
335 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
338 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
342 for i=1,#listPoints do
343 if(listPoints[i].type == "bbox") then
344 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
346 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
353 -- print points to mesh
354 function printPointsMP(chaine,mode,points,bbox,scale)
355 listPoints = buildList(chaine, mode)
356 if(bbox == "bbox" ) then
357 listPoints = buildBoundingBox(listPoints)
359 output = tracePointsMP(listPoints,points)
360 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
365 -- print points to mesh
366 function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
367 listPoints = buildList(chaine, mode)
368 if(bbox == "bbox" ) then
369 listPoints = buildBoundingBox(listPoints)
371 output = tracePointsMP(listPoints,points)
372 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
376 -- print points to mesh
377 function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
378 listPoints = buildList(chaine, mode)
379 if(bbox == "bbox" ) then
380 listPoints = buildBoundingBox(listPoints)
382 output = tracePointsTikZ(listPoints,points,color,colorBbox)
383 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
388 -- print points to mesh
389 function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
390 listPoints = buildList(chaine, mode)
391 if(bbox == "bbox" ) then
392 listPoints = buildBoundingBox(listPoints)
394 output = tracePointsTikZ(listPoints,points,color,colorBbox)
395 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
401 function buildRect(largeur,a,b,nbrA, nbrB)
402 listPoints = rectangleList(a,b,nbrA,nbrB)
403 triangulation = BowyerWatson(listPoints,"none")
404 traceTikZ(listPoints, triangulation,largeur,"none")
409 function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
411 -- build the triangulation
412 triangulation = BowyerWatson(listPoints,bbox)
413 badTriangles = buildBadTriangles(P,triangulation)
414 for i=1,#listPoints do
415 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
417 if(step == "badT") then
419 for i=1,#triangulation do
420 PointI = listPoints[triangulation[i][1]]
421 PointJ = listPoints[triangulation[i][2]]
422 PointK = listPoints[triangulation[i][3]]
423 if(triangulation[i].type == "bbox") then
424 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
426 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
429 -- draw and fill the bad triangle
430 for i=1,#badTriangles do
431 PointI = listPoints[triangulation[badTriangles[i]][1]]
432 PointJ = listPoints[triangulation[badTriangles[i]][2]]
433 PointK = listPoints[triangulation[badTriangles[i]][3]]
434 output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
436 -- draw the circoncircle
437 for i=1,#badTriangles do
438 PointI = listPoints[triangulation[badTriangles[i]][1]]
439 PointJ = listPoints[triangulation[badTriangles[i]][2]]
440 PointK = listPoints[triangulation[badTriangles[i]][3]]
441 center, radius = circoncircle(PointI, PointJ, PointK)
442 output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
446 for i=1,#listPoints do
447 if(listPoints[i].type == "bbox") then
448 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
451 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
454 -- mark the point to add
455 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
456 elseif(step == "cavity") then
457 polygon = buildCavity(badTriangles, triangulation)
458 polyNew = cleanPoly(polygon)
459 -- remove the bad triangles
460 for j=1,#badTriangles do
461 table.remove(triangulation,badTriangles[j]-(j-1))
463 -- draw the triangles
464 for i=1,#triangulation do
465 PointI = listPoints[triangulation[i][1]]
466 PointJ = listPoints[triangulation[i][2]]
467 PointK = listPoints[triangulation[i][3]]
468 if(triangulation[i].type == "bbox") then
469 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
471 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
474 -- fill and draw the cavity
477 PointI = listPoints[polyNew[i]]
478 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
480 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
481 -- mark the points of the mesh
483 for i=1,#listPoints do
484 if(listPoints[i].type == "bbox") then
485 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
488 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
491 -- mark the adding point
492 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
493 elseif(step == "newT") then
494 polygon = buildCavity(badTriangles, triangulation)
495 polyNew = cleanPoly(polygon)
496 -- remove the bad triangles
497 for j=1,#badTriangles do
498 table.remove(triangulation,badTriangles[j]-(j-1))
500 -- draw the triangle of the triangulation
501 for i=1,#triangulation do
502 PointI = listPoints[triangulation[i][1]]
503 PointJ = listPoints[triangulation[i][2]]
504 PointK = listPoints[triangulation[i][3]]
505 if(triangulation[i].type == "bbox") then
506 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
508 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
511 -- fill and draw the cavity
514 PointI = listPoints[polyNew[i]]
515 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
517 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
518 -- draw the new triangles composed by the edges of the polygon and the added point
520 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 ..");"
521 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
522 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
526 for i=1,#listPoints do
527 if(listPoints[i].type == "bbox") then
528 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
531 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
534 -- mark the added point
535 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
540 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
542 output = output .. "pair MeshPoints[];"
543 -- build the triangulation
544 triangulation = BowyerWatson(listPoints,bbox)
545 badTriangles = buildBadTriangles(P,triangulation)
546 for i=1,#listPoints do
547 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
549 if(step == "badT") then
551 for i=1,#triangulation do
552 PointI = listPoints[triangulation[i][1]]
553 PointJ = listPoints[triangulation[i][2]]
554 PointK = listPoints[triangulation[i][3]]
555 if(triangulation[i].type == "bbox") then
556 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
558 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
561 -- draw and fill the bad triangle
562 for i=1,#badTriangles do
563 PointI = listPoints[triangulation[badTriangles[i]][1]]
564 PointJ = listPoints[triangulation[badTriangles[i]][2]]
565 PointK = listPoints[triangulation[badTriangles[i]][3]]
566 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
567 output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
569 -- draw the circoncircle
570 for i=1,#badTriangles do
571 PointI = listPoints[triangulation[badTriangles[i]][1]]
572 PointJ = listPoints[triangulation[badTriangles[i]][2]]
573 PointK = listPoints[triangulation[badTriangles[i]][3]]
574 center, radius = circoncircle(PointI, PointJ, PointK)
575 output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
579 for i=1,#listPoints do
580 if(listPoints[i].type == "bbox") then
581 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
584 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
587 -- mark the point to add
588 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
589 elseif(step == "cavity") then
590 polygon = buildCavity(badTriangles, triangulation)
591 polyNew = cleanPoly(polygon)
592 -- remove the bad triangles
593 for j=1,#badTriangles do
594 table.remove(triangulation,badTriangles[j]-(j-1))
596 -- draw the triangles
597 for i=1,#triangulation do
598 PointI = listPoints[triangulation[i][1]]
599 PointJ = listPoints[triangulation[i][2]]
600 PointK = listPoints[triangulation[i][3]]
601 if(triangulation[i].type == "bbox") then
602 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
604 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
607 -- fill and draw the cavity
610 PointI = listPoints[polyNew[i]]
611 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
613 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
614 output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
615 -- mark the points of the mesh
617 for i=1,#listPoints do
618 if(listPoints[i].type == "bbox") then
619 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
622 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
625 -- mark the adding point
626 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
627 elseif(step == "newT") then
628 polygon = buildCavity(badTriangles, triangulation)
629 polyNew = cleanPoly(polygon)
630 -- remove the bad triangles
631 for j=1,#badTriangles do
632 table.remove(triangulation,badTriangles[j]-(j-1))
634 -- draw the triangle of the triangulation
635 for i=1,#triangulation do
636 PointI = listPoints[triangulation[i][1]]
637 PointJ = listPoints[triangulation[i][2]]
638 PointK = listPoints[triangulation[i][3]]
639 if(triangulation[i].type == "bbox") then
640 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
642 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
648 PointI = listPoints[polyNew[i]]
649 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
651 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
652 -- draw the new triangles composed by the edges of the polygon and the added point
654 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;"
655 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;"
656 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;"
660 for i=1,#listPoints do
661 if(listPoints[i].type == "bbox") then
662 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
665 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
668 -- mark the added point
669 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
675 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
677 Sx,Sy=string.match(point,"%((.+),(.+)%)")
679 listPoints = buildList(chaine, mode)
682 P, listPoints = buildListExt(chaine,tonumber(point))
684 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
685 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
689 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
691 Sx,Sy=string.match(point,"%((.+),(.+)%)")
693 listPoints = buildList(chaine, mode)
696 P, listPoints = buildListExt(chaine,tonumber(point))
698 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
699 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
703 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
705 Sx,Sy=string.match(point,"%((.+),(.+)%)")
707 listPoints = buildList(chaine, mode)
710 P, listPoints = buildListExt(chaine,tonumber(point))
712 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
713 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
717 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
719 Sx,Sy=string.match(point,"%((.+),(.+)%)")
721 listPoints = buildList(chaine, mode)
724 P, listPoints = buildListExt(chaine,tonumber(point))
726 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
727 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
732 function drawGmshMP(file,points,scale)
733 listPoints,triangulation = readGmsh(file)
734 output = traceMeshMP(listPoints,triangulation,points)
735 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
739 function drawGmshMPinc(file,beginning,ending,points,scale)
740 listPoints,triangulation = readGmsh(file)
741 output = traceMeshMP(listPoints,triangulation,points)
742 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
749 function drawGmshTikZ(file,points,scale,color)
750 listPoints,triangulation = readGmsh(file)
751 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
752 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
757 function drawGmshTikZinc(file,beginning, ending,points,scale,color)
758 listPoints,triangulation = readGmsh(file)
759 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
760 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
765 -- buildVoronoi with MP
766 function gmshVoronoiMP(file,points,scale,tri,styleD,styleV)
767 listPoints,triangulation = readGmsh(file)
768 listVoronoi = buildVoronoi(listPoints, triangulation)
769 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
770 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
775 -- buildVoronoi with TikZ
776 function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV)
777 listPoints,triangulation = readGmsh(file)
778 listVoronoi = buildVoronoi(listPoints, triangulation)
779 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
780 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
784 -- buildVoronoi with MP
785 function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV)
786 listPoints,triangulation = readGmsh(file)
787 listVoronoi = buildVoronoi(listPoints, triangulation)
788 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
789 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
794 -- buildVoronoi with TikZ
795 function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV)
796 listPoints,triangulation = readGmsh(file)
797 listVoronoi = buildVoronoi(listPoints, triangulation)
798 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
799 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
804 --------------------------------------------------
805 -- Meshing of a polygon --
806 --------------------------------------------------
809 function TeXMeshPolygonMP(polygon,listPoints, grid, step)
813 function tracePolygonMP(polygon,points)
815 output = output .. "pair polygon[];"
818 output = output .. "polygon[".. i .. "] = (" .. polygon[i].x .. "," .. polygon[i].y .. ")*u;"
820 output = output .. "draw "
822 output = output .. "(" .. polygon[i].x .. "," .. polygon[i].y .. ")*u -- "
824 output = output .. "cycle withcolor \\luameshmpcolorPoly withpen pencircle scaled 1pt;"
825 if(points=="points") then
827 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. polygon[i].x ..",".. polygon[i].y .. ")*u ) withcolor \\luameshmpcolorPoly ;"
830 if(points=="dotpoints") then
832 output = output .. "drawdot (" .. polygon[i].x ..",".. polygon[i].y .. ")*u withcolor \\luameshmpcolorPoly withpen pencircle scaled 3;"
840 function drawMeshPolygonMP(chaine,mode,h,step,
842 local polygon = buildList(chaine, mode)
843 polygon = addPointsPolygon(polygon,h)
845 local grid = buildGrid(polygon,h)
847 local listPoints = addGridPoints(polygon,grid,h)
849 if(step=="polygon") then
851 output = tracePolygonMP(polygon,points)
853 if(step=="grid") then
855 output = tracePointsMP(grid,points)
856 output = output .. tracePolygonMP(polygon,points)
858 if(step=="points") then
859 -- polygon + only grid points inside the polygon
860 output = tracePointsMP(listPoints,points)
861 output = output .. tracePolygonMP(polygon,points)
863 if(step=="mesh") then
865 triangulation = BowyerWatson(listPoints,"none") -- no bbox
866 output = traceMeshMP(listPoints,triangulation,points)
867 output = output .. tracePolygonMP(polygon,points)
870 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"