Perturbation aléatoire des points de la grille rectangulaire pour meshPolygon, option...
[delaunay.git] / luamesh.lua
index 833684e..a1023aa 100644 (file)
@@ -377,24 +377,33 @@ end
 
 -- 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

Licence Creative Commons Les fichiers de Syracuse sont mis à disposition (sauf mention contraire) selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.