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 ;"
249 function buildMeshMPBW(chaine,mode,points,bbox,scale)
250 listPoints = buildList(chaine, mode)
251 triangulation = BowyerWatson(listPoints,bbox)
252 output = traceMeshMP(listPoints, triangulation,points)
253 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
257 -- buildMesh with MP include code
258 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
259 listPoints = buildList(chaine, mode)
260 triangulation = BowyerWatson(listPoints,bbox)
261 output = traceMeshMP(listPoints, triangulation,points)
262 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
266 -- buildMesh with TikZ
267 function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
268 listPoints = buildList(chaine, mode)
269 triangulation = BowyerWatson(listPoints,bbox)
270 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
271 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
275 -- buildMesh with TikZ
276 function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
277 listPoints = buildList(chaine, mode)
278 triangulation = BowyerWatson(listPoints,bbox)
279 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
280 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
285 -- print points of the mesh
286 function tracePointsMP(listPoints,points)
288 output = output .. " pair MeshPoints[];"
289 for i=1,#listPoints do
290 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
292 if(points=="points") then
294 for i=1,#listPoints do
295 if(listPoints[i].type == "bbox") then
296 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
299 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
303 for i=1,#listPoints do
304 if(listPoints[i].type == "bbox") then
305 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
307 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
314 -- print points of the mesh
315 function tracePointsTikZ(listPoints,points,color,colorBbox)
317 for i=1,#listPoints do
318 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
320 if(points=="points") then
322 for i=1,#listPoints do
323 if(listPoints[i].type == "bbox") then
324 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
327 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
331 for i=1,#listPoints do
332 if(listPoints[i].type == "bbox") then
333 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
335 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
342 -- print points to mesh
343 function printPointsMP(chaine,mode,points,bbox,scale)
344 listPoints = buildList(chaine, mode)
345 if(bbox == "bbox" ) then
346 listPoints = buildBoundingBox(listPoints)
348 output = tracePointsMP(listPoints,points)
349 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
354 -- print points to mesh
355 function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
356 listPoints = buildList(chaine, mode)
357 if(bbox == "bbox" ) then
358 listPoints = buildBoundingBox(listPoints)
360 output = tracePointsMP(listPoints,points)
361 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
365 -- print points to mesh
366 function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
367 listPoints = buildList(chaine, mode)
368 if(bbox == "bbox" ) then
369 listPoints = buildBoundingBox(listPoints)
371 output = tracePointsTikZ(listPoints,points,color,colorBbox)
372 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
377 -- print points to mesh
378 function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
379 listPoints = buildList(chaine, mode)
380 if(bbox == "bbox" ) then
381 listPoints = buildBoundingBox(listPoints)
383 output = tracePointsTikZ(listPoints,points,color,colorBbox)
384 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
390 function buildRect(largeur,a,b,nbrA, nbrB)
391 listPoints = rectangleList(a,b,nbrA,nbrB)
392 triangulation = BowyerWatson(listPoints,"none")
393 traceTikZ(listPoints, triangulation,largeur,"none")
398 function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
400 -- build the triangulation
401 triangulation = BowyerWatson(listPoints,bbox)
402 badTriangles = buildBadTriangles(P,triangulation)
403 for i=1,#listPoints do
404 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
406 if(step == "badT") then
408 for i=1,#triangulation do
409 PointI = listPoints[triangulation[i][1]]
410 PointJ = listPoints[triangulation[i][2]]
411 PointK = listPoints[triangulation[i][3]]
412 if(triangulation[i].type == "bbox") then
413 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
415 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
418 -- draw and fill the bad triangle
419 for i=1,#badTriangles do
420 PointI = listPoints[triangulation[badTriangles[i]][1]]
421 PointJ = listPoints[triangulation[badTriangles[i]][2]]
422 PointK = listPoints[triangulation[badTriangles[i]][3]]
423 output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
425 -- draw the circoncircle
426 for i=1,#badTriangles do
427 PointI = listPoints[triangulation[badTriangles[i]][1]]
428 PointJ = listPoints[triangulation[badTriangles[i]][2]]
429 PointK = listPoints[triangulation[badTriangles[i]][3]]
430 center, radius = circoncircle(PointI, PointJ, PointK)
431 output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
435 for i=1,#listPoints do
436 if(listPoints[i].type == "bbox") then
437 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
440 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
443 -- mark the point to add
444 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
445 elseif(step == "cavity") then
446 polygon = buildCavity(badTriangles, triangulation)
447 polyNew = cleanPoly(polygon)
448 -- remove the bad triangles
449 for j=1,#badTriangles do
450 table.remove(triangulation,badTriangles[j]-(j-1))
452 -- draw the triangles
453 for i=1,#triangulation do
454 PointI = listPoints[triangulation[i][1]]
455 PointJ = listPoints[triangulation[i][2]]
456 PointK = listPoints[triangulation[i][3]]
457 if(triangulation[i].type == "bbox") then
458 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
460 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
463 -- fill and draw the cavity
466 PointI = listPoints[polyNew[i]]
467 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
469 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
470 -- mark the points of the mesh
472 for i=1,#listPoints do
473 if(listPoints[i].type == "bbox") then
474 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
477 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
480 -- mark the adding point
481 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
482 elseif(step == "newT") then
483 polygon = buildCavity(badTriangles, triangulation)
484 polyNew = cleanPoly(polygon)
485 -- remove the bad triangles
486 for j=1,#badTriangles do
487 table.remove(triangulation,badTriangles[j]-(j-1))
489 -- draw the triangle of the triangulation
490 for i=1,#triangulation do
491 PointI = listPoints[triangulation[i][1]]
492 PointJ = listPoints[triangulation[i][2]]
493 PointK = listPoints[triangulation[i][3]]
494 if(triangulation[i].type == "bbox") then
495 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
497 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
500 -- fill and draw the cavity
503 PointI = listPoints[polyNew[i]]
504 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
506 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
507 -- draw the new triangles composed by the edges of the polygon and the added point
509 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 ..");"
510 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
511 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
515 for i=1,#listPoints do
516 if(listPoints[i].type == "bbox") then
517 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
520 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
523 -- mark the added point
524 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
529 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
531 output = output .. "pair MeshPoints[];"
532 -- build the triangulation
533 triangulation = BowyerWatson(listPoints,bbox)
534 badTriangles = buildBadTriangles(P,triangulation)
535 for i=1,#listPoints do
536 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
538 if(step == "badT") then
540 for i=1,#triangulation do
541 PointI = listPoints[triangulation[i][1]]
542 PointJ = listPoints[triangulation[i][2]]
543 PointK = listPoints[triangulation[i][3]]
544 if(triangulation[i].type == "bbox") then
545 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
547 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
550 -- draw and fill the bad triangle
551 for i=1,#badTriangles do
552 PointI = listPoints[triangulation[badTriangles[i]][1]]
553 PointJ = listPoints[triangulation[badTriangles[i]][2]]
554 PointK = listPoints[triangulation[badTriangles[i]][3]]
555 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
556 output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
558 -- draw the circoncircle
559 for i=1,#badTriangles do
560 PointI = listPoints[triangulation[badTriangles[i]][1]]
561 PointJ = listPoints[triangulation[badTriangles[i]][2]]
562 PointK = listPoints[triangulation[badTriangles[i]][3]]
563 center, radius = circoncircle(PointI, PointJ, PointK)
564 output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
568 for i=1,#listPoints do
569 if(listPoints[i].type == "bbox") then
570 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
573 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
576 -- mark the point to add
577 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
578 elseif(step == "cavity") then
579 polygon = buildCavity(badTriangles, triangulation)
580 polyNew = cleanPoly(polygon)
581 -- remove the bad triangles
582 for j=1,#badTriangles do
583 table.remove(triangulation,badTriangles[j]-(j-1))
585 -- draw the triangles
586 for i=1,#triangulation do
587 PointI = listPoints[triangulation[i][1]]
588 PointJ = listPoints[triangulation[i][2]]
589 PointK = listPoints[triangulation[i][3]]
590 if(triangulation[i].type == "bbox") then
591 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
593 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
596 -- fill and draw the cavity
599 PointI = listPoints[polyNew[i]]
600 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
602 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
603 output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
604 -- mark the points of the mesh
606 for i=1,#listPoints do
607 if(listPoints[i].type == "bbox") then
608 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
611 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
614 -- mark the adding point
615 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
616 elseif(step == "newT") then
617 polygon = buildCavity(badTriangles, triangulation)
618 polyNew = cleanPoly(polygon)
619 -- remove the bad triangles
620 for j=1,#badTriangles do
621 table.remove(triangulation,badTriangles[j]-(j-1))
623 -- draw the triangle of the triangulation
624 for i=1,#triangulation do
625 PointI = listPoints[triangulation[i][1]]
626 PointJ = listPoints[triangulation[i][2]]
627 PointK = listPoints[triangulation[i][3]]
628 if(triangulation[i].type == "bbox") then
629 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
631 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
637 PointI = listPoints[polyNew[i]]
638 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
640 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
641 -- draw the new triangles composed by the edges of the polygon and the added point
643 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;"
644 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;"
645 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;"
649 for i=1,#listPoints do
650 if(listPoints[i].type == "bbox") then
651 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
654 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
657 -- mark the added point
658 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
664 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
666 Sx,Sy=string.match(point,"%((.+),(.+)%)")
668 listPoints = buildList(chaine, mode)
671 P, listPoints = buildListExt(chaine,tonumber(point))
673 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
674 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
678 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
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.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
692 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
694 Sx,Sy=string.match(point,"%((.+),(.+)%)")
696 listPoints = buildList(chaine, mode)
699 P, listPoints = buildListExt(chaine,tonumber(point))
701 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
702 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
706 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
708 Sx,Sy=string.match(point,"%((.+),(.+)%)")
710 listPoints = buildList(chaine, mode)
713 P, listPoints = buildListExt(chaine,tonumber(point))
715 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
716 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
721 function drawGmshMP(file,points,scale)
722 listPoints,triangulation = readGmsh(file)
723 output = traceMeshMP(listPoints,triangulation,points)
724 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
728 function drawGmshMPinc(file,beginning,ending,points,scale)
729 listPoints,triangulation = readGmsh(file)
730 output = traceMeshMP(listPoints,triangulation,points)
731 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
738 function drawGmshTikZ(file,points,scale,color)
739 listPoints,triangulation = readGmsh(file)
740 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
741 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
746 function drawGmshTikZinc(file,beginning, ending,points,scale,color)
747 listPoints,triangulation = readGmsh(file)
748 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
749 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
754 -- buildVoronoi with MP
755 function gmshVoronoiMP(file,points,scale,tri,styleD,styleV)
756 listPoints,triangulation = readGmsh(file)
757 listVoronoi = buildVoronoi(listPoints, triangulation)
758 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
759 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
764 -- buildVoronoi with TikZ
765 function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV)
766 listPoints,triangulation = readGmsh(file)
767 listVoronoi = buildVoronoi(listPoints, triangulation)
768 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
769 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
773 -- buildVoronoi with MP
774 function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV)
775 listPoints,triangulation = readGmsh(file)
776 listVoronoi = buildVoronoi(listPoints, triangulation)
777 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
778 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
783 -- buildVoronoi with TikZ
784 function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV)
785 listPoints,triangulation = readGmsh(file)
786 listVoronoi = buildVoronoi(listPoints, triangulation)
787 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
788 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"