Rectification des fichiers et de la version pour le CTAN
[delaunay.git] / luamesh.lua
index 10a2084..a1023aa 100644 (file)
@@ -13,7 +13,7 @@ end
 -- 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
@@ -139,7 +139,6 @@ end
 
 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]]
@@ -365,14 +364,9 @@ function addPointsPolygon(polygon,h)
       -- 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
@@ -383,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
@@ -427,8 +430,8 @@ 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)
@@ -464,7 +467,7 @@ end
 
 -- 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
@@ -500,8 +503,8 @@ function readGmsh(file)
    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

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.