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 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
426 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
429 for i=1,#listCircumC do
430 output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\CircumPoint_{" .. i .. "}$};"
434 for i=1,#listPoints do
435 if(listPoints[i].type == "bbox") then
436 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
439 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
442 for i=1,#listCircumC do
443 output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$};"
451 -- buildVoronoi with MP
452 function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri)
453 listPoints = buildList(chaine, mode)
454 triangulation = BowyerWatson(listPoints,bbox)
455 listVoronoi = buildVoronoi(listPoints, triangulation)
456 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
457 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
462 -- buildVoronoi with TikZ
463 function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi)
464 listPoints = buildList(chaine, mode)
465 triangulation = BowyerWatson(listPoints,bbox)
466 listVoronoi = buildVoronoi(listPoints, triangulation)
467 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi)
468 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
472 -- buildVoronoi with MP
473 function buildVoronoiMPBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri)
474 listPoints = buildList(chaine, mode)
475 triangulation = BowyerWatson(listPoints,bbox)
476 listVoronoi = buildVoronoi(listPoints, triangulation)
477 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
478 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
483 -- buildVoronoi with TikZ
484 function buildVoronoiTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi)
485 listPoints = buildList(chaine, mode)
486 triangulation = BowyerWatson(listPoints,bbox)
487 listVoronoi = buildVoronoi(listPoints, triangulation)
488 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi)
489 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
495 -- trace a triangulation with TikZ
496 function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
498 for i=1,#listPoints do
499 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
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 if(points=="points") then
513 for i=1,#listPoints do
514 if(listPoints[i].type == "bbox") then
515 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
518 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
526 -- trace a triangulation with MP
527 function traceMeshMP(listPoints, triangulation,points)
529 output = output .. " pair MeshPoints[];"
530 for i=1,#listPoints do
531 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
533 for i=1,#triangulation do
534 PointI = listPoints[triangulation[i][1]]
535 PointJ = listPoints[triangulation[i][2]]
536 PointK = listPoints[triangulation[i][3]]
537 if(triangulation[i].type == "bbox") then
538 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
540 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
543 if(points=="points") then
545 for i=1,#listPoints do
546 if(listPoints[i].type == "bbox") then
547 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
550 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
559 function buildMeshMPBW(chaine,mode,points,bbox,scale)
560 listPoints = buildList(chaine, mode)
561 triangulation = BowyerWatson(listPoints,bbox)
562 output = traceMeshMP(listPoints, triangulation,points)
563 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
567 -- buildMesh with MP include code
568 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
569 listPoints = buildList(chaine, mode)
570 triangulation = BowyerWatson(listPoints,bbox)
571 output = traceMeshMP(listPoints, triangulation,points)
572 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
576 -- buildMesh with TikZ
577 function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
578 listPoints = buildList(chaine, mode)
579 triangulation = BowyerWatson(listPoints,bbox)
580 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
581 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
585 -- buildMesh with TikZ
586 function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
587 listPoints = buildList(chaine, mode)
588 triangulation = BowyerWatson(listPoints,bbox)
589 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
590 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
595 -- print points of the mesh
596 function tracePointsMP(listPoints,points)
598 output = output .. " pair MeshPoints[];"
599 for i=1,#listPoints do
600 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
602 if(points=="points") then
604 for i=1,#listPoints do
605 if(listPoints[i].type == "bbox") then
606 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
609 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
613 for i=1,#listPoints do
614 if(listPoints[i].type == "bbox") then
615 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
617 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
624 -- print points of the mesh
625 function tracePointsTikZ(listPoints,points,color,colorBbox)
627 for i=1,#listPoints do
628 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
630 if(points=="points") then
632 for i=1,#listPoints do
633 if(listPoints[i].type == "bbox") then
634 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
637 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
641 for i=1,#listPoints do
642 if(listPoints[i].type == "bbox") then
643 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
645 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
652 -- print points to mesh
653 function printPointsMP(chaine,mode,points,bbox,scale)
654 listPoints = buildList(chaine, mode)
655 if(bbox == "bbox" ) then
656 listPoints = buildBoundingBox(listPoints)
658 output = tracePointsMP(listPoints,points)
659 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
664 -- print points to mesh
665 function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
666 listPoints = buildList(chaine, mode)
667 if(bbox == "bbox" ) then
668 listPoints = buildBoundingBox(listPoints)
670 output = tracePointsMP(listPoints,points)
671 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
675 -- print points to mesh
676 function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
677 listPoints = buildList(chaine, mode)
678 if(bbox == "bbox" ) then
679 listPoints = buildBoundingBox(listPoints)
681 output = tracePointsTikZ(listPoints,points,color,colorBbox)
682 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
687 -- print points to mesh
688 function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
689 listPoints = buildList(chaine, mode)
690 if(bbox == "bbox" ) then
691 listPoints = buildBoundingBox(listPoints)
693 output = tracePointsTikZ(listPoints,points,color,colorBbox)
694 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
700 function buildRect(largeur,a,b,nbrA, nbrB)
701 listPoints = rectangleList(a,b,nbrA,nbrB)
702 triangulation = BowyerWatson(listPoints,"none")
703 traceTikZ(listPoints, triangulation,largeur,"none")
706 local function shallowCopy(original)
708 for key, value in pairs(original) do
714 -- function give a real polygon without repeting points
715 function cleanPoly(polygon)
717 polyCopy = shallowCopy(polygon)
720 table.insert(polyNew, e1)
721 table.insert(polyNew, e2)
722 table.remove(polyCopy,1)
727 while (i<=#polyCopy and find==false) do
728 bool1 = (polyCopy[i][1] == polyNew[j])
729 bool2 = (polyCopy[i][2] == polyNew[j])
730 if(bool1 or bool2) then -- the edge has a common point with polyNew[j]
732 table.insert(polyNew, polyCopy[i][1])
734 table.remove(polyCopy,i)
736 elseif(not bool2) then
737 table.insert(polyNew, polyCopy[i][2])
739 table.remove(polyCopy,i)
750 function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
752 -- build the triangulation
753 triangulation = BowyerWatson(listPoints,bbox)
754 badTriangles = buildBadTriangles(P,triangulation)
755 for i=1,#listPoints do
756 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
758 if(step == "badT") then
760 for i=1,#triangulation do
761 PointI = listPoints[triangulation[i][1]]
762 PointJ = listPoints[triangulation[i][2]]
763 PointK = listPoints[triangulation[i][3]]
764 if(triangulation[i].type == "bbox") then
765 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
767 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
770 -- draw and fill the bad triangle
771 for i=1,#badTriangles do
772 PointI = listPoints[triangulation[badTriangles[i]][1]]
773 PointJ = listPoints[triangulation[badTriangles[i]][2]]
774 PointK = listPoints[triangulation[badTriangles[i]][3]]
775 output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
777 -- draw the circoncircle
778 for i=1,#badTriangles do
779 PointI = listPoints[triangulation[badTriangles[i]][1]]
780 PointJ = listPoints[triangulation[badTriangles[i]][2]]
781 PointK = listPoints[triangulation[badTriangles[i]][3]]
782 center, radius = circoncircle(PointI, PointJ, PointK)
783 output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
787 for i=1,#listPoints do
788 if(listPoints[i].type == "bbox") then
789 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
792 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
795 -- mark the point to add
796 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
797 elseif(step == "cavity") then
798 polygon = buildCavity(badTriangles, triangulation)
799 polyNew = cleanPoly(polygon)
800 -- remove the bad triangles
801 for j=1,#badTriangles do
802 table.remove(triangulation,badTriangles[j]-(j-1))
804 -- draw the triangles
805 for i=1,#triangulation do
806 PointI = listPoints[triangulation[i][1]]
807 PointJ = listPoints[triangulation[i][2]]
808 PointK = listPoints[triangulation[i][3]]
809 if(triangulation[i].type == "bbox") then
810 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
812 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
815 -- fill and draw the cavity
818 PointI = listPoints[polyNew[i]]
819 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
821 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
822 -- mark the points of the mesh
824 for i=1,#listPoints do
825 if(listPoints[i].type == "bbox") then
826 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
829 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
832 -- mark the adding point
833 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
834 elseif(step == "newT") then
835 polygon = buildCavity(badTriangles, triangulation)
836 polyNew = cleanPoly(polygon)
837 -- remove the bad triangles
838 for j=1,#badTriangles do
839 table.remove(triangulation,badTriangles[j]-(j-1))
841 -- draw the triangle of the triangulation
842 for i=1,#triangulation do
843 PointI = listPoints[triangulation[i][1]]
844 PointJ = listPoints[triangulation[i][2]]
845 PointK = listPoints[triangulation[i][3]]
846 if(triangulation[i].type == "bbox") then
847 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
849 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
852 -- fill and draw the cavity
855 PointI = listPoints[polyNew[i]]
856 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
858 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
859 -- draw the new triangles composed by the edges of the polygon and the added point
861 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 ..");"
862 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
863 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
867 for i=1,#listPoints do
868 if(listPoints[i].type == "bbox") then
869 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
872 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
875 -- mark the added point
876 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
881 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
883 output = output .. "pair MeshPoints[];"
884 -- build the triangulation
885 triangulation = BowyerWatson(listPoints,bbox)
886 badTriangles = buildBadTriangles(P,triangulation)
887 for i=1,#listPoints do
888 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
890 if(step == "badT") then
892 for i=1,#triangulation do
893 PointI = listPoints[triangulation[i][1]]
894 PointJ = listPoints[triangulation[i][2]]
895 PointK = listPoints[triangulation[i][3]]
896 if(triangulation[i].type == "bbox") then
897 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
899 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
902 -- draw and fill the bad triangle
903 for i=1,#badTriangles do
904 PointI = listPoints[triangulation[badTriangles[i]][1]]
905 PointJ = listPoints[triangulation[badTriangles[i]][2]]
906 PointK = listPoints[triangulation[badTriangles[i]][3]]
907 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
908 output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
910 -- draw the circoncircle
911 for i=1,#badTriangles do
912 PointI = listPoints[triangulation[badTriangles[i]][1]]
913 PointJ = listPoints[triangulation[badTriangles[i]][2]]
914 PointK = listPoints[triangulation[badTriangles[i]][3]]
915 center, radius = circoncircle(PointI, PointJ, PointK)
916 output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
920 for i=1,#listPoints do
921 if(listPoints[i].type == "bbox") then
922 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
925 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
928 -- mark the point to add
929 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
930 elseif(step == "cavity") then
931 polygon = buildCavity(badTriangles, triangulation)
932 polyNew = cleanPoly(polygon)
933 -- remove the bad triangles
934 for j=1,#badTriangles do
935 table.remove(triangulation,badTriangles[j]-(j-1))
937 -- draw the triangles
938 for i=1,#triangulation do
939 PointI = listPoints[triangulation[i][1]]
940 PointJ = listPoints[triangulation[i][2]]
941 PointK = listPoints[triangulation[i][3]]
942 if(triangulation[i].type == "bbox") then
943 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
945 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
948 -- fill and draw the cavity
951 PointI = listPoints[polyNew[i]]
952 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
954 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
955 output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
956 -- mark the points of the mesh
958 for i=1,#listPoints do
959 if(listPoints[i].type == "bbox") then
960 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
963 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
966 -- mark the adding point
967 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
968 elseif(step == "newT") then
969 polygon = buildCavity(badTriangles, triangulation)
970 polyNew = cleanPoly(polygon)
971 -- remove the bad triangles
972 for j=1,#badTriangles do
973 table.remove(triangulation,badTriangles[j]-(j-1))
975 -- draw the triangle of the triangulation
976 for i=1,#triangulation do
977 PointI = listPoints[triangulation[i][1]]
978 PointJ = listPoints[triangulation[i][2]]
979 PointK = listPoints[triangulation[i][3]]
980 if(triangulation[i].type == "bbox") then
981 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
983 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
989 PointI = listPoints[polyNew[i]]
990 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
992 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
993 -- draw the new triangles composed by the edges of the polygon and the added point
995 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;"
996 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;"
997 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;"
1001 for i=1,#listPoints do
1002 if(listPoints[i].type == "bbox") then
1003 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
1006 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
1009 -- mark the added point
1010 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
1016 -- build the list of points extern and stop at nbr
1017 function buildListExt(chaine, stop)
1019 io.input(chaine) -- open the file
1020 text=io.read("*all")
1021 lines=string.explode(text,"\n+") -- all the lines
1022 for i=1,tonumber(stop) do
1023 xy=string.explode(lines[i]," +")
1024 table.insert(listPoints,{x=tonumber(xy[1]),y=tonumber(xy[2])})
1026 xy=string.explode(lines[stop+1]," +")
1027 point={x=tonumber(xy[1]),y=tonumber(xy[2])}
1028 return point, listPoints
1032 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1033 if(mode=="int") then
1034 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1036 listPoints = buildList(chaine, mode)
1038 -- point is a number
1039 P, listPoints = buildListExt(chaine,tonumber(point))
1041 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1042 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
1046 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1047 if(mode=="int") then
1048 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1050 listPoints = buildList(chaine, mode)
1052 -- point is a number
1053 P, listPoints = buildListExt(chaine,tonumber(point))
1055 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1056 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
1060 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
1061 if(mode=="int") then
1062 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1064 listPoints = buildList(chaine, mode)
1066 -- point is a number
1067 P, listPoints = buildListExt(chaine,tonumber(point))
1069 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
1070 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
1074 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
1075 if(mode=="int") then
1076 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1078 listPoints = buildList(chaine, mode)
1080 -- point is a number
1081 P, listPoints = buildListExt(chaine,tonumber(point))
1083 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
1084 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1089 function split(pString, pPattern)
1090 local Table = {} -- NOTE: use {n = 0} in Lua-5.0
1091 local fpat = "(.-)" .. pPattern
1093 local s, e, cap = pString:find(fpat, 1)
1095 if s ~= 1 or cap ~= "" then
1096 table.insert(Table,cap)
1099 s, e, cap = pString:find(fpat, last_end)
1101 if last_end <= #pString then
1102 cap = pString:sub(last_end)
1103 table.insert(Table, cap)
1108 function readGmsh(file)
1109 io.input(file) -- open the file
1110 text=io.read("*all")
1111 local lines = split(text,"\n+") -- all the lines
1116 boolElements = false
1120 if(lines[i+J] == "$EndNodes") then
1122 -- go to the next line
1124 if(boolNodes) then -- we are in the Nodes environment
1125 xy=split(lines[i+J]," +")
1126 table.insert(listPoints,{x=tonumber(xy[2]),y=tonumber(xy[3])})
1128 if(lines[i+J] == "$Nodes") then
1130 -- go to the next line
1133 if(lines[i+J] == "$EndElements") then
1134 boolElements = false
1135 -- go to the next line
1137 if(boolElements) then -- we are in the Nodes environment
1138 xy=split(lines[i+J]," +")
1139 if(tonumber(xy[2]) == 2) then -- if the element is a triangle
1141 table.insert(triangulation,{tonumber(xy[2+nbrTags+1]),tonumber(xy[2+nbrTags+2]),tonumber(xy[2+nbrTags+3])})
1144 if(lines[i+J] == "$Elements") then
1146 -- go to the next line
1150 return listPoints, triangulation
1153 function drawGmshMP(file,points,scale)
1154 listPoints,triangulation = readGmsh(file)
1155 output = traceMeshMP(listPoints,triangulation,points)
1156 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
1160 function drawGmshMPinc(file,beginning,ending,points,scale)
1161 listPoints,triangulation = readGmsh(file)
1162 output = traceMeshMP(listPoints,triangulation,points)
1163 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1170 function drawGmshTikZ(file,points,scale,color)
1171 listPoints,triangulation = readGmsh(file)
1172 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
1173 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
1178 function drawGmshTikZinc(file,beginning, ending,points,scale,color)
1179 listPoints,triangulation = readGmsh(file)
1180 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
1181 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
1186 -- buildVoronoi with MP
1187 function gmshVoronoiMP(file,points,scale,tri)
1188 listPoints,triangulation = readGmsh(file)
1189 listVoronoi = buildVoronoi(listPoints, triangulation)
1190 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
1191 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
1196 -- buildVoronoi with TikZ
1197 function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi)
1198 listPoints,triangulation = readGmsh(file)
1199 listVoronoi = buildVoronoi(listPoints, triangulation)
1200 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi)
1201 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
1205 -- buildVoronoi with MP
1206 function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri)
1207 listPoints,triangulation = readGmsh(file)
1208 listVoronoi = buildVoronoi(listPoints, triangulation)
1209 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
1210 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1215 -- buildVoronoi with TikZ
1216 function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi)
1217 listPoints,triangulation = readGmsh(file)
1218 listVoronoi = buildVoronoi(listPoints, triangulation)
1219 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi)
1220 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"