Editing Geometry package
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 9: | Line 9: | ||
== Tutorials == | == Tutorials == | ||
=== Loading SVG files === | === Loading SVG files === | ||
=== Meshing Octave === | === Meshing Octave === | ||
<!--'''<span style="color:#FF0000;">Under construction</span>''' --> | <!--'''<span style="color:#FF0000;">Under construction</span>''' --> | ||
Line 20: | Line 20: | ||
<!-- {{SyntaxHighlight| --> | <!-- {{SyntaxHighlight| --> | ||
{{Code|Loading the file as polygon compatible with geometry package|<syntaxhighlight lang=" | {{Code|Loading the file as polygon compatible with geometry package|<syntaxhighlight line="GESHI_FANCY_LINE_NUMBERS" lang="matlab" style="font-size:13px"> | ||
octavesvg = svg ("octave.svg").normalize(); | octavesvg = svg ("octave.svg").normalize(); | ||
ids = octavesvg.pathid(); | ids = octavesvg.pathid(); | ||
Line 28: | Line 28: | ||
Now we have our SVG as a polygon compatible with the Geometry package format. You can plot the polygon using the function {{Codeline|drawPolygon}}. | 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|<syntaxhighlight lang="matlab" style="font-size:13px"> | {{Code|Plotting a polygon compatible with geometry package|<syntaxhighlight line="GESHI_FANCY_LINE_NUMBERS" lang="matlab" style="font-size:13px"> | ||
drawPolygon (P, "-o"); | drawPolygon (P, "-o"); | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
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 (> 1.5.0) comes with a simplification function that uses the [http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm Ramer-Douglas-Peucker algorithm] to reduce thenumber of points in the polygon. | 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 (> 1.5.0) comes with a simplification function that uses the [http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm Ramer-Douglas-Peucker algorithm] to reduce thenumber of points in the polygon. | ||
{{Code|Symplification of a polygon compatible with geometry package|<syntaxhighlight lang=" | {{Code|Symplification of a polygon compatible with geometry package|<syntaxhighlight line="GESHI_FANCY_LINE_NUMBERS" lang="matlab" style="font-size:13px"> | ||
P = | P = symplifypolygon(Ps, 'tol', 1e-3); | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
You should play with the tolerance option until you get a nice polygon. | You should play with the tolerance option until you get a nice polygon. | ||
Line 39: | Line 39: | ||
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: | 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|<syntaxhighlight lang=" | {{Code|Generating mesh for plot with msh package|<syntaxhighlight line="GESHI_FANCY_LINE_NUMBERS" lang="matlab" style="font-size:13px"> | ||
pkg load msh | pkg load msh | ||
filename = tmpnam (); | filename = tmpnam (); | ||
Line 50: | Line 50: | ||
After this code finishes, the structure T contains our mesh. To plot the generated mesh we use the function {{Codeline|pdemesh}} from the {{Forge|fpl}} package. In general is a good idea to use the openGL render (called ''fltk'') to plot meshes. | After this code finishes, the structure T contains our mesh. To plot the generated mesh we use the function {{Codeline|pdemesh}} from the {{Forge|fpl}} package. In general is a good idea to use the openGL render (called ''fltk'') to plot meshes. | ||
{{Code|Plotting mesh with fpl package|<syntaxhighlight lang=" | {{Code|Plotting mesh with fpl package|<syntaxhighlight line="GESHI_FANCY_LINE_NUMBERS" lang="matlab" style="font-size:13px"> | ||
pkg load fpl | pkg load fpl | ||
graphics_toolkit ('fltk') | graphics_toolkit ('fltk') | ||
Line 70: | Line 70: | ||
* [http://sourceforge.net/apps/mediawiki/matgeom/index.php?title=Main_Page matGeom] | * [http://sourceforge.net/apps/mediawiki/matgeom/index.php?title=Main_Page matGeom] | ||
[[Category: | [[Category:OctaveForge]] | ||
[[Category:Packages]] |