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)
-- 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
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]]
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)
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)
-- 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
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)