Perturbation aléatoire des points de la grille rectangulaire pour meshPolygon, option...
authorMaxime Chupin (Ceremade) <chupin@ceremade.dauphine.fr>
Fri, 10 Feb 2017 14:04:54 +0000 (15:04 +0100)
committerMaxime Chupin (Ceremade) <chupin@ceremade.dauphine.fr>
Fri, 10 Feb 2017 14:04:54 +0000 (15:04 +0100)
archives/luamesh-v0-5.zip
doc/luamesh-doc.pdf
doc/luamesh-doc.tex
doc/luamesh-doc.toc
luamesh-tex.lua
luamesh.lua
luamesh.sty
test/delaunay.pdf
test/delaunay.tex

index c797a0f..f7db31f 100644 (file)
Binary files a/archives/luamesh-v0-5.zip and b/archives/luamesh-v0-5.zip differ
index e0cb581..92a1162 100644 (file)
Binary files a/doc/luamesh-doc.pdf and b/doc/luamesh-doc.pdf differ
index 9074e5f..e2e2bdf 100644 (file)
@@ -632,7 +632,7 @@ xn yn
 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
   label the vertices of the triangulation. It is included in the math
   mode delimiters \Verb+$...$+.
-\item[step = polyqon  \textme{or} grid \textme{or}
+\item[step = polygon  \textme{or} grid \textme{or}
   points \textme{or} mesh (default):] To choose the step we want to draw,
   see the description above.
 \item[tikz (boolean, default:false):] By default, this boolean is set
@@ -643,6 +643,10 @@ xn yn
   the scale at which the picture is drawn (the same for both
   axis). It must contain the unit of length (cm,
   pt, etc.).
+\item[gridpoints = rect (default)  \textme{or} perturb:] This option
+  allows to specify the mode of generation of the grid points. The
+  value \Verb+rect+ produces a simple rectangular grid, and the value
+  \Verb+pertub+ randomly perturbs the rectangular grid.
 \end{optionsenum}
 
 Here is an example of customizing the drawing.
@@ -654,7 +658,8 @@ Here is an example of customizing the drawing.
   colorPolygon=red!120,
   scale=4cm,
   step=mesh,
-  print=points]
+  print=points,
+  gridpoints=perturb]
   {(0,0);(1,0);(1,0.5);(0,0.5);(-0.20,0.35);(-0.25,0.25);(-0.20,0.15)}
 \end{Exemple}
 
index ff499a2..cdace55 100644 (file)
 \contentsline {subsection}{\numberline {2.4}Mesh a Polygon}{11}{subsection.2.4}
 \contentsline {subsubsection}{\numberline {2.4.1}The Options}{12}{subsubsection.2.4.1}
 \contentsline {section}{\numberline {3}The \emph {inc} Macros}{13}{section.3}
-\contentsline {subsection}{\numberline {3.1}With MetaPost}{13}{subsection.3.1}
+\contentsline {subsection}{\numberline {3.1}With MetaPost}{14}{subsection.3.1}
 \contentsline {subsubsection}{\numberline {3.1.1}The \LaTeX {} Colors Inside the MetaPost Code}{14}{subsubsection.3.1.1}
 \contentsline {subsubsection}{\numberline {3.1.2}The Mesh Points}{14}{subsubsection.3.1.2}
-\contentsline {subsubsection}{\numberline {3.1.3}Examples}{14}{subsubsection.3.1.3}
+\contentsline {subsubsection}{\numberline {3.1.3}Examples}{15}{subsubsection.3.1.3}
 \contentsline {subsection}{\numberline {3.2}With TikZ}{16}{subsection.3.2}
 \contentsline {subsubsection}{\numberline {3.2.1}The Mesh Points}{16}{subsubsection.3.2.1}
 \contentsline {subsubsection}{\numberline {3.2.2}Examples}{17}{subsubsection.3.2.2}
index b035978..11e31a4 100644 (file)
@@ -873,10 +873,10 @@ end
 
 
 function drawMeshPolygonMP(chaine,mode,h,step,
-                             points,scale)
+                             points,scale,random)
    local polygon = buildList(chaine, mode)
    polygon = addPointsPolygon(polygon,h)
