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 1: | Line 1: | ||
The geometry package is multipackage providing functions to manipulate geometrical entities in 2D and 3D. | 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 === | ||
=== Meshing Octave === | === Meshing Octave === | ||
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 | This tutorial requires that you install the package [http://octave.sourceforge.net/fpl/index.html fpl] and [http://octave.sourceforge.net/msh/index.html msh] (which requires [http://geuz.org/gmsh/ Gmsh] installed in your system). Alternatively, the core function <tt>delaunay</tt> could be used (the tutorial explains how) but the result aren't so pretty. | ||
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 [link-to-file this SVG]. | |||
[[File:octave. | [[File:octave.svg|thumb|200px|right]] | ||
Lets load the file: | |||
Now we have our SVG as a polygon compatible with the Geometry package format. You can plot the polygon using the function | <!-- <syntaxhighlight lang="matlab"> --> | ||
<pre> | |||
drawPolygon | octavepoly = svg('octave.svg'); | ||
</ | ids = dc.pathid(); | ||
P = dc.path2polygon(ids{1},12)(1:end-1,:); | |||
P = bsxfun(@minus, P, centroid(P)); | |||
</pre> | |||
Now we have our SVG as a polygon compatible with the Geometry package format. You can plot the polygon using the function <tt>drawPolygon</tt>. the next step is to mesh the interior of the polygon. To do this we could just call <tt>delaunay</tt> 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 [http://octave.sourceforge.net/msh/index.html msh], which requires [http://geuz.org/gmsh/ Gmsh] installed in your system. The function data2geo in the Geometry package makes our work very easy: | |||
</pre> | |||
pkg load msh | pkg load msh | ||
filename = tmpnam (); | filename = tmpnam (); | ||
meshsize = sqrt (mean (sumsq (diff (P, 1, 1), 2)))/2; | meshsize = sqrt(mean(sumsq(diff(P,1,1),2)))/2; | ||
data2geo (P, meshsize, | data2geo (P, meshsize, 'output', [filename '.geo']); | ||
T | T = msh2m_gmsh(filename); | ||
</ | </pre> | ||
<!-- </syntaxhighlight> --> | <!-- </syntaxhighlight> --> | ||
To plot the generated mesh we use the function <tt>pdemesh</tt> from the [http://octave.sourceforge.net/fpl/index.html fpl] package. | |||
<pre> | |||
pkg load fpl | pkg load fpl | ||
pdemesh(T.p,T.e,T.t) | |||
pdemesh (T.p, T.e, T.t) | </pre> | ||
</ | |||
[[File:octave_meshed.svg|thumb|200px|left]] | |||
=== From piece-wise polynomial shapes to polygons === | === From piece-wise polynomial shapes to polygons === | ||
Line 70: | Line 49: | ||
* [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]] |