Editing Geometry package

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

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 1: Line 1:
The geometry package is multipackage providing functions to manipulate geometrical entities in 2D and 3D. It is based in [http://sourceforge.net/apps/mediawiki/matgeom/index.php?title=Main_Page matGeom] and extends it with several other functionalities, e.g. the package provides interfaces with SVG files and polygon meshing using Gmsh.
The geometry package is multipackage providing functions to manipulate geometrical entities in 2D and 3D.
 
== Relation to matGeom ==
== Relation to matGeom ==


Line 9: Line 8:
== Tutorials ==
== Tutorials ==
=== Loading SVG files ===
=== Loading SVG files ===
'''<span style="color:#FF0000;">Coming soon</span>'''
 
=== Meshing Octave ===
=== Meshing Octave ===
<!--'''<span style="color:#FF0000;">Under construction</span>''' -->
'''<span style="color:#FF0000;">Under construction</span>'''


This tutorial shows the workflow to generate a triangular mesh inside an arbitrary region.
This tutorial shows the workflow to generate a triangular mesh inside an arbitrary region.
This tutorial requires that you install the package {{Forge|fpl}} and {{Forge|msh}} (which requires [http://geuz.org/gmsh/ Gmsh] installed in your system). Alternatively, the core function {{Codeline|delaunay}} could be used but the result aren't so pretty.
This tutorial requires that you install the package {{Forge|fpl}} and {{Forge|msh}} (which requires [http://geuz.org/gmsh/ Gmsh] installed in your system). Alternatively, the core function {{Codeline|delaunay}} could be used (the tutorial explains how) but the result aren't so pretty.


This tutorial requires an interesting shape to mesh. If you have [http://inkscape.org/index.php?lang=en Inkscape] you can create one, and use the previous tutorial to load it into octave. Here I will be using [http://ubuntuone.com/5pNS12ZChUXeGNBniWNa3J this SVG].  
The first part of the tutorial requires an interesting shape. If you have Inkscape you can use the previous tutorial to load it into octave. Here I will be using [http://ubuntuone.com/5pNS12ZChUXeGNBniWNa3J this SVG].  
[[File:octave.png|200px|center]]
[[File:octave.png|200px|center]]


<!-- {{SyntaxHighlight| -->
<!-- <syntaxhighlight lang="matlab"> -->
{{Code|Loading the file as polygon compatible with geometry package|<syntaxhighlight lang="octave" style="font-size:13px">
{{Code|Loading the file as polygon compatible with geometry package|<pre>
octavesvg = svg ("octave.svg").normalize();
octavesvg = svg ("octave.svg").normalize();
ids      = octavesvg.pathid();
ids      = octavesvg.pathid();
P        = octavesvg.path2polygon (ids{1}, 12)(1:end-1,:);
P        = octavesvg.path2polygon (ids{1}, 12)(1:end-1,:);
P        = bsxfun (@minus, P, centroid (P));
P        = bsxfun (@minus, P, centroid (P));
</syntaxhighlight>}}
</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}}.
{{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 the polygon 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>


Now we have our SVG as a polygon compatible with the Geometry package format. You can plot the polygon using the function {{Codeline|drawPolygon}}.
</pre>}}
{{Code|Plotting a polygon compatible with geometry package|<syntaxhighlight lang="matlab" style="font-size:13px">
drawPolygon (P, "-o");
</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.
{{Code|Symplification of a polygon compatible with geometry package|<syntaxhighlight lang="octave" style="font-size:13px">
P  = simplifypolygon(P, 'tol', 1e-3);
</syntaxhighlight>}}
You should play with the tolerance option until you get a nice polygon.


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="octave" style="font-size:13px">
{{Code|Generating mesh for plot with msh package|<pre>
pkg load msh
pkg load msh
filename = tmpnam ();
filename = tmpnam ();
Line 45: Line 43:
data2geo (P, meshsize, "output", [filename ".geo"]);
data2geo (P, meshsize, "output", [filename ".geo"]);
T        = msh2m_gmsh (filename);
T        = msh2m_gmsh (filename);
</syntaxhighlight>}}
</pre>}}


<!-- </syntaxhighlight> -->
<!-- </syntaxhighlight> -->
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.
To plot the generated mesh we use the function {{Codeline|pdemesh}} from the {{Forge|fpl}} package.


{{Code|Plotting mesh with fpl package|<syntaxhighlight lang="octave" style="font-size:13px">
{{Code|Plotting mesh with fpl package|<pre>
pkg load fpl  
pkg load fpl  
graphics_toolkit ('fltk')
pdemesh (T.p, T.e, T.t)
pdemesh (T.p, T.e, T.t);
</pre>}}
view (2)
axis tight
axis equal
</syntaxhighlight>}}
 
The output should look something like this
[[File:octave_meshed.png|400px|center]]


Questions? Ideas? Join us in the mailing list or in the #octave IRC channel.
[[File:octave_meshed.png|600x400px|center]]


=== From piece-wise polynomial shapes to polygons ===
=== From piece-wise polynomial shapes to polygons ===
Line 70: Line 61:
* [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:Octave Forge]]
[[Category:OctaveForge]]
[[Category:Packages]]
Please note that all contributions to Octave may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Octave:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Templates used on this page: