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