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 local listPoints = buildList(chaine, mode)
144 local triangulation = BowyerWatson(listPoints,bbox)
145 local 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 local listPoints = buildList(chaine, mode)
155 local triangulation = BowyerWatson(listPoints,bbox)
156 local 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 local listPoints = buildList(chaine, mode)
165 local triangulation = BowyerWatson(listPoints,bbox)
166 local 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 local listPoints = buildList(chaine, mode,styleD,styleV)
176 local triangulation = BowyerWatson(listPoints,bbox)
177 local 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 .. "}$};"
212 if(points=="dotpoints") then
214 for i=1,#listPoints do
215 if(listPoints[i].type == "bbox") then
216 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$};"
219 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$};"
227 -- trace a triangulation with MP
228 function traceMeshMP(listPoints, triangulation,points)
230 output = output .. " pair MeshPoints[];"
231 for i=1,#listPoints do
232 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
234 for i=1,#triangulation do
235 PointI = listPoints[triangulation[i][1]]
236 PointJ = listPoints[triangulation[i][2]]
237 PointK = listPoints[triangulation[i][3]]
238 if(triangulation[i].type == "bbox") then
239 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
241 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
244 if(points=="points") then
246 for i=1,#listPoints do
247 if(listPoints[i].type == "bbox") then
248 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
251 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
255 if(points=="dotpoints") then
257 for i=1,#listPoints do
258 if(listPoints[i].type == "bbox") then
259 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
262 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
271 function buildMeshMPBW(chaine,mode,points,bbox,scale)
272 local listPoints = buildList(chaine, mode)
273 local triangulation = BowyerWatson(listPoints,bbox)
274 output = traceMeshMP(listPoints, triangulation,points)
275 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
279 -- buildMesh with MP include code
280 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
281 local listPoints = buildList(chaine, mode)
282 local triangulation = BowyerWatson(listPoints,bbox)
283 output = traceMeshMP(listPoints, triangulation,points)
284 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
288 -- buildMesh with TikZ
289 function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
290 local listPoints = buildList(chaine, mode)
291 local triangulation = BowyerWatson(listPoints,bbox)
292 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
293 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
297 -- buildMesh with TikZ
298 function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
299 local listPoints = buildList(chaine, mode)
300 local triangulation = BowyerWatson(listPoints,bbox)
301 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
302 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
307 -- print points of the mesh
308 function tracePointsMP(listPoints,points)
310 output = output .. " pair MeshPoints[];"
311 for i=1,#listPoints do
312 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
314 if(points=="points") then
316 for i=1,#listPoints do
317 if(listPoints[i].type == "bbox") then
318 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
321 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
325 for i=1,#listPoints do
326 if(listPoints[i].type == "bbox") then
327 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
329 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
336 -- print points of the mesh
337 function tracePointsTikZ(listPoints,points,color,colorBbox)
339 for i=1,#listPoints do
340 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
342 if(points=="points") then
344 for i=1,#listPoints do
345 if(listPoints[i].type == "bbox") then
346 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
349 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
353 for i=1,#listPoints do
354 if(listPoints[i].type == "bbox") then
355 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
357 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
364 -- print points to mesh
365 function printPointsMP(chaine,mode,points,bbox,scale)
366 local listPoints = buildList(chaine, mode)
367 if(bbox == "bbox" ) then
368 listPoints = buildBoundingBox(listPoints)
370 output = tracePointsMP(listPoints,points)
371 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
376 -- print points to mesh
377 function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
378 local listPoints = buildList(chaine, mode)
379 if(bbox == "bbox" ) then
380 listPoints = buildBoundingBox(listPoints)
382 output = tracePointsMP(listPoints,points)
383 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
387 -- print points to mesh
388 function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
389 local listPoints = buildList(chaine, mode)
390 if(bbox == "bbox" ) then
391 listPoints = buildBoundingBox(listPoints)
393 output = tracePointsTikZ(listPoints,points,color,colorBbox)
394 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
399 -- print points to mesh
400 function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
401 local listPoints = buildList(chaine, mode)
402 if(bbox == "bbox" ) then
403 listPoints = buildBoundingBox(listPoints)
405 output = tracePointsTikZ(listPoints,points,color,colorBbox)
406 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
412 function buildRect(largeur,a,b,nbrA, nbrB)
413 local listPoints = rectangleList(a,b,nbrA,nbrB)
414 local triangulation = BowyerWatson(listPoints,"none")
415 traceTikZ(listPoints, triangulation,largeur,"none")
420 function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
422 -- build the triangulation
423 local triangulation = BowyerWatson(listPoints,bbox)
424 local badTriangles = buildBadTriangles(P,triangulation,listPoints)
425 for i=1,#listPoints do
426 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
428 if(step == "badT") then
430 for i=1,#triangulation do
431 PointI = listPoints[triangulation[i][1]]
432 PointJ = listPoints[triangulation[i][2]]
433 PointK = listPoints[triangulation[i][3]]
434 if(triangulation[i].type == "bbox") then
435 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
437 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
440 -- draw and fill the bad triangle
441 for i=1,#badTriangles do
442 PointI = listPoints[triangulation[badTriangles[i]][1]]
443 PointJ = listPoints[triangulation[badTriangles[i]][2]]
444 PointK = listPoints[triangulation[badTriangles[i]][3]]
445 output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
447 -- draw the circoncircle
448 for i=1,#badTriangles do
449 PointI = listPoints[triangulation[badTriangles[i]][1]]
450 PointJ = listPoints[triangulation[badTriangles[i]][2]]
451 PointK = listPoints[triangulation[badTriangles[i]][3]]
452 center, radius = circoncircle(PointI, PointJ, PointK)
453 output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
457 for i=1,#listPoints do
458 if(listPoints[i].type == "bbox") then
459 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
462 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
465 -- mark the point to add
466 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
467 elseif(step == "cavity") then
468 polygon = buildCavity(badTriangles, triangulation)
469 polyNew = cleanPoly(polygon)
470 -- remove the bad triangles
471 for j=1,#badTriangles do
472 table.remove(triangulation,badTriangles[j]-(j-1))
474 -- draw the triangles
475 for i=1,#triangulation do
476 PointI = listPoints[triangulation[i][1]]
477 PointJ = listPoints[triangulation[i][2]]
478 PointK = listPoints[triangulation[i][3]]
479 if(triangulation[i].type == "bbox") then
480 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
482 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
485 -- fill and draw the cavity
488 PointI = listPoints[polyNew[i]]
489 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
491 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
492 -- mark the points of the mesh
494 for i=1,#listPoints do
495 if(listPoints[i].type == "bbox") then
496 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
499 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
502 -- mark the adding point
503 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
504 elseif(step == "newT") then
505 polygon = buildCavity(badTriangles, triangulation)
506 polyNew = cleanPoly(polygon)
507 -- remove the bad triangles
508 for j=1,#badTriangles do
509 table.remove(triangulation,badTriangles[j]-(j-1))
511 -- draw the triangle of the triangulation
512 for i=1,#triangulation do
513 PointI = listPoints[triangulation[i][1]]
514 PointJ = listPoints[triangulation[i][2]]
515 PointK = listPoints[triangulation[i][3]]
516 if(triangulation[i].type == "bbox") then
517 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
519 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
522 -- fill and draw the cavity
525 PointI = listPoints[polyNew[i]]
526 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
528 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
529 -- draw the new triangles composed by the edges of the polygon and the added point
531 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 ..");"
532 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
533 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
537 for i=1,#listPoints do
538 if(listPoints[i].type == "bbox") then
539 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
542 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
545 -- mark the added point
546 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
551 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
553 output = output .. "pair MeshPoints[];"
554 -- build the triangulation
555 local triangulation = {}
556 local badTriangles = {}
557 triangulation = BowyerWatson(listPoints,bbox)
558 badTriangles = buildBadTriangles(P,triangulation,listPoints)
559 for i=1,#listPoints do
560 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
562 if(step == "badT") then
564 for i=1,#triangulation do
565 PointI = listPoints[triangulation[i][1]]
566 PointJ = listPoints[triangulation[i][2]]
567 PointK = listPoints[triangulation[i][3]]
568 if(triangulation[i].type == "bbox") then
569 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
571 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
574 -- draw and fill the bad triangle
575 for i=1,#badTriangles do
576 PointI = listPoints[triangulation[badTriangles[i]][1]]
577 PointJ = listPoints[triangulation[badTriangles[i]][2]]
578 PointK = listPoints[triangulation[badTriangles[i]][3]]
579 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
580 output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
582 -- draw the circoncircle
583 for i=1,#badTriangles do
584 PointI = listPoints[triangulation[badTriangles[i]][1]]
585 PointJ = listPoints[triangulation[badTriangles[i]][2]]
586 PointK = listPoints[triangulation[badTriangles[i]][3]]
587 center, radius = circoncircle(PointI, PointJ, PointK)
588 output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
592 for i=1,#listPoints do
593 if(listPoints[i].type == "bbox") then
594 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
597 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
600 -- mark the point to add
601 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
602 elseif(step == "cavity") then
603 polygon = buildCavity(badTriangles, triangulation)
604 polyNew = cleanPoly(polygon)
605 -- remove the bad triangles
606 for j=1,#badTriangles do
607 table.remove(triangulation,badTriangles[j]-(j-1))
609 -- draw the triangles
610 for i=1,#triangulation do
611 PointI = listPoints[triangulation[i][1]]
612 PointJ = listPoints[triangulation[i][2]]
613 PointK = listPoints[triangulation[i][3]]
614 if(triangulation[i].type == "bbox") then
615 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
617 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
620 -- fill and draw the cavity
623 PointI = listPoints[polyNew[i]]
624 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
626 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
627 output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
628 -- mark the points of the mesh
630 for i=1,#listPoints do
631 if(listPoints[i].type == "bbox") then
632 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
635 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
638 -- mark the adding point
639 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
640 elseif(step == "newT") then
641 polygon = buildCavity(badTriangles, triangulation)
642 polyNew = cleanPoly(polygon)
643 -- remove the bad triangles
644 for j=1,#badTriangles do
645 table.remove(triangulation,badTriangles[j]-(j-1))
647 -- draw the triangle of the triangulation
648 for i=1,#triangulation do
649 PointI = listPoints[triangulation[i][1]]
650 PointJ = listPoints[triangulation[i][2]]
651 PointK = listPoints[triangulation[i][3]]
652 if(triangulation[i].type == "bbox") then
653 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
655 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
661 PointI = listPoints[polyNew[i]]
662 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
664 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
665 -- draw the new triangles composed by the edges of the polygon and the added point
667 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;"
668 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;"
669 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;"
673 for i=1,#listPoints do
674 if(listPoints[i].type == "bbox") then
675 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
678 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
681 -- mark the added point
682 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
688 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
689 local listPoints = {}
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.."]".. output .. "\\end{tikzpicture}"
703 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
704 local listPoints = {}
706 Sx,Sy=string.match(point,"%((.+),(.+)%)")
708 listPoints = buildList(chaine, mode)
711 P, listPoints = buildListExt(chaine,tonumber(point))
713 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
714 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
718 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
719 local listPoints = {}
721 Sx,Sy=string.match(point,"%((.+),(.+)%)")
723 listPoints = buildList(chaine, mode)
726 P, listPoints = buildListExt(chaine,tonumber(point))
728 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
729 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
733 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
734 local listPoints = {}
736 Sx,Sy=string.match(point,"%((.+),(.+)%)")
738 listPoints = buildList(chaine, mode)
741 P, listPoints = buildListExt(chaine,tonumber(point))
743 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
744 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
749 function drawGmshMP(file,points,scale)
750 local listPoints,triangulation = readGmsh(file)
751 output = traceMeshMP(listPoints,triangulation,points)
752 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
756 function drawGmshMPinc(file,beginning,ending,points,scale)
757 local listPoints,triangulation = readGmsh(file)
758 output = traceMeshMP(listPoints,triangulation,points)
759 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
766 function drawGmshTikZ(file,points,scale,color)
767 local listPoints,triangulation = readGmsh(file)
768 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
769 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
774 function drawGmshTikZinc(file,beginning, ending,points,scale,color)
775 local listPoints,triangulation = readGmsh(file)
776 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
777 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
782 -- buildVoronoi with MP
783 function gmshVoronoiMP(file,points,scale,tri,styleD,styleV)
784 local listPoints,triangulation = readGmsh(file)
785 local listVoronoi = buildVoronoi(listPoints, triangulation)
786 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
787 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
792 -- buildVoronoi with TikZ
793 function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV)
794 local listPoints,triangulation = readGmsh(file)
795 local listVoronoi = buildVoronoi(listPoints, triangulation)
796 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
797 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
801 -- buildVoronoi with MP
802 function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV)
803 local listPoints,triangulation = readGmsh(file)
804 local listVoronoi = buildVoronoi(listPoints, triangulation)
805 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
806 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
811 -- buildVoronoi with TikZ
812 function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV)
813 local listPoints,triangulation = readGmsh(file)
814 local listVoronoi = buildVoronoi(listPoints, triangulation)
815 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
816 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
821 --------------------------------------------------
822 -- Meshing of a polygon --
823 --------------------------------------------------
825 function tracePolygonMP(polygon,points)
827 output = output .. "pair polygon[];"
829 output = output .. "polygon[".. i .. "] = (" .. polygon[i].x .. "," .. polygon[i].y .. ")*u;"
831 output = output .. "draw "
833 output = output .. "(" .. polygon[i].x .. "," .. polygon[i].y .. ")*u -- "
835 output = output .. "cycle withcolor \\luameshmpcolorPoly withpen pencircle scaled 1pt;"
836 if(points=="points") then
838 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. polygon[i].x ..",".. polygon[i].y .. ")*u ) withcolor \\luameshmpcolorPoly ;"
841 if(points=="dotpoints") then
843 output = output .. "drawdot (" .. polygon[i].x ..",".. polygon[i].y .. ")*u withcolor \\luameshmpcolorPoly withpen pencircle scaled 3;"
850 function tracePolygonTikZ(polygon,points, colorPoly)
853 output = output .. "\\coordinate (polygon".. i .. ") at (" .. polygon[i].x .. "," .. polygon[i].y .. ");"
855 output = output .. "\\draw[color=".. colorPoly .. ", thick]"
857 output = output .. "(" .. polygon[i].x .. "," .. polygon[i].y .. ") -- "
859 output = output .. "cycle;"
860 if(points=="points") then
862 output = output .. "\\draw[color="..colorPoly.."] (" .. polygon[i].x ..",".. polygon[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
865 if(points=="dotpoints") then
867 output = output .. "\\draw[color="..colorPoly.."] (" .. polygon[i].x ..",".. polygon[i].y .. ") node {$\\bullet$};"
875 function drawMeshPolygonMP(chaine,mode,h,step,
877 local polygon = buildList(chaine, mode)
878 polygon = addPointsPolygon(polygon,h)
879 local grid = buildGrid(polygon,h,random)
880 local listPoints = addGridPoints(polygon,grid,h)
881 if(step=="polygon") then
883 output = tracePolygonMP(polygon,points)
885 if(step=="grid") then
887 output = tracePointsMP(grid,points)
888 output = output .. tracePolygonMP(polygon,points)
890 if(step=="points") then
891 -- polygon + only grid points inside the polygon
892 output = tracePointsMP(listPoints,points)
893 output = output .. tracePolygonMP(polygon,points)
895 if(step=="mesh") then
897 triangulation = BowyerWatson(listPoints,"none") -- no bbox
898 output = traceMeshMP(listPoints,triangulation,points)
899 output = output .. tracePolygonMP(polygon,points)
902 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
908 function drawMeshPolygonTikZ(chaine,mode,h,step,
909 points,scale,color,colorPoly,random)
910 local polygon = buildList(chaine, mode)
911 polygon = addPointsPolygon(polygon,h)
912 local grid = buildGrid(polygon,h,random)
913 local listPoints = addGridPoints(polygon,grid,h)
914 if(step=="polygon") then
916 output = tracePolygonTikZ(polygon,points,colorPoly)
918 if(step=="grid") then
920 output = tracePointsTikZ(grid,points,color,"none") -- none for colorBbox
921 output = output .. tracePolygonTikZ(polygon,points,colorPoly)
923 if(step=="points") then
924 -- polygon + only grid points inside the polygon
925 output = tracePointsTikZ(listPoints,points,color,"none")
926 output = output .. tracePolygonTikZ(polygon,points,colorPoly)
928 if(step=="mesh") then
930 triangulation = BowyerWatson(listPoints,"none") -- no bbox
931 output = traceMeshTikZ(listPoints,triangulation,points,color,"none")
932 output = output .. tracePolygonTikZ(polygon,points,colorPoly)
934 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
938 function drawMeshPolygonMPinc(chaine,beginning,ending,mode,h,step,
940 local polygon = buildList(chaine, mode)
941 polygon = addPointsPolygon(polygon,h)
942 local grid = buildGrid(polygon,h,random)
943 local listPoints = addGridPoints(polygon,grid,h)
944 if(step=="polygon") then
946 output = tracePolygonMP(polygon,points)
948 if(step=="grid") then
950 output = tracePointsMP(grid,points)
951 output = output .. tracePolygonMP(polygon,points)
953 if(step=="points") then
954 -- polygon + only grid points inside the polygon
955 output = tracePointsMP(listPoints,points)
956 output = output .. tracePolygonMP(polygon,points)
958 if(step=="mesh") then
960 triangulation = BowyerWatson(listPoints,"none") -- no bbox
961 output = traceMeshMP(listPoints,triangulation,points)
962 output = output .. tracePolygonMP(polygon,points)
964 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
970 function drawMeshPolygonTikZinc(chaine,beginning,ending,mode,h,step,
971 points,scale,color,colorPoly,random)
972 local polygon = buildList(chaine, mode)
973 polygon = addPointsPolygon(polygon,h)
974 local grid = buildGrid(polygon,h,random)
975 local listPoints = addGridPoints(polygon,grid,h)
976 if(step=="polygon") then
978 output = tracePolygonTikZ(polygon,points,colorPoly)
980 if(step=="grid") then
982 output = tracePointsTikZ(grid,points,color,"none") -- none for colorBbox
983 output = output .. tracePolygonTikZ(polygon,points,colorPoly)
985 if(step=="points") then
986 -- polygon + only grid points inside the polygon
987 output = tracePointsTikZ(listPoints,points,color,"none")
988 output = output .. tracePolygonTikZ(polygon,points,colorPoly)
990 if(step=="mesh") then
992 triangulation = BowyerWatson(listPoints,"none") -- no bbox
993 output = traceMeshTikZ(listPoints,triangulation,points,color,"none")
994 output = output .. tracePolygonTikZ(polygon,points,colorPoly)
996 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"