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])
211 -------------------------- TeX
212 -- build the list of points
213 function buildList(chaine, mode)
214 -- if mode = int : the list is given in the chaine string (x1,y1);(x2,y2);...;(xn,yn)
215 -- if mode = ext : the list is given in a file line by line with space separation
217 if mode == "int" then
218 local points = string.explode(chaine, ";")
221 Sx,Sy=string.match(points[i],"%((.+),(.+)%)")
222 listPoints[i]={x=tonumber(Sx),y=tonumber(Sy)}
224 elseif mode == "ext" then
225 io.input(chaine) -- open the file
227 lines=string.explode(text,"\n+") -- all the lines
230 xy=string.explode(lines[i]," +")
231 listPoints[i]={x=tonumber(xy[1]),y=tonumber(xy[2])}
234 print("Non existing mode")
241 function rectangleList(a,b,nbrA,nbrB)
248 listPoints[k] = {x = (i-1)*stepA, y=(j-1)*stepB}
255 -- trace a triangulation with TikZ
256 function traceMeshTikZ(listPoints, triangulation,points,color)
258 for i=1,#triangulation do
259 PointI = listPoints[triangulation[i][1]]
260 PointJ = listPoints[triangulation[i][2]]
261 PointK = listPoints[triangulation[i][3]]
262 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
264 if(points=="points") then
265 for i=1,#listPoints do
266 output = output .. "\\draw[color=".."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
273 -- trace a triangulation with MP
274 function traceMeshMP(listPoints, triangulation,points)
276 output = output .. " pair MeshPoints[];"
277 for i=1,#listPoints do
278 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
281 for i=1,#triangulation do
282 PointI = listPoints[triangulation[i][1]]
283 PointJ = listPoints[triangulation[i][2]]
284 PointK = listPoints[triangulation[i][3]]
285 if(triangulation[i].type == "bbox") then
286 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
288 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
291 if(points=="points") then
292 for i=1,#listPoints do
293 if(listPoints[i].type == "bbox") then
294 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
296 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
305 -- buildMesh with TikZ
306 function buildMeshTikZ(chaine,mode,points,bbox,full,scale,color)
307 listPoints = buildList(chaine, mode)
308 triangulation = BowyerWatson(listPoints,bbox)
309 output = traceMeshTikZ(listPoints, triangulation,points,color)
310 if(full=="full") then
311 output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
318 function buildMeshMPBW(chaine,mode,points,bbox,scale)
319 listPoints = buildList(chaine, mode)
320 triangulation = BowyerWatson(listPoints,bbox)
321 output = traceMeshMP(listPoints, triangulation,points)
322 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
327 -- buildMesh with MP include code
328 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
329 listPoints = buildList(chaine, mode)
330 triangulation = BowyerWatson(listPoints,bbox)
331 output = traceMeshMP(listPoints, triangulation,points)
332 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
337 function buildRect(largeur,a,b,nbrA, nbrB)
338 listPoints = rectangleList(a,b,nbrA,nbrB)
339 triangulation = BowyerWatson(listPoints,"none")
340 traceTikZ(listPoints, triangulation,largeur,"none")
343 local function shallowCopy(original)
345 for key, value in pairs(original) do
351 -- function give a real polygon without repeting points
352 function cleanPoly(polygon)
354 polyCopy = shallowCopy(polygon)
357 table.insert(polyNew, e1)
358 table.insert(polyNew, e2)
359 table.remove(polyCopy,1)
364 while (i<=#polyCopy and find==false) do
366 bool1 = (polyCopy[i][1] == polyNew[j])
367 bool2 = (polyCopy[i][2] == polyNew[j])
368 if(bool1 or bool2) then -- the edge has a common point with polyNew[j]
370 table.insert(polyNew, polyCopy[i][1])
372 table.remove(polyCopy,i)
374 elseif(not bool2) then
375 table.insert(polyNew, polyCopy[i][2])
377 table.remove(polyCopy,i)
387 function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCircle)
388 Sx,Sy=string.match(point,"%((.+),(.+)%)")
391 listPoints = buildList(chaine, "int")
392 -- build the triangulation
393 triangulation = BowyerWatson(listPoints,"none")
394 badTriangles = buildBadTriangles(P,triangulation)
395 if(step == "badT") then
397 for i=1,#triangulation do
398 PointI = listPoints[triangulation[i][1]]
399 PointJ = listPoints[triangulation[i][2]]
400 PointK = listPoints[triangulation[i][3]]
401 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
403 -- draw and fill the bad triangle
404 for i=1,#badTriangles do
405 PointI = listPoints[triangulation[badTriangles[i]][1]]
406 PointJ = listPoints[triangulation[badTriangles[i]][2]]
407 PointK = listPoints[triangulation[badTriangles[i]][3]]
408 output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
410 -- draw the circoncircle
411 for i=1,#badTriangles do
412 PointI = listPoints[triangulation[badTriangles[i]][1]]
413 PointJ = listPoints[triangulation[badTriangles[i]][2]]
414 PointK = listPoints[triangulation[badTriangles[i]][3]]
415 center, radius = circoncircle(PointI, PointJ, PointK)
416 output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
419 for i=1,#listPoints do
420 output = output .. "\\draw[color ="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
422 -- mark the point to add
423 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
424 elseif(step == "cavity") then
425 polygon = buildCavity(badTriangles, triangulation)
426 polyNew = cleanPoly(polygon)
427 -- remove the bad triangles
428 for j=1,#badTriangles do
429 table.remove(triangulation,badTriangles[j]-(j-1))
431 -- draw the triangles
432 for i=1,#triangulation do
433 PointI = listPoints[triangulation[i][1]]
434 PointJ = listPoints[triangulation[i][2]]
435 PointK = listPoints[triangulation[i][3]]
436 output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
438 -- fill and draw the cavity
441 PointI = listPoints[polyNew[i]]
442 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
444 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
445 -- mark the points of the mesh
446 for i=1,#listPoints do
447 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
449 -- mark the adding point
450 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
451 elseif(step == "newT") then
452 polygon = buildCavity(badTriangles, triangulation)
453 polyNew = cleanPoly(polygon)
454 -- remove the bad triangles
455 for j=1,#badTriangles do
456 table.remove(triangulation,badTriangles[j]-(j-1))
458 -- draw the triangle of the triangulation
459 for i=1,#triangulation do
460 PointI = listPoints[triangulation[i][1]]
461 PointJ = listPoints[triangulation[i][2]]
462 PointK = listPoints[triangulation[i][3]]
463 output = output .. "\\draw[color ="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
465 -- fill and draw the cavity
468 PointI = listPoints[polyNew[i]]
469 path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
471 output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
472 -- draw the new triangles composed by the edges of the polygon and the added point
474 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 ..");"
475 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
476 output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
479 for i=1,#listPoints do
480 output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
482 -- mark the added point
483 output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
488 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
490 output = output .. "pair MeshPoints[];"
491 -- build the triangulation
492 triangulation = BowyerWatson(listPoints,bbox)
493 badTriangles = buildBadTriangles(P,triangulation)
494 for i=1,#listPoints do
495 output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
497 if(step == "badT") then
499 for i=1,#triangulation do
500 PointI = listPoints[triangulation[i][1]]
501 PointJ = listPoints[triangulation[i][2]]
502 PointK = listPoints[triangulation[i][3]]
503 if(triangulation[i].type == "bbox") then
504 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
506 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
509 -- draw and fill the bad triangle
510 for i=1,#badTriangles do
511 PointI = listPoints[triangulation[badTriangles[i]][1]]
512 PointJ = listPoints[triangulation[badTriangles[i]][2]]
513 PointK = listPoints[triangulation[badTriangles[i]][3]]
514 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
515 output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
517 -- draw the circoncircle
518 for i=1,#badTriangles do
519 PointI = listPoints[triangulation[badTriangles[i]][1]]
520 PointJ = listPoints[triangulation[badTriangles[i]][2]]
521 PointK = listPoints[triangulation[badTriangles[i]][3]]
522 center, radius = circoncircle(PointI, PointJ, PointK)
523 output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
526 for i=1,#listPoints do
527 if(listPoints[i].type == "bbox") then
528 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
530 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
533 -- mark the point to add
534 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
535 elseif(step == "cavity") then
536 polygon = buildCavity(badTriangles, triangulation)
537 polyNew = cleanPoly(polygon)
538 -- remove the bad triangles
539 for j=1,#badTriangles do
540 table.remove(triangulation,badTriangles[j]-(j-1))
542 -- draw the triangles
543 for i=1,#triangulation do
544 PointI = listPoints[triangulation[i][1]]
545 PointJ = listPoints[triangulation[i][2]]
546 PointK = listPoints[triangulation[i][3]]
547 if(triangulation[i].type == "bbox") then
548 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
550 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
553 -- fill and draw the cavity
556 PointI = listPoints[polyNew[i]]
557 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
559 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
560 output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
561 -- mark the points of the mesh
562 for i=1,#listPoints do
563 if(listPoints[i].type == "bbox") then
564 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
566 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
569 -- mark the adding point
570 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
571 elseif(step == "newT") then
572 polygon = buildCavity(badTriangles, triangulation)
573 polyNew = cleanPoly(polygon)
574 -- remove the bad triangles
575 for j=1,#badTriangles do
576 table.remove(triangulation,badTriangles[j]-(j-1))
578 -- draw the triangle of the triangulation
579 for i=1,#triangulation do
580 PointI = listPoints[triangulation[i][1]]
581 PointJ = listPoints[triangulation[i][2]]
582 PointK = listPoints[triangulation[i][3]]
583 if(triangulation[i].type == "bbox") then
584 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
586 output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
592 PointI = listPoints[polyNew[i]]
593 path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
595 output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
596 -- draw the new triangles composed by the edges of the polygon and the added point
598 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;"
599 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;"
600 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;"
603 for i=1,#listPoints do
604 if(listPoints[i].type == "bbox") then
605 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
607 output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
610 -- mark the added point
611 output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
617 -- build the list of points extern and stop at nbr
618 function buildListExt(chaine, stop)
620 io.input(chaine) -- open the file
622 lines=string.explode(text,"\n+") -- all the lines
623 for i=1,tonumber(stop) do
624 xy=string.explode(lines[i]," +")
625 table.insert(listPoints,{x=tonumber(xy[1]),y=tonumber(xy[2])})
627 xy=string.explode(lines[stop+1]," +")
628 point={x=tonumber(xy[1]),y=tonumber(xy[2])}
629 return point, listPoints
633 function TeXOnePointTikZ(chaine,point,step,color,colorBack,colorNew,colorCircle,scale)
634 output = TeXaddOnePointTikZ(chaine,point,step,color,colorBack,colorNew,colorCircle)
635 output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
639 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
641 Sx,Sy=string.match(point,"%((.+),(.+)%)")
643 listPoints = buildList(chaine, mode)
646 P, listPoints = buildListExt(chaine,tonumber(point))
648 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
649 output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
653 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
655 Sx,Sy=string.match(point,"%((.+),(.+)%)")
657 listPoints = buildList(chaine, mode)
660 P, listPoints = buildListExt(chaine,tonumber(point))
662 output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
663 output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"