652

edits

Jump to navigation
Jump to search
~~Ps = ~~P~~; ~~~~n = 1e6;~~~~thrsd = 0.38; ~~~~while n > size (Ps,1)~~~~ n ~~ = ~~size ~~symplifypolygon(Ps,~~1); ~~~~ ds = sqrt (sumsq (Ps(1:end~~'tol',~~:) ~~1e- ~~Ps([2:end 1],:~~3)~~,2));~~~~ Ps = Ps(ds > mean (ds)*(1-thrsd),:); ~~~~end~~~~whos P Ps~~~~P = Ps~~;

[[File:octave.png|200px|center]]

<!-- ~~<syntaxhighlight lang="matlab"> ~~{{SyntaxHighlight| -->{{Code|Loading the file as polygon compatible with geometry package|~~{{SyntaxHighlight|~~<syntaxhighlight line="GESHI_FANCY_LINE_NUMBERS" lang="matlab" style="font-size:13px">

octavesvg = svg ("octave.svg").normalize();

ids = octavesvg.pathid();

P = octavesvg.path2polygon (ids{1}, 12)(1:end-1,:);

P = bsxfun (@minus, P, centroid (P));

</syntaxhighlight>}}~~}}~~

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 line="GESHI_FANCY_LINE_NUMBERS" 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 ~~but as of version 1~~that uses the [http://en.~~4~~wikipedia.~~0, this function is very naïve and wont fix this problem. If you know how to simplify polygons you can contribute!~~~~We are going ~~org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm Ramer-Douglas-Peucker algorithm] to reduce ~~the amount ~~thenumber of points ~~of ~~in 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|<syntaxhighlight line="GESHI_FANCY_LINE_NUMBERS" lang="matlab" style="font-size:13px">

</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:

652

edits

Retrieved from "https://wiki.octave.org/Special:MobileDiff/1001"

- Not logged in
- Talk
- Contributions
- Create account
- Log in