Séparation en trois fichiers lua, et fonction d'ajout de points d'une grille à l...
[delaunay.git] / luamesh-tex.lua
1 -- trace Voronoi with MP
2 function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri,styleD,styleV)
3    if(styleD == "dashed") then
4       sDelaunay = "dashed evenly"
5    else
6       sDelaunay = ""
7    end
8    if(styleV == "dashed") then
9       sVoronoi = "dashed evenly"
10    else
11       sVoronoi = ""
12    end
13    listCircumC = listCircumCenter(listPoints,triangulation)
14    output = "";
15    output = output .. " pair MeshPoints[];"
16    for i=1,#listPoints do
17       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
18    end
19    output = output .. " pair CircumCenters[];"
20    for i=1,#listCircumC do
21       output = output .. "CircumCenters[".. i .. "] = (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ")*u;"
22    end
23    if(tri=="show") then
24       for i=1,#triangulation do
25          PointI = listPoints[triangulation[i][1]]
26          PointJ = listPoints[triangulation[i][2]]
27          PointK = listPoints[triangulation[i][3]]
28          if(triangulation[i].type == "bbox") then
29             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolorBbox;"
30          else
31             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolor;"
32          end
33       end
34    end
35    for i=1,#listVoronoi do
36       PointI = listCircumC[listVoronoi[i][1]]
37       PointJ = listCircumC[listVoronoi[i][2]]
38       output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u "..sVoronoi.." withcolor \\luameshmpcolorVoronoi;"
39    end
40    if(points=="points") then
41       j=1
42       for i=1,#listPoints do
43          if(listPoints[i].type == "bbox") then
44             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
45             j=j+1
46          else
47             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
48          end
49       end
50       for i=1,#listCircumC do
51          output = output .. "dotlabel.llft (btex $\\CircumPoint_{" .. i .. "}$ etex, (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u ) withcolor \\luameshmpcolorVoronoi ;"
52       end
53    else
54       j=1
55       for i=1,#listPoints do
56          if(listPoints[i].type == "bbox") then
57             output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
58             j=j+1
59          else
60             output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolor withpen pencircle scaled 3;"
61          end
62       end
63       for i=1,#listCircumC do
64          output = output .. "drawdot  (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u  withcolor \\luameshmpcolorVoronoi withpen pencircle scaled 3;"
65       end
66    end
67
68    return output
69 end
70
71
72 -- trace Voronoi with TikZ
73 function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi,styleD,styleV)
74    if(styleD == "dashed") then
75       sDelaunay = ",dashed"
76    else
77       sDelaunay = ""
78    end
79    if(styleV == "dashed") then
80       sVoronoi = ",dashed"
81    else
82       sVoronoi = ""
83    end
84    listCircumC = listCircumCenter(listPoints,triangulation)
85     output = ""
86    for i=1,#listPoints do
87       output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
88    end
89    for i=1,#listCircumC do
90       output = output .. "\\coordinate (CircumPoints".. i .. ") at  (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ");"
91    end
92    if(tri=="show") then
93       for i=1,#triangulation do
94          PointI = listPoints[triangulation[i][1]]
95          PointJ = listPoints[triangulation[i][2]]
96          PointK = listPoints[triangulation[i][3]]
97          if(triangulation[i].type == "bbox") then
98             output = output .. "\\draw[color="..colorBbox..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
99          else
100             output = output .. "\\draw[color="..color..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
101          end
102       end
103    end
104    for i=1,#listVoronoi do
105       PointI = listCircumC[listVoronoi[i][1]]
106       PointJ = listCircumC[listVoronoi[i][2]]
107       output = output .. "\\draw[color="..colorVoronoi..sVoronoi.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..");"
108    end
109    if(points=="points") then
110       j=1
111       for i=1,#listPoints do
112          if(listPoints[i].type == "bbox") then
113             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
114             j=j+1
115          else
116             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
117          end
118       end
119       for i=1,#listCircumC do
120          output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\CircumPoint_{" .. i .. "}$};"
121       end
122    else
123       j=1
124       for i=1,#listPoints do
125          if(listPoints[i].type == "bbox") then
126             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
127             j=j+1
128          else
129             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
130          end
131       end
132       for i=1,#listCircumC do
133          output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$};"
134       end
135    end
136    return output
137 end
138
139
140
141 -- buildVoronoi with MP
142 function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri,styleD,styleV)
143    listPoints = buildList(chaine, mode)
144    triangulation = BowyerWatson(listPoints,bbox)
145    listVoronoi = buildVoronoi(listPoints, triangulation)
146    output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
147    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
148    tex.sprint(output)
149 end
150
151
152 -- buildVoronoi with TikZ
153 function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi,styleD,styleV)
154    listPoints = buildList(chaine, mode)
155    triangulation = BowyerWatson(listPoints,bbox)
156    listVoronoi = buildVoronoi(listPoints, triangulation)
157    output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
158    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"   tex.sprint(output)
159 end
160
161
162 -- buildVoronoi with MP
163 function buildVoronoiMPBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,styleD,styleV)
164    listPoints = buildList(chaine, mode)
165    triangulation = BowyerWatson(listPoints,bbox)
166    listVoronoi = buildVoronoi(listPoints, triangulation)
167    output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
168    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
169    tex.sprint(output)
170 end
171
172
173 -- buildVoronoi with TikZ
174 function buildVoronoiTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi)
175    listPoints = buildList(chaine, mode,styleD,styleV)
176    triangulation = BowyerWatson(listPoints,bbox)
177    listVoronoi = buildVoronoi(listPoints, triangulation)
178    output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
179    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
180    tex.sprint(output)
181 end
182
183
184
185 -- trace a triangulation with TikZ
186 function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
187    output = ""
188    for i=1,#listPoints do
189       output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
190    end
191    for i=1,#triangulation do
192       PointI = listPoints[triangulation[i][1]]
193       PointJ = listPoints[triangulation[i][2]]
194       PointK = listPoints[triangulation[i][3]]
195       if(triangulation[i].type == "bbox") then
196          output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
197       else
198          output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
199       end
200    end
201    if(points=="points") then
202       j=1
203       for i=1,#listPoints do
204          if(listPoints[i].type == "bbox") then
205             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
206             j=j+1
207          else
208             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
209          end
210       end
211    end
212    return output
213 end
214
215
216 -- trace a triangulation with MP
217 function traceMeshMP(listPoints, triangulation,points)
218    output = "";
219    output = output .. " pair MeshPoints[];"
220    for i=1,#listPoints do
221       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
222    end
223    for i=1,#triangulation do
224       PointI = listPoints[triangulation[i][1]]
225       PointJ = listPoints[triangulation[i][2]]
226       PointK = listPoints[triangulation[i][3]]
227       if(triangulation[i].type == "bbox") then
228          output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
229       else
230          output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
231       end
232    end
233    if(points=="points") then
234       j=1
235       for i=1,#listPoints do
236          if(listPoints[i].type == "bbox") then
237             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
238             j=j+1
239          else
240             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
241          end
242       end
243    end
244    return output
245 end
246
247
248 -- buildMesh with MP
249 function buildMeshMPBW(chaine,mode,points,bbox,scale)
250    listPoints = buildList(chaine, mode)
251    triangulation = BowyerWatson(listPoints,bbox)
252    output = traceMeshMP(listPoints, triangulation,points)
253    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
254    tex.sprint(output)
255 end
256
257 -- buildMesh with MP include code
258 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
259    listPoints = buildList(chaine, mode)
260    triangulation = BowyerWatson(listPoints,bbox)
261    output = traceMeshMP(listPoints, triangulation,points)
262    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
263    tex.sprint(output)
264 end
265
266 -- buildMesh with TikZ
267 function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
268    listPoints = buildList(chaine, mode)
269    triangulation = BowyerWatson(listPoints,bbox)
270    output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
271    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
272    tex.sprint(output)
273 end
274
275 -- buildMesh with TikZ
276 function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
277    listPoints = buildList(chaine, mode)
278    triangulation = BowyerWatson(listPoints,bbox)
279    output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
280    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
281    tex.sprint(output)
282 end
283
284
285 -- print points of the mesh
286 function tracePointsMP(listPoints,points)
287    output = "";
288    output = output .. " pair MeshPoints[];"
289    for i=1,#listPoints do
290       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
291    end
292    if(points=="points") then
293       j=1
294       for i=1,#listPoints do
295          if(listPoints[i].type == "bbox") then
296             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
297             j=j+1
298          else
299             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
300          end
301       end
302    else
303       for i=1,#listPoints do
304          if(listPoints[i].type == "bbox") then
305             output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
306          else
307             output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolor withpen pencircle scaled 3;"
308          end
309       end
310    end
311    return output
312 end
313
314 -- print points of the mesh
315 function tracePointsTikZ(listPoints,points,color,colorBbox)
316    output = "";
317    for i=1,#listPoints do
318       output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
319    end
320    if(points=="points") then
321       j=1
322       for i=1,#listPoints do
323          if(listPoints[i].type == "bbox") then
324             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
325             j = j+1
326          else
327             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
328          end
329       end
330    else
331       for i=1,#listPoints do
332          if(listPoints[i].type == "bbox") then
333             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
334          else
335             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
336          end
337       end
338    end
339    return output
340 end
341
342 -- print points to mesh
343 function printPointsMP(chaine,mode,points,bbox,scale)
344    listPoints = buildList(chaine, mode)
345    if(bbox == "bbox" ) then
346       listPoints = buildBoundingBox(listPoints)
347    end
348    output = tracePointsMP(listPoints,points)
349    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
350    tex.sprint(output)
351 end
352
353
354 -- print points to mesh
355 function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
356    listPoints = buildList(chaine, mode)
357    if(bbox == "bbox" ) then
358       listPoints = buildBoundingBox(listPoints)
359    end
360    output = tracePointsMP(listPoints,points)
361    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
362    tex.sprint(output)
363 end
364
365 -- print points to mesh
366 function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
367    listPoints = buildList(chaine, mode)
368    if(bbox == "bbox" ) then
369       listPoints = buildBoundingBox(listPoints)
370    end
371    output = tracePointsTikZ(listPoints,points,color,colorBbox)
372    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
373    tex.sprint(output)
374 end
375
376
377 -- print points to mesh
378 function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
379    listPoints = buildList(chaine, mode)
380    if(bbox == "bbox" ) then
381       listPoints = buildBoundingBox(listPoints)
382    end
383    output = tracePointsTikZ(listPoints,points,color,colorBbox)
384    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
385    tex.sprint(output)
386 end
387
388
389 -- buildMesh
390 function buildRect(largeur,a,b,nbrA, nbrB)
391    listPoints = rectangleList(a,b,nbrA,nbrB)
392    triangulation = BowyerWatson(listPoints,"none")
393    traceTikZ(listPoints, triangulation,largeur,"none")
394 end
395
396
397 --
398 function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
399    output = ""
400    -- build the triangulation
401    triangulation = BowyerWatson(listPoints,bbox)
402    badTriangles = buildBadTriangles(P,triangulation)
403    for i=1,#listPoints do
404       output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
405    end
406    if(step == "badT") then
407       -- draw all triangle
408       for i=1,#triangulation do
409          PointI = listPoints[triangulation[i][1]]
410          PointJ = listPoints[triangulation[i][2]]
411          PointK = listPoints[triangulation[i][3]]
412          if(triangulation[i].type == "bbox") then
413             output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
414          else
415             output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
416          end
417       end
418       -- draw and fill the bad triangle
419       for i=1,#badTriangles do
420          PointI = listPoints[triangulation[badTriangles[i]][1]]
421          PointJ = listPoints[triangulation[badTriangles[i]][2]]
422          PointK = listPoints[triangulation[badTriangles[i]][3]]
423          output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
424       end
425       -- draw the circoncircle
426       for i=1,#badTriangles do
427          PointI = listPoints[triangulation[badTriangles[i]][1]]
428          PointJ = listPoints[triangulation[badTriangles[i]][2]]
429          PointK = listPoints[triangulation[badTriangles[i]][3]]
430          center, radius = circoncircle(PointI, PointJ, PointK)
431          output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
432       end
433       -- mark the points
434       j=1
435       for i=1,#listPoints do
436          if(listPoints[i].type == "bbox") then
437             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
438             j = j+1
439          else
440             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
441          end
442       end
443       -- mark the point to add
444       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
445    elseif(step == "cavity") then
446       polygon = buildCavity(badTriangles, triangulation)
447       polyNew = cleanPoly(polygon)
448       -- remove the bad triangles
449       for j=1,#badTriangles do
450          table.remove(triangulation,badTriangles[j]-(j-1))
451       end
452       -- draw the triangles
453       for i=1,#triangulation do
454          PointI = listPoints[triangulation[i][1]]
455          PointJ = listPoints[triangulation[i][2]]
456          PointK = listPoints[triangulation[i][3]]
457          if(triangulation[i].type == "bbox") then
458             output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
459          else
460             output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
461          end
462       end
463       -- fill and draw the cavity
464       path = ""
465       for i=1,#polyNew do
466          PointI = listPoints[polyNew[i]]
467          path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
468       end
469       output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
470       -- mark the points of the mesh
471       j=1
472       for i=1,#listPoints do
473          if(listPoints[i].type == "bbox") then
474             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
475             j=j+1
476          else
477             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
478          end
479       end
480       -- mark the adding point
481       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
482    elseif(step == "newT") then
483       polygon = buildCavity(badTriangles, triangulation)
484       polyNew = cleanPoly(polygon)
485       -- remove the bad triangles
486       for j=1,#badTriangles do
487          table.remove(triangulation,badTriangles[j]-(j-1))
488       end
489       -- draw the triangle of the triangulation
490       for i=1,#triangulation do
491          PointI = listPoints[triangulation[i][1]]
492          PointJ = listPoints[triangulation[i][2]]
493          PointK = listPoints[triangulation[i][3]]
494          if(triangulation[i].type == "bbox") then
495             output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
496          else
497             output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
498          end
499       end
500       -- fill and draw the cavity
501       path = ""
502       for i=1,#polyNew do
503          PointI = listPoints[polyNew[i]]
504          path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
505       end
506       output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
507       -- draw the new triangles composed by the edges of the polygon and the added point
508       for i=1,#polygon do
509          output = output .. "\\draw[color=TeXCluaMeshNewTikZ, thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y ..");"
510          output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
511          output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
512       end
513       -- mark points
514       j=1
515       for i=1,#listPoints do
516          if(listPoints[i].type == "bbox") then
517             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
518             j=j+1
519          else
520             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
521          end
522       end
523       -- mark the added point
524       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
525    end
526    return output
527 end
528
529 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
530    output = "";
531    output = output .. "pair MeshPoints[];"
532    -- build the triangulation
533    triangulation = BowyerWatson(listPoints,bbox)
534    badTriangles = buildBadTriangles(P,triangulation)
535    for i=1,#listPoints do
536       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
537    end
538    if(step == "badT") then
539       -- draw all triangle
540       for i=1,#triangulation do
541          PointI = listPoints[triangulation[i][1]]
542          PointJ = listPoints[triangulation[i][2]]
543          PointK = listPoints[triangulation[i][3]]
544          if(triangulation[i].type == "bbox") then
545             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
546          else
547             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
548          end
549       end
550       -- draw and fill the bad triangle
551       for i=1,#badTriangles do
552          PointI = listPoints[triangulation[badTriangles[i]][1]]
553          PointJ = listPoints[triangulation[badTriangles[i]][2]]
554          PointK = listPoints[triangulation[badTriangles[i]][3]]
555          output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
556          output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
557       end
558       -- draw the circoncircle
559       for i=1,#badTriangles do
560          PointI = listPoints[triangulation[badTriangles[i]][1]]
561          PointJ = listPoints[triangulation[badTriangles[i]][2]]
562          PointK = listPoints[triangulation[badTriangles[i]][3]]
563          center, radius = circoncircle(PointI, PointJ, PointK)
564          output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
565       end
566       -- mark the points
567       j=1
568       for i=1,#listPoints do
569          if(listPoints[i].type == "bbox") then
570             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
571             j=j+1
572          else
573             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
574          end
575       end
576       -- mark the point to add
577       output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
578    elseif(step == "cavity") then
579       polygon = buildCavity(badTriangles, triangulation)
580       polyNew = cleanPoly(polygon)
581       -- remove the bad triangles
582       for j=1,#badTriangles do
583          table.remove(triangulation,badTriangles[j]-(j-1))
584       end
585       -- draw the triangles
586       for i=1,#triangulation do
587          PointI = listPoints[triangulation[i][1]]
588          PointJ = listPoints[triangulation[i][2]]
589          PointK = listPoints[triangulation[i][3]]
590          if(triangulation[i].type == "bbox") then
591             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
592          else
593             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
594          end
595       end
596       -- fill and draw the cavity
597       path = ""
598       for i=1,#polyNew do
599          PointI = listPoints[polyNew[i]]
600          path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
601       end
602       output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
603       output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew  withpen pencircle scaled 1pt;"
604       -- mark the points of the mesh
605       j=1
606       for i=1,#listPoints do
607          if(listPoints[i].type == "bbox") then
608             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
609             j=j+1
610          else
611             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
612          end
613       end
614       -- mark the adding point
615       output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
616    elseif(step == "newT") then
617       polygon = buildCavity(badTriangles, triangulation)
618       polyNew = cleanPoly(polygon)
619       -- remove the bad triangles
620       for j=1,#badTriangles do
621          table.remove(triangulation,badTriangles[j]-(j-1))
622       end
623       -- draw the triangle of the triangulation
624       for i=1,#triangulation do
625          PointI = listPoints[triangulation[i][1]]
626          PointJ = listPoints[triangulation[i][2]]
627          PointK = listPoints[triangulation[i][3]]
628          if(triangulation[i].type == "bbox") then
629             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
630          else
631             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
632          end
633       end
634       -- fill  the cavity
635       path = ""
636       for i=1,#polyNew do
637          PointI = listPoints[polyNew[i]]
638          path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
639       end
640       output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
641       -- draw the new triangles composed by the edges of the polygon and the added point
642       for i=1,#polygon do
643          output = output .. "draw".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ")*u -- (" .. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y ..")*u withcolor \\luameshmpcolorNew  withpen pencircle scaled 1pt;"
644          output = output .. "draw".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ")*u -- (" .. P.x .. "," .. P.y ..")*u withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
645          output = output .. "draw".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ")*u -- (" .. P.x .. "," .. P.y ..")*u withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
646       end
647       -- mark points
648       j=1
649       for i=1,#listPoints do
650          if(listPoints[i].type == "bbox") then
651             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
652             j=j+1
653          else
654             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
655          end
656       end
657       -- mark the added point
658       output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
659    end
660    return output
661 end
662
663
664 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
665    if(mode=="int") then
666       Sx,Sy=string.match(point,"%((.+),(.+)%)")
667       P = {x=Sx, y=Sy}
668       listPoints = buildList(chaine, mode)
669    else
670       -- point is a number
671       P, listPoints = buildListExt(chaine,tonumber(point))
672    end
673    output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
674    output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
675    tex.sprint(output)
676 end
677
678 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
679    if(mode=="int") then
680       Sx,Sy=string.match(point,"%((.+),(.+)%)")
681       P = {x=Sx, y=Sy}
682       listPoints = buildList(chaine, mode)
683    else
684       -- point is a number
685       P, listPoints = buildListExt(chaine,tonumber(point))
686    end
687    output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
688    output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
689    tex.sprint(output)
690 end
691
692 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
693    if(mode=="int") then
694       Sx,Sy=string.match(point,"%((.+),(.+)%)")
695       P = {x=Sx, y=Sy}
696       listPoints = buildList(chaine, mode)
697    else
698       -- point is a number
699       P, listPoints = buildListExt(chaine,tonumber(point))
700    end
701    output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
702    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
703    tex.sprint(output)
704 end
705
706 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
707    if(mode=="int") then
708       Sx,Sy=string.match(point,"%((.+),(.+)%)")
709       P = {x=Sx, y=Sy}
710       listPoints = buildList(chaine, mode)
711    else
712       -- point is a number
713       P, listPoints = buildListExt(chaine,tonumber(point))
714    end
715    output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
716    output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
717    tex.sprint(output)
718 end
719
720
721 function drawGmshMP(file,points,scale)
722    listPoints,triangulation = readGmsh(file)
723    output = traceMeshMP(listPoints,triangulation,points)
724    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
725    tex.sprint(output)
726 end
727
728 function drawGmshMPinc(file,beginning,ending,points,scale)
729    listPoints,triangulation = readGmsh(file)
730    output = traceMeshMP(listPoints,triangulation,points)
731    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
732    tex.sprint(output)
733 end
734
735
736
737 --
738 function drawGmshTikZ(file,points,scale,color)
739    listPoints,triangulation = readGmsh(file)
740    output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
741    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
742    tex.sprint(output)
743 end
744
745 --
746 function drawGmshTikZinc(file,beginning, ending,points,scale,color)
747    listPoints,triangulation = readGmsh(file)
748    output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
749    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
750    tex.sprint(output)
751 end
752
753
754 -- buildVoronoi with MP
755 function gmshVoronoiMP(file,points,scale,tri,styleD,styleV)
756    listPoints,triangulation = readGmsh(file)
757    listVoronoi = buildVoronoi(listPoints, triangulation)
758    output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
759    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
760    tex.sprint(output)
761 end
762
763
764 -- buildVoronoi with TikZ
765 function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV)
766    listPoints,triangulation = readGmsh(file)
767    listVoronoi = buildVoronoi(listPoints, triangulation)
768    output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
769    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"   tex.sprint(output)
770 end
771
772
773 -- buildVoronoi with MP
774 function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV)
775    listPoints,triangulation = readGmsh(file)
776    listVoronoi = buildVoronoi(listPoints, triangulation)
777    output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
778    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
779    tex.sprint(output)
780 end
781
782
783 -- buildVoronoi with TikZ
784 function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV)
785    listPoints,triangulation = readGmsh(file)
786    listVoronoi = buildVoronoi(listPoints, triangulation)
787    output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
788    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
789    tex.sprint(output)
790 end

Licence Creative Commons Les fichiers de Syracuse sont mis à disposition (sauf mention contraire) selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.