fonction meshPolygon pour MetaPost faite, ajout de dotpoints pour drawMesh (toujours...
[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    if(points=="dotpoints") then
245       j=1
246       for i=1,#listPoints do
247          if(listPoints[i].type == "bbox") then
248             output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
249             j=j+1
250          else
251             output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
252          end
253       end
254    end
255    return output
256 end
257
258
259 -- buildMesh with MP
260 function buildMeshMPBW(chaine,mode,points,bbox,scale)
261    listPoints = buildList(chaine, mode)
262    triangulation = BowyerWatson(listPoints,bbox)
263    output = traceMeshMP(listPoints, triangulation,points)
264    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
265    tex.sprint(output)
266 end
267
268 -- buildMesh with MP include code
269 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
270    listPoints = buildList(chaine, mode)
271    triangulation = BowyerWatson(listPoints,bbox)
272    output = traceMeshMP(listPoints, triangulation,points)
273    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
274    tex.sprint(output)
275 end
276
277 -- buildMesh with TikZ
278 function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
279    listPoints = buildList(chaine, mode)
280    triangulation = BowyerWatson(listPoints,bbox)
281    output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
282    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
283    tex.sprint(output)
284 end
285
286 -- buildMesh with TikZ
287 function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
288    listPoints = buildList(chaine, mode)
289    triangulation = BowyerWatson(listPoints,bbox)
290    output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
291    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
292    tex.sprint(output)
293 end
294
295
296 -- print points of the mesh
297 function tracePointsMP(listPoints,points)
298    output = "";
299    output = output .. " pair MeshPoints[];"
300    for i=1,#listPoints do
301       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
302    end
303    if(points=="points") then
304       j=1
305       for i=1,#listPoints do
306          if(listPoints[i].type == "bbox") then
307             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
308             j=j+1
309          else
310             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
311          end
312       end
313    else
314       for i=1,#listPoints do
315          if(listPoints[i].type == "bbox") then
316             output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
317          else
318             output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolor withpen pencircle scaled 3;"
319          end
320       end
321    end
322    return output
323 end
324
325 -- print points of the mesh
326 function tracePointsTikZ(listPoints,points,color,colorBbox)
327    output = "";
328    for i=1,#listPoints do
329       output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
330    end
331    if(points=="points") then
332       j=1
333       for i=1,#listPoints do
334          if(listPoints[i].type == "bbox") then
335             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
336             j = j+1
337          else
338             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
339          end
340       end
341    else
342       for i=1,#listPoints do
343          if(listPoints[i].type == "bbox") then
344             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
345          else
346             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
347          end
348       end
349    end
350    return output
351 end
352
353 -- print points to mesh
354 function printPointsMP(chaine,mode,points,bbox,scale)
355    listPoints = buildList(chaine, mode)
356    if(bbox == "bbox" ) then
357       listPoints = buildBoundingBox(listPoints)
358    end
359    output = tracePointsMP(listPoints,points)
360    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
361    tex.sprint(output)
362 end
363
364
365 -- print points to mesh
366 function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
367    listPoints = buildList(chaine, mode)
368    if(bbox == "bbox" ) then
369       listPoints = buildBoundingBox(listPoints)
370    end
371    output = tracePointsMP(listPoints,points)
372    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
373    tex.sprint(output)
374 end
375
376 -- print points to mesh
377 function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
378    listPoints = buildList(chaine, mode)
379    if(bbox == "bbox" ) then
380       listPoints = buildBoundingBox(listPoints)
381    end
382    output = tracePointsTikZ(listPoints,points,color,colorBbox)
383    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
384    tex.sprint(output)
385 end
386
387
388 -- print points to mesh
389 function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
390    listPoints = buildList(chaine, mode)
391    if(bbox == "bbox" ) then
392       listPoints = buildBoundingBox(listPoints)
393    end
394    output = tracePointsTikZ(listPoints,points,color,colorBbox)
395    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
396    tex.sprint(output)
397 end
398
399
400 -- buildMesh
401 function buildRect(largeur,a,b,nbrA, nbrB)
402    listPoints = rectangleList(a,b,nbrA,nbrB)
403    triangulation = BowyerWatson(listPoints,"none")
404    traceTikZ(listPoints, triangulation,largeur,"none")
405 end
406
407
408 --
409 function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
410    output = ""
411    -- build the triangulation
412    triangulation = BowyerWatson(listPoints,bbox)
413    badTriangles = buildBadTriangles(P,triangulation)
414    for i=1,#listPoints do
415       output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
416    end
417    if(step == "badT") then
418       -- draw all triangle
419       for i=1,#triangulation do
420          PointI = listPoints[triangulation[i][1]]
421          PointJ = listPoints[triangulation[i][2]]
422          PointK = listPoints[triangulation[i][3]]
423          if(triangulation[i].type == "bbox") then
424             output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
425          else
426             output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
427          end
428       end
429       -- draw and fill the bad triangle
430       for i=1,#badTriangles do
431          PointI = listPoints[triangulation[badTriangles[i]][1]]
432          PointJ = listPoints[triangulation[badTriangles[i]][2]]
433          PointK = listPoints[triangulation[badTriangles[i]][3]]
434          output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
435       end
436       -- draw the circoncircle
437       for i=1,#badTriangles do
438          PointI = listPoints[triangulation[badTriangles[i]][1]]
439          PointJ = listPoints[triangulation[badTriangles[i]][2]]
440          PointK = listPoints[triangulation[badTriangles[i]][3]]
441          center, radius = circoncircle(PointI, PointJ, PointK)
442          output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
443       end
444       -- mark the points
445       j=1
446       for i=1,#listPoints do
447          if(listPoints[i].type == "bbox") then
448             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
449             j = j+1
450          else
451             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
452          end
453       end
454       -- mark the point to add
455       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
456    elseif(step == "cavity") then
457       polygon = buildCavity(badTriangles, triangulation)
458       polyNew = cleanPoly(polygon)
459       -- remove the bad triangles
460       for j=1,#badTriangles do
461          table.remove(triangulation,badTriangles[j]-(j-1))
462       end
463       -- draw the triangles
464       for i=1,#triangulation do
465          PointI = listPoints[triangulation[i][1]]
466          PointJ = listPoints[triangulation[i][2]]
467          PointK = listPoints[triangulation[i][3]]
468          if(triangulation[i].type == "bbox") then
469             output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
470          else
471             output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
472          end
473       end
474       -- fill and draw the cavity
475       path = ""
476       for i=1,#polyNew do
477          PointI = listPoints[polyNew[i]]
478          path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
479       end
480       output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
481       -- mark the points of the mesh
482       j=1
483       for i=1,#listPoints do
484          if(listPoints[i].type == "bbox") then
485             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
486             j=j+1
487          else
488             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
489          end
490       end
491       -- mark the adding point
492       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
493    elseif(step == "newT") then
494       polygon = buildCavity(badTriangles, triangulation)
495       polyNew = cleanPoly(polygon)
496       -- remove the bad triangles
497       for j=1,#badTriangles do
498          table.remove(triangulation,badTriangles[j]-(j-1))
499       end
500       -- draw the triangle of the triangulation
501       for i=1,#triangulation do
502          PointI = listPoints[triangulation[i][1]]
503          PointJ = listPoints[triangulation[i][2]]
504          PointK = listPoints[triangulation[i][3]]
505          if(triangulation[i].type == "bbox") then
506             output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
507          else
508             output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
509          end
510       end
511       -- fill and draw the cavity
512       path = ""
513       for i=1,#polyNew do
514          PointI = listPoints[polyNew[i]]
515          path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
516       end
517       output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
518       -- draw the new triangles composed by the edges of the polygon and the added point
519       for i=1,#polygon do
520          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 ..");"
521          output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
522          output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
523       end
524       -- mark points
525       j=1
526       for i=1,#listPoints do
527          if(listPoints[i].type == "bbox") then
528             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
529             j=j+1
530          else
531             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
532          end
533       end
534       -- mark the added point
535       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
536    end
537    return output
538 end
539
540 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
541    output = "";
542    output = output .. "pair MeshPoints[];"
543    -- build the triangulation
544    triangulation = BowyerWatson(listPoints,bbox)
545    badTriangles = buildBadTriangles(P,triangulation)
546    for i=1,#listPoints do
547       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
548    end
549    if(step == "badT") then
550       -- draw all triangle
551       for i=1,#triangulation do
552          PointI = listPoints[triangulation[i][1]]
553          PointJ = listPoints[triangulation[i][2]]
554          PointK = listPoints[triangulation[i][3]]
555          if(triangulation[i].type == "bbox") then
556             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
557          else
558             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
559          end
560       end
561       -- draw and fill the bad triangle
562       for i=1,#badTriangles do
563          PointI = listPoints[triangulation[badTriangles[i]][1]]
564          PointJ = listPoints[triangulation[badTriangles[i]][2]]
565          PointK = listPoints[triangulation[badTriangles[i]][3]]
566          output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
567          output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
568       end
569       -- draw the circoncircle
570       for i=1,#badTriangles do
571          PointI = listPoints[triangulation[badTriangles[i]][1]]
572          PointJ = listPoints[triangulation[badTriangles[i]][2]]
573          PointK = listPoints[triangulation[badTriangles[i]][3]]
574          center, radius = circoncircle(PointI, PointJ, PointK)
575          output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
576       end
577       -- mark the points
578       j=1
579       for i=1,#listPoints do
580          if(listPoints[i].type == "bbox") then
581             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
582             j=j+1
583          else
584             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
585          end
586       end
587       -- mark the point to add
588       output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
589    elseif(step == "cavity") then
590       polygon = buildCavity(badTriangles, triangulation)
591       polyNew = cleanPoly(polygon)
592       -- remove the bad triangles
593       for j=1,#badTriangles do
594          table.remove(triangulation,badTriangles[j]-(j-1))
595       end
596       -- draw the triangles
597       for i=1,#triangulation do
598          PointI = listPoints[triangulation[i][1]]
599          PointJ = listPoints[triangulation[i][2]]
600          PointK = listPoints[triangulation[i][3]]
601          if(triangulation[i].type == "bbox") then
602             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
603          else
604             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
605          end
606       end
607       -- fill and draw the cavity
608       path = ""
609       for i=1,#polyNew do
610          PointI = listPoints[polyNew[i]]
611          path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
612       end
613       output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
614       output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew  withpen pencircle scaled 1pt;"
615       -- mark the points of the mesh
616       j=1
617       for i=1,#listPoints do
618          if(listPoints[i].type == "bbox") then
619             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
620             j=j+1
621          else
622             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
623          end
624       end
625       -- mark the adding point
626       output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
627    elseif(step == "newT") then
628       polygon = buildCavity(badTriangles, triangulation)
629       polyNew = cleanPoly(polygon)
630       -- remove the bad triangles
631       for j=1,#badTriangles do
632          table.remove(triangulation,badTriangles[j]-(j-1))
633       end
634       -- draw the triangle of the triangulation
635       for i=1,#triangulation do
636          PointI = listPoints[triangulation[i][1]]
637          PointJ = listPoints[triangulation[i][2]]
638          PointK = listPoints[triangulation[i][3]]
639          if(triangulation[i].type == "bbox") then
640             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
641          else
642             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
643          end
644       end
645       -- fill  the cavity
646       path = ""
647       for i=1,#polyNew do
648          PointI = listPoints[polyNew[i]]
649          path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
650       end
651       output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
652       -- draw the new triangles composed by the edges of the polygon and the added point
653       for i=1,#polygon do
654          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;"
655          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;"
656          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;"
657       end
658       -- mark points
659       j=1
660       for i=1,#listPoints do
661          if(listPoints[i].type == "bbox") then
662             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
663             j=j+1
664          else
665             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
666          end
667       end
668       -- mark the added point
669       output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
670    end
671    return output
672 end
673
674
675 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
676    if(mode=="int") then
677       Sx,Sy=string.match(point,"%((.+),(.+)%)")
678       P = {x=Sx, y=Sy}
679       listPoints = buildList(chaine, mode)
680    else
681       -- point is a number
682       P, listPoints = buildListExt(chaine,tonumber(point))
683    end
684    output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
685    output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
686    tex.sprint(output)
687 end
688
689 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
690    if(mode=="int") then
691       Sx,Sy=string.match(point,"%((.+),(.+)%)")
692       P = {x=Sx, y=Sy}
693       listPoints = buildList(chaine, mode)
694    else
695       -- point is a number
696       P, listPoints = buildListExt(chaine,tonumber(point))
697    end
698    output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
699    output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
700    tex.sprint(output)
701 end
702
703 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
704    if(mode=="int") then
705       Sx,Sy=string.match(point,"%((.+),(.+)%)")
706       P = {x=Sx, y=Sy}
707       listPoints = buildList(chaine, mode)
708    else
709       -- point is a number
710       P, listPoints = buildListExt(chaine,tonumber(point))
711    end
712    output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
713    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
714    tex.sprint(output)
715 end
716
717 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
718    if(mode=="int") then
719       Sx,Sy=string.match(point,"%((.+),(.+)%)")
720       P = {x=Sx, y=Sy}
721       listPoints = buildList(chaine, mode)
722    else
723       -- point is a number
724       P, listPoints = buildListExt(chaine,tonumber(point))
725    end
726    output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
727    output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
728    tex.sprint(output)
729 end
730
731
732 function drawGmshMP(file,points,scale)
733    listPoints,triangulation = readGmsh(file)
734    output = traceMeshMP(listPoints,triangulation,points)
735    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
736    tex.sprint(output)
737 end
738
739 function drawGmshMPinc(file,beginning,ending,points,scale)
740    listPoints,triangulation = readGmsh(file)
741    output = traceMeshMP(listPoints,triangulation,points)
742    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
743    tex.sprint(output)
744 end
745
746
747
748 --
749 function drawGmshTikZ(file,points,scale,color)
750    listPoints,triangulation = readGmsh(file)
751    output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
752    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
753    tex.sprint(output)
754 end
755
756 --
757 function drawGmshTikZinc(file,beginning, ending,points,scale,color)
758    listPoints,triangulation = readGmsh(file)
759    output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
760    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
761    tex.sprint(output)
762 end
763
764
765 -- buildVoronoi with MP
766 function gmshVoronoiMP(file,points,scale,tri,styleD,styleV)
767    listPoints,triangulation = readGmsh(file)
768    listVoronoi = buildVoronoi(listPoints, triangulation)
769    output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
770    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
771    tex.sprint(output)
772 end
773
774
775 -- buildVoronoi with TikZ
776 function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV)
777    listPoints,triangulation = readGmsh(file)
778    listVoronoi = buildVoronoi(listPoints, triangulation)
779    output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
780    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"   tex.sprint(output)
781 end
782
783
784 -- buildVoronoi with MP
785 function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV)
786    listPoints,triangulation = readGmsh(file)
787    listVoronoi = buildVoronoi(listPoints, triangulation)
788    output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
789    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
790    tex.sprint(output)
791 end
792
793
794 -- buildVoronoi with TikZ
795 function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV)
796    listPoints,triangulation = readGmsh(file)
797    listVoronoi = buildVoronoi(listPoints, triangulation)
798    output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
799    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
800    tex.sprint(output)
801 end
802
803
804 --------------------------------------------------
805 --         Meshing of a polygon                 --
806 --------------------------------------------------
807
808
809 function TeXMeshPolygonMP(polygon,listPoints, grid, step)
810
811 end
812
813 function  tracePolygonMP(polygon,points)
814    output = "";
815    output = output .. "pair polygon[];"
816    print(#polygon)
817    for i=1,#polygon do
818       output = output .. "polygon[".. i .. "] = (" .. polygon[i].x .. "," .. polygon[i].y .. ")*u;"
819    end
820    output = output .. "draw "
821    for i=1,#polygon do
822       output = output .. "(" .. polygon[i].x .. "," .. polygon[i].y .. ")*u -- "
823    end
824    output = output .. "cycle withcolor \\luameshmpcolorPoly withpen pencircle scaled 1pt;"
825    if(points=="points") then
826       for i=1,#polygon do
827          output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. polygon[i].x ..",".. polygon[i].y .. ")*u ) withcolor \\luameshmpcolorPoly ;"
828       end
829    end
830    if(points=="dotpoints") then
831          for i=1,#polygon do
832          output = output .. "drawdot  (" .. polygon[i].x ..",".. polygon[i].y .. ")*u  withcolor \\luameshmpcolorPoly withpen pencircle scaled 3;"
833       end
834    end
835    return output
836 end
837
838
839
840 function drawMeshPolygonMP(chaine,mode,h,step,
841                              points,scale)
842    local polygon = buildList(chaine, mode)
843    polygon = addPointsPolygon(polygon,h)
844    print(#polygon)
845    local grid = buildGrid(polygon,h)
846    print(#polygon)
847    local listPoints = addGridPoints(polygon,grid,h)
848    print(#polygon)
849    if(step=="polygon") then
850       -- the polygon
851       output = tracePolygonMP(polygon,points)
852    end
853    if(step=="grid") then
854       -- polygon + grid
855       output = tracePointsMP(grid,points)
856       output = output .. tracePolygonMP(polygon,points)
857    end
858    if(step=="points") then
859       -- polygon + only grid points inside the polygon
860       output = tracePointsMP(listPoints,points)
861       output = output .. tracePolygonMP(polygon,points)
862    end
863    if(step=="mesh") then
864       -- polygon + mesh
865       triangulation = BowyerWatson(listPoints,"none") -- no bbox
866       output = traceMeshMP(listPoints,triangulation,points)
867       output = output .. tracePolygonMP(polygon,points)
868    end
869
870    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
871    tex.sprint(output)
872 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.