1 require "polygon-luamesh"
3 -- Bowyer and Watson algorithm
5 function BowyerWatson (listPoints,bbox)
6 local triangulation = {}
7 local lgth = #listPoints
8 -- add four points to listPoints to have a bounding box
9 listPoints = buildBoundingBox(listPoints)
11 triangulation[1] = {lgth+1, lgth+2, lgth+3,type="bbox"}
12 -- the second triangle
13 triangulation[2] = {lgth+1, lgth+3, lgth+4,type="bbox"}
14 -- add points one by one
16 -- find the triangles which the circumcircle contained the point to add
17 badTriangles = buildBadTriangles(listPoints[i],triangulation)
18 -- build the polygon of the cavity containing the point to add
19 polygon = buildCavity(badTriangles, triangulation)
20 -- remove the bad triangles
21 for j=1,#badTriangles do
22 table.remove(triangulation,badTriangles[j]-(j-1))
24 -- build the new triangles and add them to triangulation
26 if((polygon[j][1]>lgth) or (polygon[j][2]>lgth) or (i>lgth)) then
27 table.insert(triangulation,{polygon[j][1],polygon[j][2],i,type="bbox"})
29 table.insert(triangulation,{polygon[j][1],polygon[j][2],i,type="in"})
32 end -- end adding points of the listPoints
33 -- remove bounding box
34 if(bbox ~= "bbox") then
35 triangulation = removeBoundingBox(triangulation,lgth)
36 table.remove(listPoints,lgth+1)
37 table.remove(listPoints,lgth+1)
38 table.remove(listPoints,lgth+1)
39 table.remove(listPoints,lgth+1)
45 function buildBoundingBox(listPoints)
46 -- listPoints : list of points
47 -- epsV : parameter for the distance of the bounding box
48 local xmin, xmax, ymin, ymax, eps
53 for i=1,#listPoints do
54 if (listPoints[i].x < xmin) then
55 xmin = listPoints[i].x
57 if (listPoints[i].x > xmax) then
58 xmax = listPoints[i].x
60 if (listPoints[i].y < ymin) then
61 ymin = listPoints[i].y
63 if (listPoints[i].y > ymax) then
64 ymax = listPoints[i].y
67 eps = math.max(math.abs(xmax-xmin),math.abs(ymax-ymin))*0.15
72 -- add points of the bounding box in last positions
73 table.insert(listPoints,{x=xmin,y=ymin,type="bbox"})
74 table.insert(listPoints,{x=xmin,y=ymax,type="bbox"})
75 table.insert(listPoints,{x=xmax,y=ymax,type="bbox"})
76 table.insert(listPoints,{x=xmax,y=ymin,type="bbox"})
80 function removeBoundingBox(triangulation,lgth)
81 -- build the four bounding box edge
88 for i=1,#triangulation do
89 boolE1 = pointInTriangle(point1,triangulation[i])
90 boolE2 = pointInTriangle(point2,triangulation[i])
91 boolE3 = pointInTriangle(point3,triangulation[i])
92 boolE4 = pointInTriangle(point4,triangulation[i])
93 if((not boolE1) and (not boolE2) and (not boolE3) and (not boolE4)) then
94 table.insert(newTriangulation,triangulation[i])
97 return newTriangulation
101 function buildBadTriangles(point, triangulation)
103 for j=1,#triangulation do -- for all triangles
104 A = listPoints[triangulation[j][1]]
105 B = listPoints[triangulation[j][2]]
106 C = listPoints[triangulation[j][3]]
107 center, radius = circoncircle(A,B,C)
108 CP = Vector(center,point)
109 if(VectorNorm(CP)<radius) then -- the point belongs to the circoncirle
110 table.insert(badTriangles,j)
116 -- construction of the cavity composed by the bad triangles around the point to add
117 function buildCavity(badTriangles, triangulation)
119 for j=1,#badTriangles do -- for all bad triangles
120 ind = badTriangles[j]
121 for k=1,3 do -- for all edges
122 edge = {triangulation[ind][k],triangulation[ind][k%3+1]}
124 for l = 1,#badTriangles do -- for all badtriangles
125 badInd = badTriangles[l]
126 if(badInd ~= ind) then -- if not the current one
127 edgeBord = edgeBord or edgeInTriangle(edge,triangulation[badInd])
130 -- if the edge does not belong to another bad triangle
131 if(edgeBord == false) then
132 -- insert the edge to the cavity
133 table.insert(polygon,edge)
140 function edgeInTriangle(e,t)
155 function pointInTriangle(e,t)
167 local out = {x = B.x - A.x, y = B.y - A.y}
171 function VectorNorm(NP)
172 return math.sqrt(NP.x*NP.x +NP.y*NP.y)
176 function circoncircle(M, N, P)
177 -- Compute center and radius of the circoncircle of the triangle M N P
179 -- return : (center [Point],radius [float])
181 local MN = Vector(M,N)
182 local NP = Vector(N,P)
183 local PM = Vector(P,M)
184 m = VectorNorm(NP) -- |NP|
185 n = VectorNorm(PM) -- |PM|
186 p = VectorNorm(MN) -- |MN|
188 d = (m + n + p) * (-m + n + p) * (m - n + p) * (m + n - p)
190 rad = m * n * p / math.sqrt(d)
194 d = -2 * (M.x * NP.y + N.x * PM.y + P.x * MN.y)
199 om2 = math.pow(VectorNorm(OM),2) -- |OM|**2
200 on2 = math.pow(VectorNorm(ON),2) -- |ON|**2
201 op2 = math.pow(VectorNorm(OP),2) -- |OP|**2
202 x0 = -(om2 * NP.y + on2 * PM.y + op2 * MN.y) / d
203 y0 = (om2 * NP.x + on2 * PM.x + op2 * MN.x) / d
209 return Out, rad -- (center [Point], R [float])
212 -- compute the list of the circumcircle of a triangulation
213 function listCircumCenter(listPoints,triangulation)
215 for j=1,#triangulation do
216 A = listPoints[triangulation[j][1]]
217 B = listPoints[triangulation[j][2]]
218 C = listPoints[triangulation[j][3]]
219 center, radius = circoncircle(A,B,C)
220 table.insert(list,{x=center.x,y=center.y,r=radius})
225 -- find the three neighbour triangles of T
226 function findNeighbour(T,i,triangulation)
228 -- i : index of T in triangualation
232 -- define the three edge
236 for j=1,#triangulation do
238 if(edgeInTriangle(e1,triangulation[j])) then
241 if(edgeInTriangle(e2,triangulation[j])) then
244 if(edgeInTriangle(e3,triangulation[j])) then
252 -- test if edge are the same (reverse)
253 function equalEdge(e1,e2)
254 if(((e1[1] == e2[1]) and (e1[2] == e2[2])) or ((e1[1] == e2[2]) and (e1[2] == e2[1]))) then
261 -- test if the edge belongs to the list
262 function edgeInList(e,listE)
265 if(equalEdge(e,listE[i])) then
272 -- build the edges of the Voronoi diagram with a given triangulation
273 function buildVoronoi(listPoints, triangulation)
274 listCircumCircle = listCircumCenter(listPoints, triangulation)
276 for i=1,#listCircumCircle do
277 listN = findNeighbour(triangulation[i],i,triangulation)
280 if( not edgeInList(edge, listVoronoi)) then
281 table.insert(listVoronoi, edge)
288 -------------------------- TeX
289 -- build the list of points
290 function buildList(chaine, mode)
291 -- if mode = int : the list is given in the chaine string (x1,y1);(x2,y2);...;(xn,yn)
292 -- if mode = ext : the list is given in a file line by line with space separation
294 if mode == "int" then
295 local points = string.explode(chaine, ";")
298 Sx,Sy=string.match(points[i],"%((.+),(.+)%)")
299 listPoints[i]={x=tonumber(Sx),y=tonumber(Sy)}
301 elseif mode == "ext" then
302 io.input(chaine) -- open the file
304 lines=string.explode(text,"\n+") -- all the lines
307 xy=string.explode(lines[i]," +")
308 listPoints[i]={x=tonumber(xy[1]),y=tonumber(xy[2])}
311 print("Non existing mode")
318 function rectangleList(a,b,nbrA,nbrB)
325 listPoints[k] = {x = (i-1)*stepA, y=(j-1)*stepB}
333 -- trace Voronoi with MP
334 function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri,styleD,styleV)
335 if(styleD == "dashed") then
336 sDelaunay = "dashed evenly"
340 if(styleV == "dashed") then
341 sVoronoi = "dashed evenly"
345 listCircumC = listCircumCenter(listPoints,triangulation)
347 output = output .. " pair MeshPoints[];"
348 for i=1,#listPoints do
349 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
351 output = output .. " pair CircumCenters[];"
352 for i=1,#listCircumC do
353 output = output .. "CircumCenters[".. i .. "] = (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ")*u;"
356 for i=1,#triangulation do
357 PointI = listPoints[triangulation[i][1]]
358 PointJ = listPoints[triangulation[i][2]]
359 PointK = listPoints[triangulation[i][3]]
360 if(triangulation[i].type == "bbox") then
361 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolorBbox;"
363 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolor;"
367 for i=1,#listVoronoi do
368 PointI = listCircumC[listVoronoi[i][1]]
369 PointJ = listCircumC[listVoronoi[i][2]]
370 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u "..sVoronoi.." withcolor \\luameshmpcolorVoronoi;"
372 if(points=="points") then
374 for i=1,#listPoints do
375 if(listPoints[i].type == "bbox") then
376 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
379 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
382 for i=1,#listCircumC do
383 output = output .. "dotlabel.llft (btex $\\CircumPoint_{" .. i .. "}$ etex, (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u ) withcolor \\luameshmpcolorVoronoi ;"
387 for i=1,#listPoints do
388 if(listPoints[i].type == "bbox") then
389 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
392 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
395 for i=1,#listCircumC do
396 output = output .. "drawdot (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u withcolor \\luameshmpcolorVoronoi withpen pencircle scaled 3;"
404 -- trace Voronoi with TikZ
405 function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi,styleD,styleV)
406 if(styleD == "dashed") then
407 sDelaunay = ",dashed"
411 if(styleV == "dashed") then
416 listCircumC = listCircumCenter(listPoints,triangulation)
418 for i=1,#listPoints do
419 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
421 for i=1,#listCircumC do
422 output = output .. "\\coordinate (CircumPoints".. i .. ") at (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ");"
425 for i=1,#triangulation do
426 PointI = listPoints[triangulation[i][1]]
427 PointJ = listPoints[triangulation[i][2]]
428 PointK = listPoints[triangulation[i][3]]
429 if(triangulation[i].type == "bbox") then
430 output = output .. "\\draw[color="..colorBbox..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
432 output = output .. "\\draw[color="..color..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
436 for i=1,#listVoronoi do
437 PointI = listCircumC[listVoronoi[i][1]]
438 PointJ = listCircumC[listVoronoi[i][2]]
439 output = output .. "\\draw[color="..colorVoronoi..sVoronoi.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..");"
441 if(points=="points") then
443 for i=1,#listPoints do
444 if(listPoints[i].type == "bbox") then
445 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
448 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
451 for i=1,#listCircumC do
452 output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\CircumPoint_{" .. i .. "}$};"
456 for i=1,#listPoints do
457 if(listPoints[i].type == "bbox") then
458 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
461 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
464 for i=1,#listCircumC do
465 output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$};"
473 -- buildVoronoi with MP
474 function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri,styleD,styleV)
475 listPoints = buildList(chaine, mode)
476 triangulation = BowyerWatson(listPoints,bbox)
477 listVoronoi = buildVoronoi(listPoints, triangulation)
478 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
479 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
484 -- buildVoronoi with TikZ
485 function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi,styleD,styleV)
486 listPoints = buildList(chaine, mode)
487 triangulation = BowyerWatson(listPoints,bbox)
488 listVoronoi = buildVoronoi(listPoints, triangulation)
489 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
490 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
494 -- buildVoronoi with MP
495 function buildVoronoiMPBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,styleD,styleV)
496 listPoints = buildList(chaine, mode)
497 triangulation = BowyerWatson(listPoints,bbox)
498 listVoronoi = buildVoronoi(listPoints, triangulation)
499 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
500 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
505 -- buildVoronoi with TikZ
506 function buildVoronoiTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi)
507 listPoints = buildList(chaine, mode,styleD,styleV)
508 triangulation = BowyerWatson(listPoints,bbox)
509 listVoronoi = buildVoronoi(listPoints, triangulation)
510 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
511 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
517 -- trace a triangulation with TikZ
518 function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
520 for i=1,#listPoints do
521 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
523 for i=1,#triangulation do
524 PointI = listPoints[triangulation[i][1]]
525 PointJ = listPoints[triangulation[i][2]]
526 PointK = listPoints[triangulation[i][3]]
527 if(triangulation[i].type == "bbox") then
528 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
530 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
533 if(points=="points") then
535 for i=1,#listPoints do
536 if(listPoints[i].type == "bbox") then
537 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
540 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
548 -- trace a triangulation with MP
549 function traceMeshMP(listPoints, triangulation,points)
551 output = output .. " pair MeshPoints[];"
552 for i=1,#listPoints do
553 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
555 for i=1,#triangulation do
556 PointI = listPoints[triangulation[i][1]]
557 PointJ = listPoints[triangulation[i][2]]
558 PointK = listPoints[triangulation[i][3]]
559 if(triangulation[i].type == "bbox") then
560 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
562 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
565 if(points=="points") then
567 for i=1,#listPoints do
568 if(listPoints[i].type == "bbox") then
569 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
572 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
581 function buildMeshMPBW(chaine,mode,points,bbox,scale)
582 listPoints = buildList(chaine, mode)
583 triangulation = BowyerWatson(listPoints,bbox)
584 output = traceMeshMP(listPoints, triangulation,points)
585 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
589 -- buildMesh with MP include code
590 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
591 listPoints = buildList(chaine, mode)
592 triangulation = BowyerWatson(listPoints,bbox)
593 output = traceMeshMP(listPoints, triangulation,points)
594 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
598 -- buildMesh with TikZ
599 function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
600 listPoints = buildList(chaine, mode)
601 triangulation = BowyerWatson(listPoints,bbox)
602 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
603 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
607 -- buildMesh with TikZ
608 function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
609 listPoints = buildList(chaine, mode)
610 triangulation = BowyerWatson(listPoints,bbox)
611 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
612 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
617 -- print points of the mesh
618 function tracePointsMP(listPoints,points)
620 output = output .. " pair MeshPoints[];"
621 for i=1,#listPoints do
622 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
624 if(points=="points") then
626 for i=1,#listPoints do
627 if(listPoints[i].type == "bbox") then
628 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
631 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
635 for i=1,#listPoints do
636 if(listPoints[i].type == "bbox") then
637 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
639 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
646 -- print points of the mesh
647 function tracePointsTikZ(listPoints,points,color,colorBbox)
649 for i=1,#listPoints do
650 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
652 if(points=="points") then
654 for i=1,#listPoints do
655 if(listPoints[i].type == "bbox") then
656 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
659 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
663 for i=1,#listPoints do
664 if(listPoints[i].type == "bbox") then
665 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
667 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
674 -- print points to mesh
675 function printPointsMP(chaine,mode,points,bbox,scale)
676 listPoints = buildList(chaine, mode)
677 if(bbox == "bbox" ) then
678 listPoints = buildBoundingBox(listPoints)
680 output = tracePointsMP(listPoints,points)
681 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
686 -- print points to mesh
687 function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
688 listPoints = buildList(chaine, mode)
689 if(bbox == "bbox" ) then
690 listPoints = buildBoundingBox(listPoints)
692 output = tracePointsMP(listPoints,points)
693 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
697 -- print points to mesh
698 function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
699 listPoints = buildList(chaine, mode)
700 if(bbox == "bbox" ) then
701 listPoints = buildBoundingBox(listPoints)
703 output = tracePointsTikZ(listPoints,points,color,colorBbox)
704 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
709 -- print points to mesh
710 function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
711 listPoints = buildList(chaine, mode)
712 if(bbox == "bbox" ) then
713 listPoints = buildBoundingBox(listPoints)
715 output = tracePointsTikZ(listPoints,points,color,colorBbox)
716 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
722 function buildRect(largeur,a,b,nbrA, nbrB)
723 listPoints = rectangleList(a,b,nbrA,nbrB)
724 triangulation = BowyerWatson(listPoints,"none")
725 traceTikZ(listPoints, triangulation,largeur,"none")
728 local function shallowCopy(original)
730 for key, value in pairs(original) do
736 -- function give a real polygon without repeting points
737 function cleanPoly(polygon)
739 polyCopy = shallowCopy(polygon)
742 table.insert(polyNew, e1)
743 table.insert(polyNew, e2)
744 table.remove(polyCopy,1)
749 while (i<=#polyCopy and find==false) do
750 bool1 = (polyCopy[i][1] == polyNew[j])
751 bool2 = (polyCopy[i][2] == polyNew[j])
752 if(bool1 or bool2) then -- the edge has a common point with polyNew[j]
754 table.insert(polyNew, polyCopy[i][1])
756 table.remove(polyCopy,i)
758 elseif(not bool2) then
759 table.insert(polyNew, polyCopy[i][2])
761 table.remove(polyCopy,i)
772 function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
774 -- build the triangulation
775 triangulation = BowyerWatson(listPoints,bbox)
776 badTriangles = buildBadTriangles(P,triangulation)
777 for i=1,#listPoints do
778 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
780 if(step == "badT") then
782 for i=1,#triangulation do
783 PointI = listPoints[triangulation[i][1]]
784 PointJ = listPoints[triangulation[i][2]]
785 PointK = listPoints[triangulation[i][3]]
786 if(triangulation[i].type == "bbox") then
787 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
789 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
792 -- draw and fill the bad triangle
793 for i=1,#badTriangles do
794 PointI = listPoints[triangulation[badTriangles[i]][1]]
795 PointJ = listPoints[triangulation[badTriangles[i]][2]]
796 PointK = listPoints[triangulation[badTriangles[i]][3]]
797 output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
799 -- draw the circoncircle
800 for i=1,#badTriangles do
801 PointI = listPoints[triangulation[badTriangles[i]][1]]
802 PointJ = listPoints[triangulation[badTriangles[i]][2]]
803 PointK = listPoints[triangulation[badTriangles[i]][3]]
804 center, radius = circoncircle(PointI, PointJ, PointK)
805 output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
809 for i=1,#listPoints do
810 if(listPoints[i].type == "bbox") then
811 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
814 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
817 -- mark the point to add
818 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
819 elseif(step == "cavity") then
820 polygon = buildCavity(badTriangles, triangulation)
821 polyNew = cleanPoly(polygon)
822 -- remove the bad triangles
823 for j=1,#badTriangles do
824 table.remove(triangulation,badTriangles[j]-(j-1))
826 -- draw the triangles
827 for i=1,#triangulation do
828 PointI = listPoints[triangulation[i][1]]
829 PointJ = listPoints[triangulation[i][2]]
830 PointK = listPoints[triangulation[i][3]]
831 if(triangulation[i].type == "bbox") then
832 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
834 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
837 -- fill and draw the cavity
840 PointI = listPoints[polyNew[i]]
841 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
843 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
844 -- mark the points of the mesh
846 for i=1,#listPoints do
847 if(listPoints[i].type == "bbox") then
848 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
851 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
854 -- mark the adding point
855 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
856 elseif(step == "newT") then
857 polygon = buildCavity(badTriangles, triangulation)
858 polyNew = cleanPoly(polygon)
859 -- remove the bad triangles
860 for j=1,#badTriangles do
861 table.remove(triangulation,badTriangles[j]-(j-1))
863 -- draw the triangle of the triangulation
864 for i=1,#triangulation do
865 PointI = listPoints[triangulation[i][1]]
866 PointJ = listPoints[triangulation[i][2]]
867 PointK = listPoints[triangulation[i][3]]
868 if(triangulation[i].type == "bbox") then
869 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
871 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
874 -- fill and draw the cavity
877 PointI = listPoints[polyNew[i]]
878 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
880 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
881 -- draw the new triangles composed by the edges of the polygon and the added point
883 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 ..");"
884 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
885 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
889 for i=1,#listPoints do
890 if(listPoints[i].type == "bbox") then
891 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
894 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
897 -- mark the added point
898 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
903 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
905 output = output .. "pair MeshPoints[];"
906 -- build the triangulation
907 triangulation = BowyerWatson(listPoints,bbox)
908 badTriangles = buildBadTriangles(P,triangulation)
909 for i=1,#listPoints do
910 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
912 if(step == "badT") then
914 for i=1,#triangulation do
915 PointI = listPoints[triangulation[i][1]]
916 PointJ = listPoints[triangulation[i][2]]
917 PointK = listPoints[triangulation[i][3]]
918 if(triangulation[i].type == "bbox") then
919 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
921 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
924 -- draw and fill the bad triangle
925 for i=1,#badTriangles do
926 PointI = listPoints[triangulation[badTriangles[i]][1]]
927 PointJ = listPoints[triangulation[badTriangles[i]][2]]
928 PointK = listPoints[triangulation[badTriangles[i]][3]]
929 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
930 output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
932 -- draw the circoncircle
933 for i=1,#badTriangles do
934 PointI = listPoints[triangulation[badTriangles[i]][1]]
935 PointJ = listPoints[triangulation[badTriangles[i]][2]]
936 PointK = listPoints[triangulation[badTriangles[i]][3]]
937 center, radius = circoncircle(PointI, PointJ, PointK)
938 output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
942 for i=1,#listPoints do
943 if(listPoints[i].type == "bbox") then
944 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
947 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
950 -- mark the point to add
951 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
952 elseif(step == "cavity") then
953 polygon = buildCavity(badTriangles, triangulation)
954 polyNew = cleanPoly(polygon)
955 -- remove the bad triangles
956 for j=1,#badTriangles do
957 table.remove(triangulation,badTriangles[j]-(j-1))
959 -- draw the triangles
960 for i=1,#triangulation do
961 PointI = listPoints[triangulation[i][1]]
962 PointJ = listPoints[triangulation[i][2]]
963 PointK = listPoints[triangulation[i][3]]
964 if(triangulation[i].type == "bbox") then
965 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
967 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
970 -- fill and draw the cavity
973 PointI = listPoints[polyNew[i]]
974 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
976 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
977 output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
978 -- mark the points of the mesh
980 for i=1,#listPoints do
981 if(listPoints[i].type == "bbox") then
982 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
985 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
988 -- mark the adding point
989 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
990 elseif(step == "newT") then
991 polygon = buildCavity(badTriangles, triangulation)
992 polyNew = cleanPoly(polygon)
993 -- remove the bad triangles
994 for j=1,#badTriangles do
995 table.remove(triangulation,badTriangles[j]-(j-1))
997 -- draw the triangle of the triangulation
998 for i=1,#triangulation do
999 PointI = listPoints[triangulation[i][1]]
1000 PointJ = listPoints[triangulation[i][2]]
1001 PointK = listPoints[triangulation[i][3]]
1002 if(triangulation[i].type == "bbox") then
1003 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
1005 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
1011 PointI = listPoints[polyNew[i]]
1012 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
1014 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
1015 -- draw the new triangles composed by the edges of the polygon and the added point
1017 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;"
1018 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;"
1019 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;"
1023 for i=1,#listPoints do
1024 if(listPoints[i].type == "bbox") then
1025 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
1028 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
1031 -- mark the added point
1032 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
1038 -- build the list of points extern and stop at nbr
1039 function buildListExt(chaine, stop)
1041 io.input(chaine) -- open the file
1042 text=io.read("*all")
1043 lines=string.explode(text,"\n+") -- all the lines
1044 for i=1,tonumber(stop) do
1045 xy=string.explode(lines[i]," +")
1046 table.insert(listPoints,{x=tonumber(xy[1]),y=tonumber(xy[2])})
1048 xy=string.explode(lines[stop+1]," +")
1049 point={x=tonumber(xy[1]),y=tonumber(xy[2])}
1050 return point, listPoints
1054 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1055 if(mode=="int") then
1056 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1058 listPoints = buildList(chaine, mode)
1060 -- point is a number
1061 P, listPoints = buildListExt(chaine,tonumber(point))
1063 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1064 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
1068 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1069 if(mode=="int") then
1070 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1072 listPoints = buildList(chaine, mode)
1074 -- point is a number
1075 P, listPoints = buildListExt(chaine,tonumber(point))
1077 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1078 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
1082 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
1083 if(mode=="int") then
1084 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1086 listPoints = buildList(chaine, mode)
1088 -- point is a number
1089 P, listPoints = buildListExt(chaine,tonumber(point))
1091 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
1092 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
1096 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
1097 if(mode=="int") then
1098 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1100 listPoints = buildList(chaine, mode)
1102 -- point is a number
1103 P, listPoints = buildListExt(chaine,tonumber(point))
1105 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
1106 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1111 function split(pString, pPattern)
1112 local Table = {} -- NOTE: use {n = 0} in Lua-5.0
1113 local fpat = "(.-)" .. pPattern
1115 local s, e, cap = pString:find(fpat, 1)
1117 if s ~= 1 or cap ~= "" then
1118 table.insert(Table,cap)
1121 s, e, cap = pString:find(fpat, last_end)
1123 if last_end <= #pString then
1124 cap = pString:sub(last_end)
1125 table.insert(Table, cap)
1130 function readGmsh(file)
1131 io.input(file) -- open the file
1132 text=io.read("*all")
1133 local lines = split(text,"\n+") -- all the lines
1138 boolElements = false
1142 if(lines[i+J] == "$EndNodes") then
1144 -- go to the next line
1146 if(boolNodes) then -- we are in the Nodes environment
1147 xy=split(lines[i+J]," +")
1148 table.insert(listPoints,{x=tonumber(xy[2]),y=tonumber(xy[3])})
1150 if(lines[i+J] == "$Nodes") then
1152 -- go to the next line
1155 if(lines[i+J] == "$EndElements") then
1156 boolElements = false
1157 -- go to the next line
1159 if(boolElements) then -- we are in the Nodes environment
1160 xy=split(lines[i+J]," +")
1161 if(tonumber(xy[2]) == 2) then -- if the element is a triangle
1163 table.insert(triangulation,{tonumber(xy[2+nbrTags+1]),tonumber(xy[2+nbrTags+2]),tonumber(xy[2+nbrTags+3])})
1166 if(lines[i+J] == "$Elements") then
1168 -- go to the next line
1172 return listPoints, triangulation
1175 function drawGmshMP(file,points,scale)
1176 listPoints,triangulation = readGmsh(file)
1177 output = traceMeshMP(listPoints,triangulation,points)
1178 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
1182 function drawGmshMPinc(file,beginning,ending,points,scale)
1183 listPoints,triangulation = readGmsh(file)
1184 output = traceMeshMP(listPoints,triangulation,points)
1185 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1192 function drawGmshTikZ(file,points,scale,color)
1193 listPoints,triangulation = readGmsh(file)
1194 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
1195 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
1200 function drawGmshTikZinc(file,beginning, ending,points,scale,color)
1201 listPoints,triangulation = readGmsh(file)
1202 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
1203 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
1208 -- buildVoronoi with MP
1209 function gmshVoronoiMP(file,points,scale,tri,styleD,styleV)
1210 listPoints,triangulation = readGmsh(file)
1211 listVoronoi = buildVoronoi(listPoints, triangulation)
1212 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
1213 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
1218 -- buildVoronoi with TikZ
1219 function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV)
1220 listPoints,triangulation = readGmsh(file)
1221 listVoronoi = buildVoronoi(listPoints, triangulation)
1222 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
1223 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
1227 -- buildVoronoi with MP
1228 function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV)
1229 listPoints,triangulation = readGmsh(file)
1230 listVoronoi = buildVoronoi(listPoints, triangulation)
1231 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
1232 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1237 -- buildVoronoi with TikZ
1238 function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV)
1239 listPoints,triangulation = readGmsh(file)
1240 listVoronoi = buildVoronoi(listPoints, triangulation)
1241 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
1242 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"