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)
local triangulation = {}
- local lgth = #listPoints
+ lgth = #listPoints
-- add four points to listPoints to have a bounding box
listPoints = buildBoundingBox(listPoints)
-- the first triangle
-- 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 = {}
for j=1,#triangulation do -- for all triangles
A = listPoints[triangulation[j][1]]
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)
+ step = dist/(n+1)
+ for j=1,n do
+ 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}
+ 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)
- polyNew = {}
- polyCopy = shallowCopy(polygon)
+ local polyNew = {}
+ local polyCopy = shallowCopy(polygon)
e1 = polyCopy[1][1]
e2 = polyCopy[1][2]
table.insert(polyNew, e1)
-- build the list of points extern and stop at nbr
function buildListExt(chaine, stop)
- listPoints = {}
+ local listPoints = {}
io.input(chaine) -- open the file
text=io.read("*all")
lines=string.explode(text,"\n+") -- all the lines
io.input(file) -- open the file
text=io.read("*all")
local lines = split(text,"\n+") -- all the lines
- listPoints={}
- triangulation ={}
+ local listPoints={}
+ local triangulation ={}
boolNodes = false
Jnodes = 0
boolElements = false