1 -- Bowyer and Watson algorithm
3 function BowyerWatson (listPoints,bbox)
4 local triangulation = {}
5 local lgth = #listPoints
6 -- add four points to listPoints to have a bounding box
7 listPoints = buildBoundingBox(listPoints)
9 triangulation[1] = {lgth+1, lgth+2, lgth+3,type="bbox"}
10 -- the second triangle
11 triangulation[2] = {lgth+1, lgth+3, lgth+4,type="bbox"}
12 -- add points one by one
14 -- find the triangles which the circumcircle contained the point to add
15 badTriangles = buildBadTriangles(listPoints[i],triangulation)
16 -- build the polygon of the cavity containing the point to add
17 polygon = buildCavity(badTriangles, triangulation)
18 -- remove the bad triangles
19 for j=1,#badTriangles do
20 table.remove(triangulation,badTriangles[j]-(j-1))
22 -- build the new triangles and add them to triangulation
24 if((polygon[j][1]>lgth) or (polygon[j][2]>lgth) or (i>lgth)) then
25 table.insert(triangulation,{polygon[j][1],polygon[j][2],i,type="bbox"})
27 table.insert(triangulation,{polygon[j][1],polygon[j][2],i,type="in"})
30 end -- end adding points of the listPoints
31 -- remove bounding box
32 if(bbox ~= "bbox") then
33 triangulation = removeBoundingBox(triangulation,lgth)
34 table.remove(listPoints,lgth+1)
35 table.remove(listPoints,lgth+1)
36 table.remove(listPoints,lgth+1)
37 table.remove(listPoints,lgth+1)
43 function buildBoundingBox(listPoints)
44 -- listPoints : list of points
45 -- epsV : parameter for the distance of the bounding box
46 local xmin, xmax, ymin, ymax, eps
51 for i=1,#listPoints do
52 if (listPoints[i].x < xmin) then
53 xmin = listPoints[i].x
55 if (listPoints[i].x > xmax) then
56 xmax = listPoints[i].x
58 if (listPoints[i].y < ymin) then
59 ymin = listPoints[i].y
61 if (listPoints[i].y > ymax) then
62 ymax = listPoints[i].y
65 eps = math.max(math.abs(xmax-xmin),math.abs(ymax-ymin))*0.15
70 -- add points of the bounding box in last positions
71 table.insert(listPoints,{x=xmin,y=ymin,type="bbox"})
72 table.insert(listPoints,{x=xmin,y=ymax,type="bbox"})
73 table.insert(listPoints,{x=xmax,y=ymax,type="bbox"})
74 table.insert(listPoints,{x=xmax,y=ymin,type="bbox"})
78 function removeBoundingBox(triangulation,lgth)
79 -- build the four bounding box edge
86 for i=1,#triangulation do
87 boolE1 = pointInTriangle(point1,triangulation[i])
88 boolE2 = pointInTriangle(point2,triangulation[i])
89 boolE3 = pointInTriangle(point3,triangulation[i])
90 boolE4 = pointInTriangle(point4,triangulation[i])
91 if((not boolE1) and (not boolE2) and (not boolE3) and (not boolE4)) then
92 table.insert(newTriangulation,triangulation[i])
95 return newTriangulation
99 function buildBadTriangles(point, triangulation)
101 for j=1,#triangulation do -- for all triangles
102 A = listPoints[triangulation[j][1]]
103 B = listPoints[triangulation[j][2]]
104 C = listPoints[triangulation[j][3]]
105 center, radius = circoncircle(A,B,C)
106 CP = Vector(center,point)
107 if(VectorNorm(CP)<radius) then -- the point belongs to the circoncirle
108 table.insert(badTriangles,j)
114 -- construction of the cavity composed by the bad triangles around the point to add
115 function buildCavity(badTriangles, triangulation)
117 for j=1,#badTriangles do -- for all bad triangles
118 ind = badTriangles[j]
119 for k=1,3 do -- for all edges
120 edge = {triangulation[ind][k],triangulation[ind][k%3+1]}
122 for l = 1,#badTriangles do -- for all badtriangles
123 badInd = badTriangles[l]
124 if(badInd ~= ind) then -- if not the current one
125 edgeBord = edgeBord or edgeInTriangle(edge,triangulation[badInd])
128 -- if the edge does not belong to another bad triangle
129 if(edgeBord == false) then
130 -- insert the edge to the cavity
131 table.insert(polygon,edge)
138 function edgeInTriangle(e,t)
153 function pointInTriangle(e,t)
165 local out = {x = B.x - A.x, y = B.y - A.y}
169 function VectorNorm(NP)
170 return math.sqrt(NP.x*NP.x +NP.y*NP.y)
174 function circoncircle(M, N, P)
175 -- Compute center and radius of the circoncircle of the triangle M N P
177 -- return : (center [Point],radius [float])
179 local MN = Vector(M,N)
180 local NP = Vector(N,P)
181 local PM = Vector(P,M)
182 m = VectorNorm(NP) -- |NP|
183 n = VectorNorm(PM) -- |PM|
184 p = VectorNorm(MN) -- |MN|
186 d = (m + n + p) * (-m + n + p) * (m - n + p) * (m + n - p)
188 rad = m * n * p / math.sqrt(d)
192 d = -2 * (M.x * NP.y + N.x * PM.y + P.x * MN.y)
197 om2 = math.pow(VectorNorm(OM),2) -- |OM|**2
198 on2 = math.pow(VectorNorm(ON),2) -- |ON|**2
199 op2 = math.pow(VectorNorm(OP),2) -- |OP|**2
200 x0 = -(om2 * NP.y + on2 * PM.y + op2 * MN.y) / d
201 y0 = (om2 * NP.x + on2 * PM.x + op2 * MN.x) / d
207 return Out, rad -- (center [Point], R [float])
210 -- compute the list of the circumcircle of a triangulation
211 function listCircumCenter(listPoints,triangulation)
213 for j=1,#triangulation do
214 A = listPoints[triangulation[j][1]]
215 B = listPoints[triangulation[j][2]]
216 C = listPoints[triangulation[j][3]]
217 center, radius = circoncircle(A,B,C)
218 table.insert(list,{x=center.x,y=center.y,r=radius})
223 -- find the three neighbour triangles of T
224 function findNeighbour(T,i,triangulation)
226 -- i : index of T in triangualation
230 -- define the three edge
234 for j=1,#triangulation do
236 if(edgeInTriangle(e1,triangulation[j])) then
239 if(edgeInTriangle(e2,triangulation[j])) then
242 if(edgeInTriangle(e3,triangulation[j])) then
250 -- test if edge are the same (reverse)
251 function equalEdge(e1,e2)
252 if(((e1[1] == e2[1]) and (e1[2] == e2[2])) or ((e1[1] == e2[2]) and (e1[2] == e2[1]))) then
259 -- test if the edge belongs to the list
260 function edgeInList(e,listE)
263 if(equalEdge(e,listE[i])) then
270 -- build the edges of the Voronoi diagram with a given triangulation
271 function buildVoronoi(listPoints, triangulation)
272 listCircumCircle = listCircumCenter(listPoints, triangulation)
274 for i=1,#listCircumCircle do
275 listN = findNeighbour(triangulation[i],i,triangulation)
278 if( not edgeInList(edge, listVoronoi)) then
279 table.insert(listVoronoi, edge)
286 -------------------------- TeX
287 -- build the list of points
288 function buildList(chaine, mode)
289 -- if mode = int : the list is given in the chaine string (x1,y1);(x2,y2);...;(xn,yn)
290 -- if mode = ext : the list is given in a file line by line with space separation
292 if mode == "int" then
293 local points = string.explode(chaine, ";")
296 Sx,Sy=string.match(points[i],"%((.+),(.+)%)")
297 listPoints[i]={x=tonumber(Sx),y=tonumber(Sy)}
299 elseif mode == "ext" then
300 io.input(chaine) -- open the file
302 lines=string.explode(text,"\n+") -- all the lines
305 xy=string.explode(lines[i]," +")
306 listPoints[i]={x=tonumber(xy[1]),y=tonumber(xy[2])}
309 print("Non existing mode")
316 function rectangleList(a,b,nbrA,nbrB)
323 listPoints[k] = {x = (i-1)*stepA, y=(j-1)*stepB}
331 -- trace Voronoi with MP
332 function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri)
333 listCircumC = listCircumCenter(listPoints,triangulation)
335 output = output .. " pair MeshPoints[];"
336 for i=1,#listPoints do
337 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
339 output = output .. " pair CircumCenters[];"
340 for i=1,#listCircumC do
341 output = output .. "CircumCenters[".. i .. "] = (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ")*u;"
344 for i=1,#triangulation do
345 PointI = listPoints[triangulation[i][1]]
346 PointJ = listPoints[triangulation[i][2]]
347 PointK = listPoints[triangulation[i][3]]
348 if(triangulation[i].type == "bbox") then
349 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
351 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
355 for i=1,#listVoronoi do
356 PointI = listCircumC[listVoronoi[i][1]]
357 PointJ = listCircumC[listVoronoi[i][2]]
358 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u withcolor \\luameshmpcolorVoronoi;"
360 if(points=="points") then
362 for i=1,#listPoints do
363 if(listPoints[i].type == "bbox") then
364 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
367 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
370 for i=1,#listCircumC do
371 output = output .. "dotlabel.llft (btex $\\CircumPoint_{" .. i .. "}$ etex, (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u ) withcolor \\luameshmpcolorVoronoi ;"
375 for i=1,#listPoints do
376 if(listPoints[i].type == "bbox") then
377 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
380 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
383 for i=1,#listCircumC do
384 output = output .. "drawdot (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u withcolor \\luameshmpcolorVoronoi withpen pencircle scaled 3;"
392 -- trace Voronoi with TikZ
393 function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi)
394 listCircumC = listCircumCenter(listPoints,triangulation)
396 for i=1,#listPoints do
397 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
399 for i=1,#listCircumC do
400 output = output .. "\\coordinate (CircumPoints".. i .. ") at (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ");"
403 for i=1,#triangulation do
404 PointI = listPoints[triangulation[i][1]]
405 PointJ = listPoints[triangulation[i][2]]
406 PointK = listPoints[triangulation[i][3]]
407 if(triangulation[i].type == "bbox") then
408 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
410 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
414 for i=1,#listVoronoi do
415 PointI = listCircumC[listVoronoi[i][1]]
416 PointJ = listCircumC[listVoronoi[i][2]]
417 output = output .. "\\draw[color="..colorVoronoi.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..");"
419 if(points=="points") then
421 for i=1,#listPoints do
422 if(listPoints[i].type == "bbox") then
423 if(listPoints[i].type == "bbox") then
424 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
427 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
431 for i=1,#listCircumC do
432 output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\CircumPoint_{" .. i .. "}$};"
436 for i=1,#listPoints do
437 if(listPoints[i].type == "bbox") then
438 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
441 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
444 for i=1,#listCircumC do
445 output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$};"
453 -- buildVoronoi with MP
454 function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri)
455 listPoints = buildList(chaine, mode)
456 triangulation = BowyerWatson(listPoints,bbox)
457 listVoronoi = buildVoronoi(listPoints, triangulation)
458 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
459 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
464 -- buildVoronoi with TikZ
465 function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi)
466 listPoints = buildList(chaine, mode)
467 triangulation = BowyerWatson(listPoints,bbox)
468 listVoronoi = buildVoronoi(listPoints, triangulation)
469 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi)
470 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
474 -- buildVoronoi with MP
475 function buildVoronoiMPBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri)
476 listPoints = buildList(chaine, mode)
477 triangulation = BowyerWatson(listPoints,bbox)
478 listVoronoi = buildVoronoi(listPoints, triangulation)
479 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
480 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
485 -- buildVoronoi with TikZ
486 function buildVoronoiTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi)
487 listPoints = buildList(chaine, mode)
488 triangulation = BowyerWatson(listPoints,bbox)
489 listVoronoi = buildVoronoi(listPoints, triangulation)
490 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi)
491 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
497 -- trace a triangulation with TikZ
498 function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
500 for i=1,#listPoints do
501 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
503 for i=1,#triangulation do
504 PointI = listPoints[triangulation[i][1]]
505 PointJ = listPoints[triangulation[i][2]]
506 PointK = listPoints[triangulation[i][3]]
507 if(triangulation[i].type == "bbox") then
508 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
510 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
513 if(points=="points") then
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 .. "}$};"
528 -- trace a triangulation with MP
529 function traceMeshMP(listPoints, triangulation,points)
531 output = output .. " pair MeshPoints[];"
532 for i=1,#listPoints do
533 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
535 for i=1,#triangulation do
536 PointI = listPoints[triangulation[i][1]]
537 PointJ = listPoints[triangulation[i][2]]
538 PointK = listPoints[triangulation[i][3]]
539 if(triangulation[i].type == "bbox") then
540 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
542 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
545 if(points=="points") then
547 for i=1,#listPoints do
548 if(listPoints[i].type == "bbox") then
549 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
552 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
561 function buildMeshMPBW(chaine,mode,points,bbox,scale)
562 listPoints = buildList(chaine, mode)
563 triangulation = BowyerWatson(listPoints,bbox)
564 output = traceMeshMP(listPoints, triangulation,points)
565 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
569 -- buildMesh with MP include code
570 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
571 listPoints = buildList(chaine, mode)
572 triangulation = BowyerWatson(listPoints,bbox)
573 output = traceMeshMP(listPoints, triangulation,points)
574 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
578 -- buildMesh with TikZ
579 function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
580 listPoints = buildList(chaine, mode)
581 triangulation = BowyerWatson(listPoints,bbox)
582 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
583 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
587 -- buildMesh with TikZ
588 function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
589 listPoints = buildList(chaine, mode)
590 triangulation = BowyerWatson(listPoints,bbox)
591 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
592 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
597 -- print points of the mesh
598 function tracePointsMP(listPoints,points)
600 output = output .. " pair MeshPoints[];"
601 for i=1,#listPoints do
602 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
604 if(points=="points") then
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 ;"
615 for i=1,#listPoints do
616 if(listPoints[i].type == "bbox") then
617 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
619 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
626 -- print points of the mesh
627 function tracePointsTikZ(listPoints,points,color,colorBbox)
629 for i=1,#listPoints do
630 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
632 if(points=="points") then
634 for i=1,#listPoints do
635 if(listPoints[i].type == "bbox") then
636 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
639 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
643 for i=1,#listPoints do
644 if(listPoints[i].type == "bbox") then
645 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
647 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
654 -- print points to mesh
655 function printPointsMP(chaine,mode,points,bbox,scale)
656 listPoints = buildList(chaine, mode)
657 if(bbox == "bbox" ) then
658 listPoints = buildBoundingBox(listPoints)
660 output = tracePointsMP(listPoints,points)
661 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
666 -- print points to mesh
667 function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
668 listPoints = buildList(chaine, mode)
669 if(bbox == "bbox" ) then
670 listPoints = buildBoundingBox(listPoints)
672 output = tracePointsMP(listPoints,points)
673 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
677 -- print points to mesh
678 function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
679 listPoints = buildList(chaine, mode)
680 if(bbox == "bbox" ) then
681 listPoints = buildBoundingBox(listPoints)
683 output = tracePointsTikZ(listPoints,points,color,colorBbox)
684 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
689 -- print points to mesh
690 function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
691 listPoints = buildList(chaine, mode)
692 if(bbox == "bbox" ) then
693 listPoints = buildBoundingBox(listPoints)
695 output = tracePointsTikZ(listPoints,points,color,colorBbox)
696 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
702 function buildRect(largeur,a,b,nbrA, nbrB)
703 listPoints = rectangleList(a,b,nbrA,nbrB)
704 triangulation = BowyerWatson(listPoints,"none")
705 traceTikZ(listPoints, triangulation,largeur,"none")
708 local function shallowCopy(original)
710 for key, value in pairs(original) do
716 -- function give a real polygon without repeting points
717 function cleanPoly(polygon)
719 polyCopy = shallowCopy(polygon)
722 table.insert(polyNew, e1)
723 table.insert(polyNew, e2)
724 table.remove(polyCopy,1)
729 while (i<=#polyCopy and find==false) do
730 bool1 = (polyCopy[i][1] == polyNew[j])
731 bool2 = (polyCopy[i][2] == polyNew[j])
732 if(bool1 or bool2) then -- the edge has a common point with polyNew[j]
734 table.insert(polyNew, polyCopy[i][1])
736 table.remove(polyCopy,i)
738 elseif(not bool2) then
739 table.insert(polyNew, polyCopy[i][2])
741 table.remove(polyCopy,i)
752 function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
754 -- build the triangulation
755 triangulation = BowyerWatson(listPoints,bbox)
756 badTriangles = buildBadTriangles(P,triangulation)
757 for i=1,#listPoints do
758 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
760 if(step == "badT") then
762 for i=1,#triangulation do
763 PointI = listPoints[triangulation[i][1]]
764 PointJ = listPoints[triangulation[i][2]]
765 PointK = listPoints[triangulation[i][3]]
766 if(triangulation[i].type == "bbox") then
767 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
769 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
772 -- draw and fill the bad triangle
773 for i=1,#badTriangles do
774 PointI = listPoints[triangulation[badTriangles[i]][1]]
775 PointJ = listPoints[triangulation[badTriangles[i]][2]]
776 PointK = listPoints[triangulation[badTriangles[i]][3]]
777 output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
779 -- draw the circoncircle
780 for i=1,#badTriangles do
781 PointI = listPoints[triangulation[badTriangles[i]][1]]
782 PointJ = listPoints[triangulation[badTriangles[i]][2]]
783 PointK = listPoints[triangulation[badTriangles[i]][3]]
784 center, radius = circoncircle(PointI, PointJ, PointK)
785 output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
789 for i=1,#listPoints do
790 if(listPoints[i].type == "bbox") then
791 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
794 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
797 -- mark the point to add
798 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
799 elseif(step == "cavity") then
800 polygon = buildCavity(badTriangles, triangulation)
801 polyNew = cleanPoly(polygon)
802 -- remove the bad triangles
803 for j=1,#badTriangles do
804 table.remove(triangulation,badTriangles[j]-(j-1))
806 -- draw the triangles
807 for i=1,#triangulation do
808 PointI = listPoints[triangulation[i][1]]
809 PointJ = listPoints[triangulation[i][2]]
810 PointK = listPoints[triangulation[i][3]]
811 if(triangulation[i].type == "bbox") then
812 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
814 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
817 -- fill and draw the cavity
820 PointI = listPoints[polyNew[i]]
821 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
823 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
824 -- mark the points of the mesh
826 for i=1,#listPoints do
827 if(listPoints[i].type == "bbox") then
828 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
831 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
834 -- mark the adding point
835 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
836 elseif(step == "newT") then
837 polygon = buildCavity(badTriangles, triangulation)
838 polyNew = cleanPoly(polygon)
839 -- remove the bad triangles
840 for j=1,#badTriangles do
841 table.remove(triangulation,badTriangles[j]-(j-1))
843 -- draw the triangle of the triangulation
844 for i=1,#triangulation do
845 PointI = listPoints[triangulation[i][1]]
846 PointJ = listPoints[triangulation[i][2]]
847 PointK = listPoints[triangulation[i][3]]
848 if(triangulation[i].type == "bbox") then
849 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
851 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
854 -- fill and draw the cavity
857 PointI = listPoints[polyNew[i]]
858 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
860 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
861 -- draw the new triangles composed by the edges of the polygon and the added point
863 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 ..");"
864 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
865 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
869 for i=1,#listPoints do
870 if(listPoints[i].type == "bbox") then
871 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
874 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
877 -- mark the added point
878 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
883 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
885 output = output .. "pair MeshPoints[];"
886 -- build the triangulation
887 triangulation = BowyerWatson(listPoints,bbox)
888 badTriangles = buildBadTriangles(P,triangulation)
889 for i=1,#listPoints do
890 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
892 if(step == "badT") then
894 for i=1,#triangulation do
895 PointI = listPoints[triangulation[i][1]]
896 PointJ = listPoints[triangulation[i][2]]
897 PointK = listPoints[triangulation[i][3]]
898 if(triangulation[i].type == "bbox") then
899 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
901 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
904 -- draw and fill the bad triangle
905 for i=1,#badTriangles do
906 PointI = listPoints[triangulation[badTriangles[i]][1]]
907 PointJ = listPoints[triangulation[badTriangles[i]][2]]
908 PointK = listPoints[triangulation[badTriangles[i]][3]]
909 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
910 output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
912 -- draw the circoncircle
913 for i=1,#badTriangles do
914 PointI = listPoints[triangulation[badTriangles[i]][1]]
915 PointJ = listPoints[triangulation[badTriangles[i]][2]]
916 PointK = listPoints[triangulation[badTriangles[i]][3]]
917 center, radius = circoncircle(PointI, PointJ, PointK)
918 output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
922 for i=1,#listPoints do
923 if(listPoints[i].type == "bbox") then
924 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
927 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
930 -- mark the point to add
931 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
932 elseif(step == "cavity") then
933 polygon = buildCavity(badTriangles, triangulation)
934 polyNew = cleanPoly(polygon)
935 -- remove the bad triangles
936 for j=1,#badTriangles do
937 table.remove(triangulation,badTriangles[j]-(j-1))
939 -- draw the triangles
940 for i=1,#triangulation do
941 PointI = listPoints[triangulation[i][1]]
942 PointJ = listPoints[triangulation[i][2]]
943 PointK = listPoints[triangulation[i][3]]
944 if(triangulation[i].type == "bbox") then
945 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
947 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
950 -- fill and draw the cavity
953 PointI = listPoints[polyNew[i]]
954 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
956 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
957 output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
958 -- mark the points of the mesh
960 for i=1,#listPoints do
961 if(listPoints[i].type == "bbox") then
962 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
965 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
968 -- mark the adding point
969 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
970 elseif(step == "newT") then
971 polygon = buildCavity(badTriangles, triangulation)
972 polyNew = cleanPoly(polygon)
973 -- remove the bad triangles
974 for j=1,#badTriangles do
975 table.remove(triangulation,badTriangles[j]-(j-1))
977 -- draw the triangle of the triangulation
978 for i=1,#triangulation do
979 PointI = listPoints[triangulation[i][1]]
980 PointJ = listPoints[triangulation[i][2]]
981 PointK = listPoints[triangulation[i][3]]
982 if(triangulation[i].type == "bbox") then
983 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
985 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
991 PointI = listPoints[polyNew[i]]
992 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
994 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
995 -- draw the new triangles composed by the edges of the polygon and the added point
997 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;"
998 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;"
999 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;"
1003 for i=1,#listPoints do
1004 if(listPoints[i].type == "bbox") then
1005 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
1008 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
1011 -- mark the added point
1012 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
1018 -- build the list of points extern and stop at nbr
1019 function buildListExt(chaine, stop)
1021 io.input(chaine) -- open the file
1022 text=io.read("*all")
1023 lines=string.explode(text,"\n+") -- all the lines
1024 for i=1,tonumber(stop) do
1025 xy=string.explode(lines[i]," +")
1026 table.insert(listPoints,{x=tonumber(xy[1]),y=tonumber(xy[2])})
1028 xy=string.explode(lines[stop+1]," +")
1029 point={x=tonumber(xy[1]),y=tonumber(xy[2])}
1030 return point, listPoints
1034 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1035 if(mode=="int") then
1036 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1038 listPoints = buildList(chaine, mode)
1040 -- point is a number
1041 P, listPoints = buildListExt(chaine,tonumber(point))
1043 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1044 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
1048 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1049 if(mode=="int") then
1050 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1052 listPoints = buildList(chaine, mode)
1054 -- point is a number
1055 P, listPoints = buildListExt(chaine,tonumber(point))
1057 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1058 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
1062 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
1063 if(mode=="int") then
1064 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1066 listPoints = buildList(chaine, mode)
1068 -- point is a number
1069 P, listPoints = buildListExt(chaine,tonumber(point))
1071 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
1072 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
1076 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
1077 if(mode=="int") then
1078 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1080 listPoints = buildList(chaine, mode)
1082 -- point is a number
1083 P, listPoints = buildListExt(chaine,tonumber(point))
1085 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
1086 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1091 function split(pString, pPattern)
1092 local Table = {} -- NOTE: use {n = 0} in Lua-5.0
1093 local fpat = "(.-)" .. pPattern
1095 local s, e, cap = pString:find(fpat, 1)
1097 if s ~= 1 or cap ~= "" then
1098 table.insert(Table,cap)
1101 s, e, cap = pString:find(fpat, last_end)
1103 if last_end <= #pString then
1104 cap = pString:sub(last_end)
1105 table.insert(Table, cap)
1110 function readGmsh(file)
1111 io.input(file) -- open the file
1112 text=io.read("*all")
1113 local lines = split(text,"\n+") -- all the lines
1118 boolElements = false
1122 if(lines[i+J] == "$EndNodes") then
1124 -- go to the next line
1126 if(boolNodes) then -- we are in the Nodes environment
1127 xy=split(lines[i+J]," +")
1128 table.insert(listPoints,{x=tonumber(xy[2]),y=tonumber(xy[3])})
1130 if(lines[i+J] == "$Nodes") then
1132 -- go to the next line
1135 if(lines[i+J] == "$EndElements") then
1136 boolElements = false
1137 -- go to the next line
1139 if(boolElements) then -- we are in the Nodes environment
1140 xy=split(lines[i+J]," +")
1141 if(tonumber(xy[2]) == 2) then -- if the element is a triangle
1143 table.insert(triangulation,{tonumber(xy[2+nbrTags+1]),tonumber(xy[2+nbrTags+2]),tonumber(xy[2+nbrTags+3])})
1146 if(lines[i+J] == "$Elements") then
1148 -- go to the next line
1152 return listPoints, triangulation
1155 function drawGmshMP(file,points,scale)
1156 listPoints,triangulation = readGmsh(file)
1157 output = traceMeshMP(listPoints,triangulation,points)
1158 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
1162 function drawGmshMPinc(file,beginning,ending,points,scale)
1163 listPoints,triangulation = readGmsh(file)
1164 output = traceMeshMP(listPoints,triangulation,points)
1165 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1172 function drawGmshTikZ(file,points,scale,color)
1173 listPoints,triangulation = readGmsh(file)
1174 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
1175 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
1180 function drawGmshTikZinc(file,beginning, ending,points,scale,color)
1181 listPoints,triangulation = readGmsh(file)
1182 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
1183 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
1188 -- buildVoronoi with MP
1189 function buildGmshVoronoiMP(file,points,scale,tri)
1190 listPoints,triangulation = readGmsh(file)
1191 listVoronoi = buildVoronoi(listPoints, triangulation)
1192 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
1193 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
1198 -- buildVoronoi with TikZ
1199 function buildGmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi)
1200 listPoints,triangulation = readGmsh(file)
1201 listVoronoi = buildVoronoi(listPoints, triangulation)
1202 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi)
1203 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
1207 -- buildVoronoi with MP
1208 function buildGmshVoronoiMPinc(file,beginning, ending,points,scale,tri)
1209 listPoints,triangulation = readGmsh(file)
1210 listVoronoi = buildVoronoi(listPoints, triangulation)
1211 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
1212 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1217 -- buildVoronoi with TikZ
1218 function buildGmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi)
1219 listPoints,triangulation = readGmsh(file)
1220 listVoronoi = buildVoronoi(listPoints, triangulation)
1221 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi)
1222 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"