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,styleD,styleV)
333 if(styleD == "dashed") then
334 sDelaunay = "dashed evenly"
338 if(styleV == "dashed") then
339 sVoronoi = "dashed evenly"
343 listCircumC = listCircumCenter(listPoints,triangulation)
345 output = output .. " pair MeshPoints[];"
346 for i=1,#listPoints do
347 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
349 output = output .. " pair CircumCenters[];"
350 for i=1,#listCircumC do
351 output = output .. "CircumCenters[".. i .. "] = (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ")*u;"
354 for i=1,#triangulation do
355 PointI = listPoints[triangulation[i][1]]
356 PointJ = listPoints[triangulation[i][2]]
357 PointK = listPoints[triangulation[i][3]]
358 if(triangulation[i].type == "bbox") then
359 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolorBbox;"
361 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolor;"
365 for i=1,#listVoronoi do
366 PointI = listCircumC[listVoronoi[i][1]]
367 PointJ = listCircumC[listVoronoi[i][2]]
368 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u "..sVoronoi.." withcolor \\luameshmpcolorVoronoi;"
370 if(points=="points") then
372 for i=1,#listPoints do
373 if(listPoints[i].type == "bbox") then
374 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
377 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
380 for i=1,#listCircumC do
381 output = output .. "dotlabel.llft (btex $\\CircumPoint_{" .. i .. "}$ etex, (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u ) withcolor \\luameshmpcolorVoronoi ;"
385 for i=1,#listPoints do
386 if(listPoints[i].type == "bbox") then
387 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
390 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
393 for i=1,#listCircumC do
394 output = output .. "drawdot (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u withcolor \\luameshmpcolorVoronoi withpen pencircle scaled 3;"
402 -- trace Voronoi with TikZ
403 function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi,styleD,styleV)
404 if(styleD == "dashed") then
405 sDelaunay = ",dashed"
409 if(styleV == "dashed") then
414 listCircumC = listCircumCenter(listPoints,triangulation)
416 for i=1,#listPoints do
417 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
419 for i=1,#listCircumC do
420 output = output .. "\\coordinate (CircumPoints".. i .. ") at (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ");"
423 for i=1,#triangulation do
424 PointI = listPoints[triangulation[i][1]]
425 PointJ = listPoints[triangulation[i][2]]
426 PointK = listPoints[triangulation[i][3]]
427 if(triangulation[i].type == "bbox") then
428 output = output .. "\\draw[color="..colorBbox..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
430 output = output .. "\\draw[color="..color..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
434 for i=1,#listVoronoi do
435 PointI = listCircumC[listVoronoi[i][1]]
436 PointJ = listCircumC[listVoronoi[i][2]]
437 output = output .. "\\draw[color="..colorVoronoi..sVoronoi.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..");"
439 if(points=="points") then
441 for i=1,#listPoints do
442 if(listPoints[i].type == "bbox") then
443 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
446 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
449 for i=1,#listCircumC do
450 output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\CircumPoint_{" .. i .. "}$};"
454 for i=1,#listPoints do
455 if(listPoints[i].type == "bbox") then
456 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
459 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
462 for i=1,#listCircumC do
463 output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$};"
471 -- buildVoronoi with MP
472 function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri,styleD,styleV)
473 listPoints = buildList(chaine, mode)
474 triangulation = BowyerWatson(listPoints,bbox)
475 listVoronoi = buildVoronoi(listPoints, triangulation)
476 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
477 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
482 -- buildVoronoi with TikZ
483 function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi,styleD,styleV)
484 listPoints = buildList(chaine, mode)
485 triangulation = BowyerWatson(listPoints,bbox)
486 listVoronoi = buildVoronoi(listPoints, triangulation)
487 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
488 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
492 -- buildVoronoi with MP
493 function buildVoronoiMPBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,styleD,styleV)
494 listPoints = buildList(chaine, mode)
495 triangulation = BowyerWatson(listPoints,bbox)
496 listVoronoi = buildVoronoi(listPoints, triangulation)
497 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
498 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
503 -- buildVoronoi with TikZ
504 function buildVoronoiTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi)
505 listPoints = buildList(chaine, mode,styleD,styleV)
506 triangulation = BowyerWatson(listPoints,bbox)
507 listVoronoi = buildVoronoi(listPoints, triangulation)
508 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
509 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
515 -- trace a triangulation with TikZ
516 function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
518 for i=1,#listPoints do
519 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
521 for i=1,#triangulation do
522 PointI = listPoints[triangulation[i][1]]
523 PointJ = listPoints[triangulation[i][2]]
524 PointK = listPoints[triangulation[i][3]]
525 if(triangulation[i].type == "bbox") then
526 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
528 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
531 if(points=="points") then
533 for i=1,#listPoints do
534 if(listPoints[i].type == "bbox") then
535 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
538 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
546 -- trace a triangulation with MP
547 function traceMeshMP(listPoints, triangulation,points)
549 output = output .. " pair MeshPoints[];"
550 for i=1,#listPoints do
551 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
553 for i=1,#triangulation do
554 PointI = listPoints[triangulation[i][1]]
555 PointJ = listPoints[triangulation[i][2]]
556 PointK = listPoints[triangulation[i][3]]
557 if(triangulation[i].type == "bbox") then
558 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
560 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
563 if(points=="points") then
565 for i=1,#listPoints do
566 if(listPoints[i].type == "bbox") then
567 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
570 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
579 function buildMeshMPBW(chaine,mode,points,bbox,scale)
580 listPoints = buildList(chaine, mode)
581 triangulation = BowyerWatson(listPoints,bbox)
582 output = traceMeshMP(listPoints, triangulation,points)
583 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
587 -- buildMesh with MP include code
588 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
589 listPoints = buildList(chaine, mode)
590 triangulation = BowyerWatson(listPoints,bbox)
591 output = traceMeshMP(listPoints, triangulation,points)
592 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
596 -- buildMesh with TikZ
597 function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
598 listPoints = buildList(chaine, mode)
599 triangulation = BowyerWatson(listPoints,bbox)
600 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
601 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
605 -- buildMesh with TikZ
606 function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
607 listPoints = buildList(chaine, mode)
608 triangulation = BowyerWatson(listPoints,bbox)
609 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
610 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
615 -- print points of the mesh
616 function tracePointsMP(listPoints,points)
618 output = output .. " pair MeshPoints[];"
619 for i=1,#listPoints do
620 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
622 if(points=="points") then
624 for i=1,#listPoints do
625 if(listPoints[i].type == "bbox") then
626 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
629 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
633 for i=1,#listPoints do
634 if(listPoints[i].type == "bbox") then
635 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
637 output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
644 -- print points of the mesh
645 function tracePointsTikZ(listPoints,points,color,colorBbox)
647 for i=1,#listPoints do
648 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
650 if(points=="points") then
652 for i=1,#listPoints do
653 if(listPoints[i].type == "bbox") then
654 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
657 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
661 for i=1,#listPoints do
662 if(listPoints[i].type == "bbox") then
663 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
665 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
672 -- print points to mesh
673 function printPointsMP(chaine,mode,points,bbox,scale)
674 listPoints = buildList(chaine, mode)
675 if(bbox == "bbox" ) then
676 listPoints = buildBoundingBox(listPoints)
678 output = tracePointsMP(listPoints,points)
679 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
684 -- print points to mesh
685 function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
686 listPoints = buildList(chaine, mode)
687 if(bbox == "bbox" ) then
688 listPoints = buildBoundingBox(listPoints)
690 output = tracePointsMP(listPoints,points)
691 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
695 -- print points to mesh
696 function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
697 listPoints = buildList(chaine, mode)
698 if(bbox == "bbox" ) then
699 listPoints = buildBoundingBox(listPoints)
701 output = tracePointsTikZ(listPoints,points,color,colorBbox)
702 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
707 -- print points to mesh
708 function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
709 listPoints = buildList(chaine, mode)
710 if(bbox == "bbox" ) then
711 listPoints = buildBoundingBox(listPoints)
713 output = tracePointsTikZ(listPoints,points,color,colorBbox)
714 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
720 function buildRect(largeur,a,b,nbrA, nbrB)
721 listPoints = rectangleList(a,b,nbrA,nbrB)
722 triangulation = BowyerWatson(listPoints,"none")
723 traceTikZ(listPoints, triangulation,largeur,"none")
726 local function shallowCopy(original)
728 for key, value in pairs(original) do
734 -- function give a real polygon without repeting points
735 function cleanPoly(polygon)
737 polyCopy = shallowCopy(polygon)
740 table.insert(polyNew, e1)
741 table.insert(polyNew, e2)
742 table.remove(polyCopy,1)
747 while (i<=#polyCopy and find==false) do
748 bool1 = (polyCopy[i][1] == polyNew[j])
749 bool2 = (polyCopy[i][2] == polyNew[j])
750 if(bool1 or bool2) then -- the edge has a common point with polyNew[j]
752 table.insert(polyNew, polyCopy[i][1])
754 table.remove(polyCopy,i)
756 elseif(not bool2) then
757 table.insert(polyNew, polyCopy[i][2])
759 table.remove(polyCopy,i)
770 function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
772 -- build the triangulation
773 triangulation = BowyerWatson(listPoints,bbox)
774 badTriangles = buildBadTriangles(P,triangulation)
775 for i=1,#listPoints do
776 output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
778 if(step == "badT") then
780 for i=1,#triangulation do
781 PointI = listPoints[triangulation[i][1]]
782 PointJ = listPoints[triangulation[i][2]]
783 PointK = listPoints[triangulation[i][3]]
784 if(triangulation[i].type == "bbox") then
785 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
787 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
790 -- draw and fill the bad triangle
791 for i=1,#badTriangles do
792 PointI = listPoints[triangulation[badTriangles[i]][1]]
793 PointJ = listPoints[triangulation[badTriangles[i]][2]]
794 PointK = listPoints[triangulation[badTriangles[i]][3]]
795 output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
797 -- draw the circoncircle
798 for i=1,#badTriangles do
799 PointI = listPoints[triangulation[badTriangles[i]][1]]
800 PointJ = listPoints[triangulation[badTriangles[i]][2]]
801 PointK = listPoints[triangulation[badTriangles[i]][3]]
802 center, radius = circoncircle(PointI, PointJ, PointK)
803 output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
807 for i=1,#listPoints do
808 if(listPoints[i].type == "bbox") then
809 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
812 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
815 -- mark the point to add
816 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
817 elseif(step == "cavity") then
818 polygon = buildCavity(badTriangles, triangulation)
819 polyNew = cleanPoly(polygon)
820 -- remove the bad triangles
821 for j=1,#badTriangles do
822 table.remove(triangulation,badTriangles[j]-(j-1))
824 -- draw the triangles
825 for i=1,#triangulation do
826 PointI = listPoints[triangulation[i][1]]
827 PointJ = listPoints[triangulation[i][2]]
828 PointK = listPoints[triangulation[i][3]]
829 if(triangulation[i].type == "bbox") then
830 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
832 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
835 -- fill and draw the cavity
838 PointI = listPoints[polyNew[i]]
839 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
841 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
842 -- mark the points of the mesh
844 for i=1,#listPoints do
845 if(listPoints[i].type == "bbox") then
846 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
849 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
852 -- mark the adding point
853 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
854 elseif(step == "newT") then
855 polygon = buildCavity(badTriangles, triangulation)
856 polyNew = cleanPoly(polygon)
857 -- remove the bad triangles
858 for j=1,#badTriangles do
859 table.remove(triangulation,badTriangles[j]-(j-1))
861 -- draw the triangle of the triangulation
862 for i=1,#triangulation do
863 PointI = listPoints[triangulation[i][1]]
864 PointJ = listPoints[triangulation[i][2]]
865 PointK = listPoints[triangulation[i][3]]
866 if(triangulation[i].type == "bbox") then
867 output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
869 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
872 -- fill and draw the cavity
875 PointI = listPoints[polyNew[i]]
876 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
878 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
879 -- draw the new triangles composed by the edges of the polygon and the added point
881 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 ..");"
882 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
883 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
887 for i=1,#listPoints do
888 if(listPoints[i].type == "bbox") then
889 output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
892 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
895 -- mark the added point
896 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
901 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
903 output = output .. "pair MeshPoints[];"
904 -- build the triangulation
905 triangulation = BowyerWatson(listPoints,bbox)
906 badTriangles = buildBadTriangles(P,triangulation)
907 for i=1,#listPoints do
908 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
910 if(step == "badT") then
912 for i=1,#triangulation do
913 PointI = listPoints[triangulation[i][1]]
914 PointJ = listPoints[triangulation[i][2]]
915 PointK = listPoints[triangulation[i][3]]
916 if(triangulation[i].type == "bbox") then
917 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
919 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
922 -- draw and fill the bad triangle
923 for i=1,#badTriangles do
924 PointI = listPoints[triangulation[badTriangles[i]][1]]
925 PointJ = listPoints[triangulation[badTriangles[i]][2]]
926 PointK = listPoints[triangulation[badTriangles[i]][3]]
927 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
928 output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
930 -- draw the circoncircle
931 for i=1,#badTriangles do
932 PointI = listPoints[triangulation[badTriangles[i]][1]]
933 PointJ = listPoints[triangulation[badTriangles[i]][2]]
934 PointK = listPoints[triangulation[badTriangles[i]][3]]
935 center, radius = circoncircle(PointI, PointJ, PointK)
936 output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
940 for i=1,#listPoints do
941 if(listPoints[i].type == "bbox") then
942 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
945 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
948 -- mark the point to add
949 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
950 elseif(step == "cavity") then
951 polygon = buildCavity(badTriangles, triangulation)
952 polyNew = cleanPoly(polygon)
953 -- remove the bad triangles
954 for j=1,#badTriangles do
955 table.remove(triangulation,badTriangles[j]-(j-1))
957 -- draw the triangles
958 for i=1,#triangulation do
959 PointI = listPoints[triangulation[i][1]]
960 PointJ = listPoints[triangulation[i][2]]
961 PointK = listPoints[triangulation[i][3]]
962 if(triangulation[i].type == "bbox") then
963 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
965 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
968 -- fill and draw the cavity
971 PointI = listPoints[polyNew[i]]
972 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
974 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
975 output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
976 -- mark the points of the mesh
978 for i=1,#listPoints do
979 if(listPoints[i].type == "bbox") then
980 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
983 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
986 -- mark the adding point
987 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
988 elseif(step == "newT") then
989 polygon = buildCavity(badTriangles, triangulation)
990 polyNew = cleanPoly(polygon)
991 -- remove the bad triangles
992 for j=1,#badTriangles do
993 table.remove(triangulation,badTriangles[j]-(j-1))
995 -- draw the triangle of the triangulation
996 for i=1,#triangulation do
997 PointI = listPoints[triangulation[i][1]]
998 PointJ = listPoints[triangulation[i][2]]
999 PointK = listPoints[triangulation[i][3]]
1000 if(triangulation[i].type == "bbox") then
1001 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
1003 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
1009 PointI = listPoints[polyNew[i]]
1010 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
1012 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
1013 -- draw the new triangles composed by the edges of the polygon and the added point
1015 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;"
1016 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;"
1017 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;"
1021 for i=1,#listPoints do
1022 if(listPoints[i].type == "bbox") then
1023 output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
1026 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
1029 -- mark the added point
1030 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
1036 -- build the list of points extern and stop at nbr
1037 function buildListExt(chaine, stop)
1039 io.input(chaine) -- open the file
1040 text=io.read("*all")
1041 lines=string.explode(text,"\n+") -- all the lines
1042 for i=1,tonumber(stop) do
1043 xy=string.explode(lines[i]," +")
1044 table.insert(listPoints,{x=tonumber(xy[1]),y=tonumber(xy[2])})
1046 xy=string.explode(lines[stop+1]," +")
1047 point={x=tonumber(xy[1]),y=tonumber(xy[2])}
1048 return point, listPoints
1052 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1053 if(mode=="int") then
1054 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1056 listPoints = buildList(chaine, mode)
1058 -- point is a number
1059 P, listPoints = buildListExt(chaine,tonumber(point))
1061 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1062 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
1066 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1067 if(mode=="int") then
1068 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1070 listPoints = buildList(chaine, mode)
1072 -- point is a number
1073 P, listPoints = buildListExt(chaine,tonumber(point))
1075 output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1076 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
1080 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
1081 if(mode=="int") then
1082 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1084 listPoints = buildList(chaine, mode)
1086 -- point is a number
1087 P, listPoints = buildListExt(chaine,tonumber(point))
1089 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
1090 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
1094 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
1095 if(mode=="int") then
1096 Sx,Sy=string.match(point,"%((.+),(.+)%)")
1098 listPoints = buildList(chaine, mode)
1100 -- point is a number
1101 P, listPoints = buildListExt(chaine,tonumber(point))
1103 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
1104 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1109 function split(pString, pPattern)
1110 local Table = {} -- NOTE: use {n = 0} in Lua-5.0
1111 local fpat = "(.-)" .. pPattern
1113 local s, e, cap = pString:find(fpat, 1)
1115 if s ~= 1 or cap ~= "" then
1116 table.insert(Table,cap)
1119 s, e, cap = pString:find(fpat, last_end)
1121 if last_end <= #pString then
1122 cap = pString:sub(last_end)
1123 table.insert(Table, cap)
1128 function readGmsh(file)
1129 io.input(file) -- open the file
1130 text=io.read("*all")
1131 local lines = split(text,"\n+") -- all the lines
1136 boolElements = false
1140 if(lines[i+J] == "$EndNodes") then
1142 -- go to the next line
1144 if(boolNodes) then -- we are in the Nodes environment
1145 xy=split(lines[i+J]," +")
1146 table.insert(listPoints,{x=tonumber(xy[2]),y=tonumber(xy[3])})
1148 if(lines[i+J] == "$Nodes") then
1150 -- go to the next line
1153 if(lines[i+J] == "$EndElements") then
1154 boolElements = false
1155 -- go to the next line
1157 if(boolElements) then -- we are in the Nodes environment
1158 xy=split(lines[i+J]," +")
1159 if(tonumber(xy[2]) == 2) then -- if the element is a triangle
1161 table.insert(triangulation,{tonumber(xy[2+nbrTags+1]),tonumber(xy[2+nbrTags+2]),tonumber(xy[2+nbrTags+3])})
1164 if(lines[i+J] == "$Elements") then
1166 -- go to the next line
1170 return listPoints, triangulation
1173 function drawGmshMP(file,points,scale)
1174 listPoints,triangulation = readGmsh(file)
1175 output = traceMeshMP(listPoints,triangulation,points)
1176 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
1180 function drawGmshMPinc(file,beginning,ending,points,scale)
1181 listPoints,triangulation = readGmsh(file)
1182 output = traceMeshMP(listPoints,triangulation,points)
1183 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1190 function drawGmshTikZ(file,points,scale,color)
1191 listPoints,triangulation = readGmsh(file)
1192 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
1193 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
1198 function drawGmshTikZinc(file,beginning, ending,points,scale,color)
1199 listPoints,triangulation = readGmsh(file)
1200 output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
1201 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
1206 -- buildVoronoi with MP
1207 function gmshVoronoiMP(file,points,scale,tri,styleD,styleV)
1208 listPoints,triangulation = readGmsh(file)
1209 listVoronoi = buildVoronoi(listPoints, triangulation)
1210 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
1211 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
1216 -- buildVoronoi with TikZ
1217 function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV)
1218 listPoints,triangulation = readGmsh(file)
1219 listVoronoi = buildVoronoi(listPoints, triangulation)
1220 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
1221 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
1225 -- buildVoronoi with MP
1226 function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV)
1227 listPoints,triangulation = readGmsh(file)
1228 listVoronoi = buildVoronoi(listPoints, triangulation)
1229 output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
1230 output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1235 -- buildVoronoi with TikZ
1236 function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV)
1237 listPoints,triangulation = readGmsh(file)
1238 listVoronoi = buildVoronoi(listPoints, triangulation)
1239 output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
1240 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"