-   local grid = buildGrid(polygon,h)
+   local grid = buildGrid(polygon,h,random)
    local listPoints = addGridPoints(polygon,grid,h)
    if(step=="polygon") then
       -- the polygon
@@ -906,10 +906,10 @@ end
 
 
 function drawMeshPolygonTikZ(chaine,mode,h,step,
-                             points,scale,color,colorPoly)
+                             points,scale,color,colorPoly,random)
    local polygon = buildList(chaine, mode)
    polygon = addPointsPolygon(polygon,h)
-   local grid = buildGrid(polygon,h)
+   local grid = buildGrid(polygon,h,random)
    local listPoints = addGridPoints(polygon,grid,h)
    if(step=="polygon") then
       -- the polygon
@@ -936,10 +936,10 @@ function drawMeshPolygonTikZ(chaine,mode,h,step,
 end
 
 function drawMeshPolygonMPinc(chaine,beginning,ending,mode,h,step,
-                             points,scale)
+                             points,scale,random)
    local polygon = buildList(chaine, mode)
    polygon = addPointsPolygon(polygon,h)
-   local grid = buildGrid(polygon,h)
+   local grid = buildGrid(polygon,h,random)
    local listPoints = addGridPoints(polygon,grid,h)
    if(step=="polygon") then
       -- the polygon
@@ -968,10 +968,10 @@ end
 
 
 function drawMeshPolygonTikZinc(chaine,beginning,ending,mode,h,step,
-                             points,scale,color,colorPoly)
+                             points,scale,color,colorPoly,random)
    local polygon = buildList(chaine, mode)
    polygon = addPointsPolygon(polygon,h)
-   local grid = buildGrid(polygon,h)
+   local grid = buildGrid(polygon,h,random)
    local listPoints = addGridPoints(polygon,grid,h)
    if(step=="polygon") then
       -- the polygon
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
index c0a1789..b0ee1fc 100644 (file)
   \def\luameshval@mp@mode{ext}%
   \fi%
 }%
