Changes

834 bytes added ,  08:16, 8 March 2012
Line 25: Line 25:  
P        = bsxfun (@minus, P, centroid (P));
 
P        = bsxfun (@minus, P, centroid (P));
 
</pre>}}
 
</pre>}}
Now we have our SVG as a polygon compatible with the Geometry package format. You can plot the polygon using the function {{Codeline|drawPolygon}}. the next step is to mesh the interior of the polygon. To do this we could just call {{Codeline|delaunay}} on the polygon and be done with it, but in general such mesh wont be so nice (you will need to add interior points). A very effective way of generating a good mesh is to use the package {{Forge|msh}}, which requires [http://geuz.org/gmsh/ Gmsh] installed in your system. The function {{Codeline|data2geo}} in the Geometry package makes our work very easy:
+
Now we have our SVG as a polygon compatible with the Geometry package format. You can plot the polygon using the function {{Codeline|drawPolygon}}.  
 +
{{Code|Plotting a polygon compatible with geometry package|<pre>
 +
drawPolygon (P,'-o');
 +
</pre>}}
 +
As you can see the polygon has lots of points. We need to simplify the polygon in order to obtain a mesh of reasonable size. Otherwise gmsh will have problems meshing and the result could be huge (or a segmentation fault :( ). THe package geometry comes with a simplification function but as of version 1.4.0, this function is very naive and wont fix this problem. If you know how to simplify polygons you can contribute!
 +
We are going to reduce the amount of points of th epolygon in a drastic and destructive way (i.e. the shape may be considerably damaged). The codes to do so follows, in the future a better procedure will be published here.
 +
{{Code|Symplification of a polygon compatible with geometry package|<pre>
 +
 
 +
</pre>}}
 +
 
 +
The next step is to mesh the interior of the polygon. To do this we could just call {{Codeline|delaunay}} on the polygon and be done with it, but in general such mesh wont be so nice (you will need to add interior points). A very effective way of generating a good mesh is to use the package {{Forge|msh}}, which requires [http://geuz.org/gmsh/ Gmsh] installed in your system. The function {{Codeline|data2geo}} in the Geometry package makes our work very easy:
    
{{Code|Generating mesh for plot with msh package|<pre>
 
{{Code|Generating mesh for plot with msh package|<pre>
Line 32: Line 42:  
meshsize = sqrt (mean (sumsq (diff (P, 1, 1), 2)))/2;
 
meshsize = sqrt (mean (sumsq (diff (P, 1, 1), 2)))/2;
 
data2geo (P, meshsize, "output", [filename ".geo"]);
 
data2geo (P, meshsize, "output", [filename ".geo"]);
T = msh2m_gmsh (filename);
+
T       = msh2m_gmsh (filename);
 
</pre>}}
 
</pre>}}
  
657

edits