-- 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
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]]
-- 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
-- function to build a gridpoints from the bounding box
-- with a prescribed
-function buildGrid(listPoints,h)
+function buildGrid(listPoints,h,random)
-- listPoints : list of the points of the polygon, ordered
-- h : parameter for the grid
xmin, xmax, ymin, ymax = BoundingBox(listPoints)
- local grid = rectangleList(xmin,xmax,ymin,ymax,h)
+ local grid = rectangleList(xmin,xmax,ymin,ymax,h,random)
return grid
end
-- function to build the list of points in the rectangle
-function rectangleList(xmin,xmax,ymin,ymax,h)
+function rectangleList(xmin,xmax,ymin,ymax,h,random)
+ -- for the random
+ math.randomseed( os.time() )
nbrX = math.floor(math.abs(xmax-xmin)/h)
nbrY = math.floor(math.abs(ymax-ymin)/h)
local listPoints = {}
k=1
for i=1,(nbrX+1) do
for j=1,(nbrY+1) do
- listPoints[k] = {x = xmin+(i-1)*h, y=ymin+(j-1)*h}
+ rd = math.random()
+ if(random=="perturb") then
+ fact = 0.3*h
+ --print(fact)
+ else
+ fact = 0.0
+ end
+ listPoints[k] = {x = xmin+(i-1)*h+rd*fact, y=ymin+(j-1)*h+rd*fact}
k=k+1
end
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