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 .. "}$};"
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 local listPoints = buildList(chaine, mode)
262 local 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 local listPoints = buildList(chaine, mode)
271 local 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 local listPoints = buildList(chaine, mode)
280 local 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 local listPoints = buildList(chaine, mode)
289 local 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 local 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 local 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 local 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 local 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 local listPoints = rectangleList(a,b,nbrA,nbrB)
403 local 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 local triangulation = BowyerWatson(listPoints,bbox)
413 local badTriangles = buildBadTriangles(P,triangulation,listPoints)
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 local triangulation = {}
545 local badTriangles = {}
546 triangulation = BowyerWatson(listPoints,bbox)
547 badTriangles = buildBadTriangles(P,triangulation,listPoints)
548 for i=1,#listPoints do
549 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
551 if(step == "badT") then
553 for i=1,#triangulation do
554 PointI = listPoints[triangulation[i][1]]
555 PointJ = listPoints[triangulation[i][2]]
556 PointK = listPoints[triangulation[i][3]]
557 if(triangulation[i].type == "bbox") then
558 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
560 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
563 -- draw and fill the bad triangle
564 for i=1,#badTriangles do
565 PointI = listPoints[triangulation[badTriangles[i]][1]]
566 PointJ = listPoints[triangulation[badTriangles[i]][2]]
567 PointK = listPoints[triangulation[badTriangles[i]][3]]
568 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
569 output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
571 -- draw the circoncircle
572 for i=1,#badTriangles do
573 PointI = listPoints[triangulation[badTriangles[i]][1]]
574 PointJ = listPoints[triangulation[badTriangles[i]][2]]
575 PointK = listPoints[triangulation[badTriangles[i]][3]]
576 center, radius = circoncircle(PointI, PointJ, PointK)
577 output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
581 for i=1,#listPoints do
582 if(listPoints[i].type == "bbox") then
583 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
586 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
589 -- mark the point to add
590 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
591 elseif(step == "cavity") then
592 polygon = buildCavity(badTriangles, triangulation)
593 polyNew = cleanPoly(polygon)
594 -- remove the bad triangles
595 for j=1,#badTriangles do
596 table.remove(triangulation,badTriangles[j]-(j-1))
598 -- draw the triangles
599 for i=1,#triangulation do
600 PointI = listPoints[triangulation[i][1]]
601 PointJ = listPoints[triangulation[i][2]]
602 PointK = listPoints[triangulation[i][3]]
603 if(triangulation[i].type == "bbox") then
604 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
606 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
609 -- fill and draw the cavity
612 PointI = listPoints[polyNew[i]]
613 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
615 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
616 output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
617 -- mark the points of the mesh
619 for i=1,#listPoints do
620 if(listPoints[i].type == "bbox") then
621 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
624 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
627 -- mark the adding point
628 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
629 elseif(step == "newT") then
630 polygon = buildCavity(badTriangles, triangulation)
631 polyNew = cleanPoly(polygon)
632 -- remove the bad triangles
633 for j=1,#badTriangles do
634 table.remove(triangulation,badTriangles[j]-(j-1))
636 -- draw the triangle of the triangulation
637 for i=1,#triangulation do
638 PointI = listPoints[triangulation[i][1]]
639 PointJ = listPoints[triangulation[i][2]]
640 PointK = listPoints[triangulation[i][3]]
641 if(triangulation[i].type == "bbox") then
642 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
644 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
650 PointI = listPoints[polyNew[i]]
651 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
653 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
654 -- draw the new triangles composed by the edges of the polygon and the added point
656 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;"
657 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;"
658 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;"
662 for i=1,#listPoints do
663 if(listPoints[i].type == "bbox") then
664 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
667 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
670 -- mark the added point
671 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
677 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
678 local listPoints = {}
680 Sx,Sy=string.match(point,"%((.+),(.+)%)")
682 listPoints = buildList(chaine, mode)
685 P, listPoints = buildListExt(chaine,tonumber(point))
687 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
688 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
692 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
693 local listPoints = {}
695 Sx,Sy=string.match(point,"%((.+),(.+)%)")
697 listPoints = buildList(chaine, mode)
700 P, listPoints = buildListExt(chaine,tonumber(point))
702 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
703 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
707 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
708 local listPoints = {}
710 Sx,Sy=string.match(point,"%((.+),(.+)%)")
712 listPoints = buildList(chaine, mode)
715 P, listPoints = buildListExt(chaine,tonumber(point))
717 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
718 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
722 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
723 local listPoints = {}
725 Sx,Sy=string.match(point,"%((.+),(.+)%)")
727 listPoints = buildList(chaine, mode)
730 P, listPoints = buildListExt(chaine,tonumber(point))
732 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
733 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
738 function drawGmshMP(file,points,scale)
739 local listPoints,triangulation = readGmsh(file)
740 output = traceMeshMP(listPoints,triangulation,points)
741 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
745 function drawGmshMPinc(file,beginning,ending,points,scale)
746 local listPoints,triangulation = readGmsh(file)
747 output = traceMeshMP(listPoints,triangulation,points)
748 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
755 function drawGmshTikZ(file,points,scale,color)
756 local listPoints,triangulation = readGmsh(file)
757 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
758 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
763 function drawGmshTikZinc(file,beginning, ending,points,scale,color)
764 local listPoints,triangulation = readGmsh(file)
765 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
766 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
771 -- buildVoronoi with MP
772 function gmshVoronoiMP(file,points,scale,tri,styleD,styleV)
773 local listPoints,triangulation = readGmsh(file)
774 local listVoronoi = buildVoronoi(listPoints, triangulation)
775 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
776 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
781 -- buildVoronoi with TikZ
782 function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV)
783 local listPoints,triangulation = readGmsh(file)
784 local listVoronoi = buildVoronoi(listPoints, triangulation)
785 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
786 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
790 -- buildVoronoi with MP
791 function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV)
792 local listPoints,triangulation = readGmsh(file)
793 local listVoronoi = buildVoronoi(listPoints, triangulation)
794 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
795 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
800 -- buildVoronoi with TikZ
801 function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV)
802 local listPoints,triangulation = readGmsh(file)
803 local listVoronoi = buildVoronoi(listPoints, triangulation)
804 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
805 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
810 --------------------------------------------------
811 -- Meshing of a polygon --
812 --------------------------------------------------
815 function TeXMeshPolygonMP(polygon,listPoints, grid, step)
819 function tracePolygonMP(polygon,points)
821 output = output .. "pair polygon[];"
823 output = output .. "polygon[".. i .. "] = (" .. polygon[i].x .. "," .. polygon[i].y .. ")*u;"
825 output = output .. "draw "
827 output = output .. "(" .. polygon[i].x .. "," .. polygon[i].y .. ")*u -- "
829 output = output .. "cycle withcolor \\luameshmpcolorPoly withpen pencircle scaled 1pt;"
830 if(points=="points") then
832 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. polygon[i].x ..",".. polygon[i].y .. ")*u ) withcolor \\luameshmpcolorPoly ;"
835 if(points=="dotpoints") then
837 output = output .. "drawdot (" .. polygon[i].x ..",".. polygon[i].y .. ")*u withcolor \\luameshmpcolorPoly withpen pencircle scaled 3;"
845 function drawMeshPolygonMP(chaine,mode,h,step,
847 local polygon = buildList(chaine, mode)
848 polygon = addPointsPolygon(polygon,h)
849 local grid = buildGrid(polygon,h)
850 local listPoints = addGridPoints(polygon,grid,h)
851 if(step=="polygon") then
853 output = tracePolygonMP(polygon,points)
855 if(step=="grid") then
857 output = tracePointsMP(grid,points)
858 output = output .. tracePolygonMP(polygon,points)
860 if(step=="points") then
861 -- polygon + only grid points inside the polygon
862 output = tracePointsMP(listPoints,points)
863 output = output .. tracePolygonMP(polygon,points)
865 if(step=="mesh") then
867 triangulation = BowyerWatson(listPoints,"none") -- no bbox
868 output = traceMeshMP(listPoints,triangulation,points)
869 output = output .. tracePolygonMP(polygon,points)
872 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"