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