X-Git-Url: https://melusine.eu.org/syracuse/G/git/?a=blobdiff_plain;f=luamesh.lua;h=4d255a11b6820c2b502b6f0742af3dc011f220a3;hb=a00e38bda1dd258080ec6a649d61b1f577ccb71a;hp=945d9cc443c9eafc02b439815e374011eeb895a5;hpb=8dac495f9a49c66620e9e105e9cc16b5243dd8f7;p=delaunay.git diff --git a/luamesh.lua b/luamesh.lua index 945d9cc..4d255a1 100644 --- a/luamesh.lua +++ b/luamesh.lua @@ -6,9 +6,9 @@ function BowyerWatson (listPoints,bbox) -- add four points to listPoints to have a bounding box listPoints = buildBoundingBox(listPoints) -- the first triangle - triangulation[1] = {lgth+1, lgth+2, lgth+3} + triangulation[1] = {lgth+1, lgth+2, lgth+3,type="bbox"} -- the second triangle - triangulation[2] = {lgth+1, lgth+3, lgth+4} + triangulation[2] = {lgth+1, lgth+3, lgth+4,type="bbox"} -- add points one by one for i=1,lgth do -- find the triangles which the circumcircle contained the point to add @@ -21,7 +21,11 @@ function BowyerWatson (listPoints,bbox) end -- build the new triangles and add them to triangulation for j=1,#polygon do - table.insert(triangulation,{polygon[j][1],polygon[j][2],i}) + if((polygon[j][1]>lgth) or (polygon[j][2]>lgth) or (i>lgth)) then + table.insert(triangulation,{polygon[j][1],polygon[j][2],i,type="bbox"}) + else + table.insert(triangulation,{polygon[j][1],polygon[j][2],i,type="in"}) + end end end -- end adding points of the listPoints -- remove bounding box @@ -64,10 +68,10 @@ function buildBoundingBox(listPoints) ymin = ymin - eps ymax = ymax + eps -- add points of the bounding box in last positions - table.insert(listPoints,{x=xmin,y=ymin}) - table.insert(listPoints,{x=xmin,y=ymax}) - table.insert(listPoints,{x=xmax,y=ymax}) - table.insert(listPoints,{x=xmax,y=ymin}) + table.insert(listPoints,{x=xmin,y=ymin,type="bbox"}) + table.insert(listPoints,{x=xmin,y=ymax,type="bbox"}) + table.insert(listPoints,{x=xmax,y=ymax,type="bbox"}) + table.insert(listPoints,{x=xmax,y=ymin,type="bbox"}) return listPoints end @@ -203,6 +207,81 @@ function circoncircle(M, N, P) return Out, rad -- (center [Point], R [float]) end +-- compute the list of the circumcircle of a triangulation +function listCircumCenter(listPoints,triangulation) + list = {} + for j=1,#triangulation do + A = listPoints[triangulation[j][1]] + B = listPoints[triangulation[j][2]] + C = listPoints[triangulation[j][3]] + center, radius = circoncircle(A,B,C) + table.insert(list,{x=center.x,y=center.y,r=radius}) + end + return list +end + +-- find the three neighbour triangles of T +function findNeighbour(T,i,triangulation) + -- T : triangle + -- i : index of T in triangualation + -- triangulation + + list = {} + -- define the three edge + e1 = {T[1],T[2]} + e2 = {T[2],T[3]} + e3 = {T[3],T[1]} + for j=1,#triangulation do + if j~= i then + if(edgeInTriangle(e1,triangulation[j])) then + table.insert(list,j) + end + if(edgeInTriangle(e2,triangulation[j])) then + table.insert(list,j) + end + if(edgeInTriangle(e3,triangulation[j])) then + table.insert(list,j) + end + end + end + return list +end + +-- test if edge are the same (reverse) +function equalEdge(e1,e2) + if(((e1[1] == e2[1]) and (e1[2] == e2[2])) or ((e1[1] == e2[2]) and (e1[2] == e2[1]))) then + return true + else + return false + end +end + +-- test if the edge belongs to the list +function edgeInList(e,listE) + output = false + for i=1,#listE do + if(equalEdge(e,listE[i])) then + output = true + end + end + return output +end + +-- build the edges of the Voronoi diagram with a given triangulation +function buildVoronoi(listPoints, triangulation) + listCircumCircle = listCircumCenter(listPoints, triangulation) + listVoronoi = {} + for i=1,#listCircumCircle do + listN = findNeighbour(triangulation[i],i,triangulation) + for j=1,#listN do + edge = {i,listN[j]} + if( not edgeInList(edge, listVoronoi)) then + table.insert(listVoronoi, edge) + end + end + end + return listVoronoi +end -------------------------- TeX -- build the list of points @@ -248,18 +327,106 @@ function rectangleList(a,b,nbrA,nbrB) return listPoints end + +-- trace Voronoi with MP +function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri) + listCircumC = listCircumCenter(listPoints,triangulation) + output = ""; + output = output .. " pair MeshPoints[];" + for i=1,#listPoints do + output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;" + end + output = output .. " pair CircumCenters[];" + for i=1,#listCircumC do + output = output .. "CircumCenters[".. i .. "] = (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ")*u;" + end + if(tri=="show") then + for i=1,#triangulation do + PointI = listPoints[triangulation[i][1]] + PointJ = listPoints[triangulation[i][2]] + PointK = listPoints[triangulation[i][3]] + if(triangulation[i].type == "bbox") then + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;" + else + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;" + end + end + end + for i=1,#listVoronoi do + PointI = listCircumC[listVoronoi[i][1]] + PointJ = listCircumC[listVoronoi[i][2]] + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u withcolor \\luameshmpcolorVoronoi;" + end + if(points=="points") then + j=1 + for i=1,#listPoints do + if(listPoints[i].type == "bbox") then + output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;" + j=j+1 + else + output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;" + end + end + for i=1,#listCircumC do + output = output .. "dotlabel.llft (btex $\\CircumPoint_{" .. i .. "}$ etex, (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u ) withcolor \\luameshmpcolorVoronoi ;" + end + else + j=1 + for i=1,#listPoints do + if(listPoints[i].type == "bbox") then + output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;" + j=j+1 + else + output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;" + end + end + for i=1,#listCircumC do + output = output .. "drawdot (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u withcolor \\luameshmpcolorVoronoi withpen pencircle scaled 3;" + end + end + + return output +end + + + +-- buildVoronoi with MP +function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri) + listPoints = buildList(chaine, mode) + triangulation = BowyerWatson(listPoints,bbox) + listVoronoi = buildVoronoi(listPoints, triangulation) + output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri) + output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" + tex.sprint(output) +end + + + -- trace a triangulation with TikZ -function traceMeshTikZ(listPoints, triangulation,points,color) +function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox) output = "" + for i=1,#listPoints do + output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");" + end for i=1,#triangulation do PointI = listPoints[triangulation[i][1]] PointJ = listPoints[triangulation[i][2]] PointK = listPoints[triangulation[i][3]] - output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + if(triangulation[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + else + output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + end end if(points=="points") then + j=1 for i=1,#listPoints do - output = output .. "\\draw[color=".."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" + if(listPoints[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};" + j=j+1 + else + output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" + end end end return output @@ -267,54 +434,179 @@ end -- trace a triangulation with MP -function traceMeshMP(listPoints, triangulation,points,color) +function traceMeshMP(listPoints, triangulation,points) output = ""; output = output .. " pair MeshPoints[];" for i=1,#listPoints do - output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");" + output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;" end for i=1,#triangulation do PointI = listPoints[triangulation[i][1]] PointJ = listPoints[triangulation[i][2]] PointK = listPoints[triangulation[i][3]] - output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{"..color.. "};" + if(triangulation[i].type == "bbox") then + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;" + else + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;" + end end if(points=="points") then + j=1 for i=1,#listPoints do - output = output .. "dotlabel.llft( btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u) withcolor \\mpcolor{"..color.. "};" + if(listPoints[i].type == "bbox") then + output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;" + j=j+1 + else + output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;" + end end end return output end +-- buildMesh with MP +function buildMeshMPBW(chaine,mode,points,bbox,scale) + listPoints = buildList(chaine, mode) + triangulation = BowyerWatson(listPoints,bbox) + output = traceMeshMP(listPoints, triangulation,points) + output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" + tex.sprint(output) +end --- buildMesh with TikZ -function buildMeshTikZ(chaine,mode,points,bbox,full,scale,color) +-- buildMesh with MP include code +function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale) listPoints = buildList(chaine, mode) triangulation = BowyerWatson(listPoints,bbox) - output = traceMeshTikZ(listPoints, triangulation,points,color) - if(full=="full") then - output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" - end + output = traceMeshMP(listPoints, triangulation,points) + output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" tex.sprint(output) end +-- buildMesh with TikZ +function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox) + listPoints = buildList(chaine, mode) + triangulation = BowyerWatson(listPoints,bbox) + output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox) + output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" + tex.sprint(output) +end --- buildMesh with MP -function buildMeshMP(chaine,mode,points,bbox,full,scale,color) +-- buildMesh with TikZ +function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox) listPoints = buildList(chaine, mode) triangulation = BowyerWatson(listPoints,bbox) - output = traceMeshMP(listPoints, triangulation,points,color) - if(full=="full") then - output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" + output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox) + output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}" + tex.sprint(output) +end + + +-- print points of the mesh +function tracePointsMP(listPoints,points) + output = ""; + output = output .. " pair MeshPoints[];" + for i=1,#listPoints do + output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;" + end + if(points=="points") then + j=1 + for i=1,#listPoints do + if(listPoints[i].type == "bbox") then + output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;" + j=j+1 + else + output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;" + end + end + else + for i=1,#listPoints do + if(listPoints[i].type == "bbox") then + output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;" + else + output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;" + end + end + end + return output +end + +-- print points of the mesh +function tracePointsTikZ(listPoints,points,color,colorBbox) + output = ""; + for i=1,#listPoints do + output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");" + end + if(points=="points") then + j=1 + for i=1,#listPoints do + if(listPoints[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};" + j = j+1 + else + output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" + end + end else - output = "u:="..scale.. ";".. output + for i=1,#listPoints do + if(listPoints[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;" + else + output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;" + end + end + end + return output +end + +-- print points to mesh +function printPointsMP(chaine,mode,points,bbox,scale) + listPoints = buildList(chaine, mode) + if(bbox == "bbox" ) then + listPoints = buildBoundingBox(listPoints) + end + output = tracePointsMP(listPoints,points) + output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" + tex.sprint(output) +end + + +-- print points to mesh +function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale) + listPoints = buildList(chaine, mode) + if(bbox == "bbox" ) then + listPoints = buildBoundingBox(listPoints) + end + output = tracePointsMP(listPoints,points) + output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" + tex.sprint(output) +end + +-- print points to mesh +function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox) + listPoints = buildList(chaine, mode) + if(bbox == "bbox" ) then + listPoints = buildBoundingBox(listPoints) + end + output = tracePointsTikZ(listPoints,points,color,colorBbox) + output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" + tex.sprint(output) +end + + +-- print points to mesh +function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox) + listPoints = buildList(chaine, mode) + if(bbox == "bbox" ) then + listPoints = buildBoundingBox(listPoints) end + output = tracePointsTikZ(listPoints,points,color,colorBbox) + output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}" tex.sprint(output) end + -- buildMesh function buildRect(largeur,a,b,nbrA, nbrB) listPoints = rectangleList(a,b,nbrA,nbrB) @@ -322,47 +614,69 @@ function buildRect(largeur,a,b,nbrA, nbrB) traceTikZ(listPoints, triangulation,largeur,"none") end +local function shallowCopy(original) + local copy = {} + for key, value in pairs(original) do + copy[key] = value + end + return copy +end -- function give a real polygon without repeting points function cleanPoly(polygon) polyNew = {} - e1 = polygon[1][1] - e2 = polygon[1][2] + polyCopy = shallowCopy(polygon) + e1 = polyCopy[1][1] + e2 = polyCopy[1][2] table.insert(polyNew, e1) table.insert(polyNew, e2) + table.remove(polyCopy,1) j = 2 - for i=2,#polygon do - bool1 = (polygon[i][1] == polyNew[j]) - bool2 = (polygon[i][2] == polyNew[j]) - if(bool1 or bool2) then -- the edge has a common point with polyNew[j] - if(not bool1) then - table.insert(polyNew, polygon[i][1]) - j = j+1 - elseif(not bool2) then - table.insert(polyNew, polygon[i][2]) - j = j+1 + while #polyCopy>1 do + i=1 + find = false + while (i<=#polyCopy and find==false) do + bool1 = (polyCopy[i][1] == polyNew[j]) + bool2 = (polyCopy[i][2] == polyNew[j]) + if(bool1 or bool2) then -- the edge has a common point with polyNew[j] + if(not bool1) then + table.insert(polyNew, polyCopy[i][1]) + find = true + table.remove(polyCopy,i) + j = j+1 + elseif(not bool2) then + table.insert(polyNew, polyCopy[i][2]) + find = true + table.remove(polyCopy,i) + j = j+1 + end end + i=i+1 end end return polyNew end -- -function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCircle) - Sx,Sy=string.match(point,"%((.+),(.+)%)") - P = {x=Sx, y=Sy} +function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox) output = "" - listPoints = buildList(chaine, "int") -- build the triangulation - triangulation = BowyerWatson(listPoints,"none") + triangulation = BowyerWatson(listPoints,bbox) badTriangles = buildBadTriangles(P,triangulation) + for i=1,#listPoints do + output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");" + end if(step == "badT") then -- draw all triangle for i=1,#triangulation do PointI = listPoints[triangulation[i][1]] PointJ = listPoints[triangulation[i][2]] PointK = listPoints[triangulation[i][3]] - output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + if(triangulation[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + else + output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + end end -- draw and fill the bad triangle for i=1,#badTriangles do @@ -380,8 +694,14 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");" end -- mark the points + j=1 for i=1,#listPoints do - output = output .. "\\draw[color ="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" + if(listPoints[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};" + j = j+1 + else + output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" + end end -- mark the point to add output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};" @@ -397,7 +717,11 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi PointI = listPoints[triangulation[i][1]] PointJ = listPoints[triangulation[i][2]] PointK = listPoints[triangulation[i][3]] - output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + if(triangulation[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + else + output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + end end -- fill and draw the cavity path = "" @@ -407,8 +731,14 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi end output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;" -- mark the points of the mesh + j=1 for i=1,#listPoints do - output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" + if(listPoints[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};" + j=j+1 + else + output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" + end end -- mark the adding point output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};" @@ -424,7 +754,11 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi PointI = listPoints[triangulation[i][1]] PointJ = listPoints[triangulation[i][2]] PointK = listPoints[triangulation[i][3]] - output = output .. "\\draw[color ="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + if(triangulation[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + else + output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + end end -- fill and draw the cavity path = "" @@ -440,8 +774,14 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");" end -- mark points + j=1 for i=1,#listPoints do - output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" + if(listPoints[i].type == "bbox") then + output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};" + j=j+1 + else + output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" + end end -- mark the added point output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};" @@ -449,14 +789,14 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi return output end -function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCircle,bbox) +function TeXaddOnePointMPBW(listPoints,P,step,bbox) output = ""; output = output .. "pair MeshPoints[];" -- build the triangulation triangulation = BowyerWatson(listPoints,bbox) badTriangles = buildBadTriangles(P,triangulation) for i=1,#listPoints do - output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");" + output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;" end if(step == "badT") then -- draw all triangle @@ -464,15 +804,19 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc PointI = listPoints[triangulation[i][1]] PointJ = listPoints[triangulation[i][2]] PointK = listPoints[triangulation[i][3]] - output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{" .. color .."};" + if(triangulation[i].type == "bbox") then + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;" + else + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;" + end end -- draw and fill the bad triangle for i=1,#badTriangles do PointI = listPoints[triangulation[badTriangles[i]][1]] PointJ = listPoints[triangulation[badTriangles[i]][2]] PointK = listPoints[triangulation[badTriangles[i]][3]] - output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{" .. color .."};" - output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{" .. colorBack .."};" + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;" + output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;" end -- draw the circoncircle for i=1,#badTriangles do @@ -480,14 +824,20 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc PointJ = listPoints[triangulation[badTriangles[i]][2]] PointK = listPoints[triangulation[badTriangles[i]][3]] center, radius = circoncircle(PointI, PointJ, PointK) - output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\mpcolor{" .. colorCircle .."};" + output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;" end -- mark the points + j=1 for i=1,#listPoints do - output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\mpcolor{" .. color .."};" + if(listPoints[i].type == "bbox") then + output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;" + j=j+1 + else + output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;" + end end -- mark the point to add - output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\mpcolor{" .. colorNew .."};" + output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;" elseif(step == "cavity") then polygon = buildCavity(badTriangles, triangulation) polyNew = cleanPoly(polygon) @@ -500,7 +850,11 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc PointI = listPoints[triangulation[i][1]] PointJ = listPoints[triangulation[i][2]] PointK = listPoints[triangulation[i][3]] - output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{" .. color .."};" + if(triangulation[i].type == "bbox") then + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;" + else + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;" + end end -- fill and draw the cavity path = "" @@ -508,14 +862,20 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc PointI = listPoints[polyNew[i]] path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--" end - output = output .. "fill " .. path .. "cycle withcolor \\mpcolor{" .. colorBack .."};" - output = output .. "draw " .. path .. "cycle withcolor \\mpcolor{" .. colorNew .."} withpen pencircle scaled 1pt;" + output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;" + output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;" -- mark the points of the mesh + j=1 for i=1,#listPoints do - output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\mpcolor{" .. color .."};" + if(listPoints[i].type == "bbox") then + output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;" + j=j+1 + else + output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;" + end end -- mark the adding point - output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\mpcolor{" .. colorNew .."};" + output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;" elseif(step == "newT") then polygon = buildCavity(badTriangles, triangulation) polyNew = cleanPoly(polygon) @@ -528,7 +888,11 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc PointI = listPoints[triangulation[i][1]] PointJ = listPoints[triangulation[i][2]] PointK = listPoints[triangulation[i][3]] - output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{" .. color .."};" + if(triangulation[i].type == "bbox") then + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;" + else + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;" + end end -- fill the cavity path = "" @@ -536,19 +900,25 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc PointI = listPoints[polyNew[i]] path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--" end - output = output .. "fill " .. path .. "cycle withcolor \\mpcolor{" .. colorBack .."};" + output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;" -- draw the new triangles composed by the edges of the polygon and the added point for i=1,#polygon do - 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 \\mpcolor{" .. colorNew .."} withpen pencircle scaled 1pt;" - output = output .. "draw".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ")*u -- (" .. P.x .. "," .. P.y ..")*u withcolor \\mpcolor{" .. colorNew .."} withpen pencircle scaled 1pt;" - output = output .. "draw".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ")*u -- (" .. P.x .. "," .. P.y ..")*u withcolor \\mpcolor{" .. colorNew .."} withpen pencircle scaled 1pt;" + 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;" + 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;" + 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;" end -- mark points + j=1 for i=1,#listPoints do - output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\mpcolor{" .. color .."};" + if(listPoints[i].type == "bbox") then + output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;" + j=j+1 + else + output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;" + end end -- mark the added point - output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\mpcolor{ " .. colorNew .."};" + output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;" end return output end @@ -570,13 +940,35 @@ function buildListExt(chaine, stop) end -function TeXOnePointTikZ(chaine,point,step,color,colorBack,colorNew,colorCircle,scale) - output = TeXaddOnePointTikZ(chaine,point,step,color,colorBack,colorNew,colorCircle) +function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox) + if(mode=="int") then + Sx,Sy=string.match(point,"%((.+),(.+)%)") + P = {x=Sx, y=Sy} + listPoints = buildList(chaine, mode) + else + -- point is a number + P, listPoints = buildListExt(chaine,tonumber(point)) + end + output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox) output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}" tex.sprint(output) end -function TeXOnePointMP(chaine,point,step,color,colorBack,colorNew,colorCircle,scale,mode,picture,bbox) +function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox) + if(mode=="int") then + Sx,Sy=string.match(point,"%((.+),(.+)%)") + P = {x=Sx, y=Sy} + listPoints = buildList(chaine, mode) + else + -- point is a number + P, listPoints = buildListExt(chaine,tonumber(point)) + end + output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox) + output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}" + tex.sprint(output) +end + +function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox) if(mode=="int") then Sx,Sy=string.match(point,"%((.+),(.+)%)") P = {x=Sx, y=Sy} @@ -585,11 +977,21 @@ function TeXOnePointMP(chaine,point,step,color,colorBack,colorNew,colorCircle,sc -- point is a number P, listPoints = buildListExt(chaine,tonumber(point)) end - output = TeXaddOnePointMP(listPoints,P,step,color,colorBack,colorNew,colorCircle,bbox) - if(picture=="full") then - output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}" + output = TeXaddOnePointMPBW(listPoints,P,step,bbox) + output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}" + tex.sprint(output) +end + +function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox) + if(mode=="int") then + Sx,Sy=string.match(point,"%((.+),(.+)%)") + P = {x=Sx, y=Sy} + listPoints = buildList(chaine, mode) else - output = "u:="..scale..";".. output + -- point is a number + P, listPoints = buildListExt(chaine,tonumber(point)) end + output = TeXaddOnePointMPBW(listPoints,P,step,bbox) + output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" tex.sprint(output) end