X-Git-Url: https://melusine.eu.org/syracuse/G/git/?p=delaunay.git;a=blobdiff_plain;f=luamesh.lua;h=10a2084193c4956b5d9b1af658aeb75eb3c92d2b;hp=402e33dec6661c91774c205d5c04d1c2b364a459;hb=fe3a5df51411d6ea20f72115641db9bc7d19a466;hpb=7bc85345ad42b4b24478accec113804862650422 diff --git a/luamesh.lua b/luamesh.lua index 402e33d..10a2084 100644 --- a/luamesh.lua +++ b/luamesh.lua @@ -1,6 +1,14 @@ require "luamesh-polygon" require "luamesh-tex" +local function shallowCopy(original) + local copy = {} + for key, value in pairs(original) do + copy[key] = value + end + return copy +end + -- Bowyer and Watson algorithm -- Delaunay meshing function BowyerWatson (listPoints,bbox) @@ -15,7 +23,7 @@ function BowyerWatson (listPoints,bbox) -- add points one by one for i=1,lgth do -- find the triangles which the circumcircle contained the point to add - badTriangles = buildBadTriangles(listPoints[i],triangulation) + badTriangles = buildBadTriangles(listPoints[i],triangulation,listPoints) -- build the polygon of the cavity containing the point to add polygon = buildCavity(badTriangles, triangulation) -- remove the bad triangles @@ -129,8 +137,9 @@ function removeBoundingBox(triangulation,lgth) end -function buildBadTriangles(point, triangulation) +function buildBadTriangles(point, triangulation,listPoints) local badTriangles = {} + print(#triangulation) for j=1,#triangulation do -- for all triangles A = listPoints[triangulation[j][1]] B = listPoints[triangulation[j][2]] @@ -316,7 +325,6 @@ function buildVoronoi(listPoints, triangulation) return listVoronoi end --------------------------- TeX -- build the list of points function buildList(chaine, mode) -- if mode = int : the list is given in the chaine string (x1,y1);(x2,y2);...;(xn,yn) @@ -345,6 +353,34 @@ function buildList(chaine, mode) end +-- function to add points on a polygon to respect +-- the size of unit mesh +function addPointsPolygon(polygon,h) + local newPolygon = shallowCopy(polygon) + k=0 -- to follow in the newPolygon + for i=1,#polygon do + k = k+1 + ip = (i)%(#polygon)+1 + dist = math.sqrt(math.pow(polygon[i].x-polygon[ip].x,2) + math.pow(polygon[i].y-polygon[ip].y,2)) + -- if the distance between two ponits of the polygon is greater than 1.5*h + if(dist>=2*h) then + n = math.floor(dist/h) + print(polygon[i].x,polygon[i].y,polygon[ip].x,polygon[ip].y) + step = dist/(n+1) + print("step="..step) + print("n="..n) + for j=1,n do + print(j*step) + a = {x=polygon[i].x+j*step*(polygon[ip].x-polygon[i].x)/dist,y=polygon[i].y+j*step*(polygon[ip].y-polygon[i].y)/dist} + print("new = "..a.x.." "..a.y) + table.insert(newPolygon,k+j,a) + end + k=k+n + end + end + return newPolygon +end + -- function to build a gridpoints from the bounding box -- with a prescribed function buildGrid(listPoints,h) @@ -373,13 +409,13 @@ end -- function to add points from a grid to the interior of a polygon -function addGridPoints(polygon, grid) - local listPoints = polygon +function addGridPoints(polygon, grid,h) + local listPoints = shallowCopy(polygon) k = #polygon for i=1, #grid do --print(grid[i].x,grid[i].y) --print(isInside(polygon,grid[i])) - if(isInside(polygon,grid[i])) then + if(isInside(polygon,grid[i],h)) then k=k+1 listPoints[k] = grid[i] end @@ -388,13 +424,6 @@ function addGridPoints(polygon, grid) 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)