+%% the mode for the generation of gridpoints
+\define@choicekey*{meshPolygon}{gridpoints}[\val\nr]{rect, perturb}{%
+  \ifcase\nr\relax%
+  \def\luameshval@mp@gridpoints{rect}%
+  \or%
+  \def\luameshval@mp@gridpoints{perturb}%
+  \fi%
+}%
 %% the different steps of the  meshing
 \define@choicekey*{meshPolygon}{step}[\val\nr]{polygon, grid, points, mesh}{%
   \ifcase\nr\relax%
 \define@key{meshPolygon}{colorPolygon}[red]{\def\luameshval@mp@colorPolygon{#1}}%
 %% the name of the color of drawing the bbox
 %
-\presetkeys{meshPolygon}{tikz=false,scale,mode=int,step=mesh,print=none,color,colorPolygon,h,meshpoint}{}%
+\presetkeys{meshPolygon}{tikz=false,scale,mode=int,step=mesh,print=none,color,colorPolygon,h,meshpoint,gridpoints=rect}{}%
 %
 \newcommand{\meshPolygon}[2][]{%
   % #1 : optionnal arguments
   \def\MeshPoint{\luameshval@mp@meshpoint}%
   \ifKV@meshPolygon@tikz% if we are using tikz
   \directlua{%
-    drawMeshPolygonTikZ("#2","\luameshval@mp@mode","\luameshval@mp@h","\luameshval@mp@step","\luameshval@mp@print","\luameshval@mp@scale","\luameshval@mp@color","\luameshval@mp@colorPolygon")%
+    drawMeshPolygonTikZ("#2","\luameshval@mp@mode","\luameshval@mp@h","\luameshval@mp@step","\luameshval@mp@print","\luameshval@mp@scale","\luameshval@mp@color","\luameshval@mp@colorPolygon","\luameshval@mp@gridpoints")%
   }%
   \else % we are using MP
   \mplibcolor{\luameshmpcolor}{\luameshval@mp@color}%
   \mplibcolor{\luameshmpcolorPoly}{\luameshval@mp@colorPolygon}%
   \directlua{%
-    drawMeshPolygonMP("#2","\luameshval@mp@mode","\luameshval@mp@h","\luameshval@mp@step","\luameshval@mp@print","\luameshval@mp@scale")%
+    drawMeshPolygonMP("#2","\luameshval@mp@mode","\luameshval@mp@h","\luameshval@mp@step","\luameshval@mp@print","\luameshval@mp@scale","\luameshval@mp@gridpoints")%
   }%
   %
   \fi%
   \def\luameshval@mpi@print{dotpoints}%
   \fi%
 }%
+%% the mode for the generation of gridpoints
+\define@choicekey*{meshPolygonInc}{gridpoints}[\val\nr]{rect, perturb}{%
+  \ifcase\nr\relax%
+  \def\luameshval@mpi@gridpoints{rect}%
+  \or%
+  \def\luameshval@mpi@gridpoints{perturb}%
+  \fi%
+}%
 %% the name of the point
 \define@key{meshPolygonInc}{meshpoint}[P]{\def\luameshval@mpi@meshpoint{#1}}%
 %% the grid parameter
 \define@key{meshPolygonInc}{colorPolygon}[red]{\def\luameshval@mpi@colorPolygon{#1}}%
 %% the name of the color of drawing the bbox
 %
-\presetkeys{meshPolygonInc}{tikz=false,scale,mode=int,step=mesh,print=none,color,colorPolygon,h,meshpoint}{}%
+\presetkeys{meshPolygonInc}{tikz=false,scale,mode=int,step=mesh,print=none,color,colorPolygon,h,meshpoint,gridpoints=rect}{}%
 %
 \newcommand{\meshPolygonInc}[4][]{%
   % #1 : optionnal arguments
   \def\MeshPoint{\luameshval@mpi@meshpoint}%
   \ifKV@meshPolygonInc@tikz% if we are using tikz
   \directlua{%
-    drawMeshPolygonTikZinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@mpi@mode","\luameshval@mpi@h","\luameshval@mpi@step","\luameshval@mpi@print","\luameshval@mpi@scale","\luameshval@mpi@color","\luameshval@mpi@colorPolygon")%
+    drawMeshPolygonTikZinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@mpi@mode","\luameshval@mpi@h","\luameshval@mpi@step","\luameshval@mpi@print","\luameshval@mpi@scale","\luameshval@mpi@color","\luameshval@mpi@colorPolygon","\luameshval@mpi@gridpoints")%
   }%
   \else % we are using MP
   \mplibcolor{\luameshmpcolor}{\luameshval@mpi@color}%
   \mplibcolor{\luameshmpcolorPoly}{\luameshval@mpi@colorPolygon}%
   \directlua{%
-    drawMeshPolygonMPinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@mpi@mode","\luameshval@mpi@h","\luameshval@mpi@step","\luameshval@mpi@print","\luameshval@mpi@scale")%
+    drawMeshPolygonMPinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@mpi@mode","\luameshval@mpi@h","\luameshval@mpi@step","\luameshval@mpi@print","\luameshval@mpi@scale","\luameshval@mpi@gridpoints")%
   }%
   %
   \fi%
index e33b131..a797288 100644 (file)
Binary files a/test/delaunay.pdf and b/test/delaunay.pdf differ
index f5b7bae..45a7ff4 100644 (file)
@@ -176,7 +176,7 @@ colorBbox = black
 \meshPolygon[step=polygon,scale=3cm]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
 \meshPolygon[step=grid,scale=3cm]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
 \meshPolygon[step=points,scale=3cm,print=points]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
-\meshPolygon[step=mesh,scale=3cm,print=dotpoints]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
+\meshPolygon[step=mesh,scale=3cm,print=dotpoints,gridpoints=perturb]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
 
 \meshPolygon[tikz,step=polygon,scale=3cm]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}
 \meshPolygon[tikz,step=grid,scale=3cm]{(0,0);(1,0);(1,0.5);(0.5,1);(-0.3,0.3)}

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.