poly2tri

PURPOSE ^

POLY2TRI Polygon triangulation using GPC library.

SYNOPSIS ^

function [xtri, ytri] = poly2tri(x, y)

DESCRIPTION ^

POLY2TRI  Polygon triangulation using GPC library.

  Syntax:
    [XTRI, YTRI] = POLY2TRI(X, Y)

  Description:
    [XTRI, YTRI] = POLY2TRI(X, Y) triangulates the polygon with coordinates in
    vectors X and Y, returning the coordinates of the resulting triangulation
    3-by-M arrays XTRI and YTRI, where M is the number of triangles in the
    decomposition, and each column defines a triangle. X and Y must b the same 
    size. The polygon may be self-intersecting, and it is supposed to be
    closed even if the first vertex is not repeated at the end.

  Notes:
    The true decomposition is performed by the function GPC_POLYGON_TO_TRISTRIP
    of the General Polygon Clipper library (GPC), written by Alan Murta.
    This function is called in the companion mex file.

    An alternative implementation using constrained Delaunay triangulation
    functions provided by MATLAB is commented in this source file.
    If you can not build or use the GPC based mex file, uncoment those lines.

  Examples:
    x = [0 -1 -1  0  0  1  1  0]
    y = [0  0 -1 -1  1  1  0  0]
    [xtri, ytri] = poly2tri(x, y)
    patch(xtri, ytri, 1:size(xtri,2), 'Marker', 'none', 'EdgeColor', 'none')
    hold on
    plot(x, y, '-r', 'LineWidth', 2)

  References:
    Alan Murta, GPC - General Polygon Clipper library:
    <http://www.cs.man.ac.uk/~amurta/software/index.html#gpc>

  Authors:
    Joan Pau Beltran  <joanpau.beltran@socib.cat>

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

poly2tri.m

SOURCE CODE ^

0001 function [xtri, ytri] = poly2tri(x, y)
0002 %POLY2TRI  Polygon triangulation using GPC library.
0003 %
0004 %  Syntax:
0005 %    [XTRI, YTRI] = POLY2TRI(X, Y)
0006 %
0007 %  Description:
0008 %    [XTRI, YTRI] = POLY2TRI(X, Y) triangulates the polygon with coordinates in
0009 %    vectors X and Y, returning the coordinates of the resulting triangulation
0010 %    3-by-M arrays XTRI and YTRI, where M is the number of triangles in the
0011 %    decomposition, and each column defines a triangle. X and Y must b the same
0012 %    size. The polygon may be self-intersecting, and it is supposed to be
0013 %    closed even if the first vertex is not repeated at the end.
0014 %
0015 %  Notes:
0016 %    The true decomposition is performed by the function GPC_POLYGON_TO_TRISTRIP
0017 %    of the General Polygon Clipper library (GPC), written by Alan Murta.
0018 %    This function is called in the companion mex file.
0019 %
0020 %    An alternative implementation using constrained Delaunay triangulation
0021 %    functions provided by MATLAB is commented in this source file.
0022 %    If you can not build or use the GPC based mex file, uncoment those lines.
0023 %
0024 %  Examples:
0025 %    x = [0 -1 -1  0  0  1  1  0]
0026 %    y = [0  0 -1 -1  1  1  0  0]
0027 %    [xtri, ytri] = poly2tri(x, y)
0028 %    patch(xtri, ytri, 1:size(xtri,2), 'Marker', 'none', 'EdgeColor', 'none')
0029 %    hold on
0030 %    plot(x, y, '-r', 'LineWidth', 2)
0031 %
0032 %  References:
0033 %    Alan Murta, GPC - General Polygon Clipper library:
0034 %    <http://www.cs.man.ac.uk/~amurta/software/index.html#gpc>
0035 %
0036 %  Authors:
0037 %    Joan Pau Beltran  <joanpau.beltran@socib.cat>
0038 
0039 %  Copyright (C) 2013-2016
0040 %  ICTS SOCIB - Servei d'observacio i prediccio costaner de les Illes Balears
0041 %  <http://www.socib.es>
0042 %
0043 %  This program is free software: you can redistribute it and/or modify
0044 %  it under the terms of the GNU General Public License as published by
0045 %  the Free Software Foundation, either version 3 of the License, or
0046 %  (at your option) any later version.
0047 %
0048 %  This program is distributed in the hope that it will be useful,
0049 %  but WITHOUT ANY WARRANTY; without even the implied warranty of
0050 %  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0051 %  GNU General Public License for more details.
0052 %
0053 %  You should have received a copy of the GNU General Public License
0054 %  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0055 
0056   error('glider_toolbox:poly2tri:MissingMexfile', 'Missing required mex file.');
0057 
0058   % Altrernative implementation using Delaunay Triangulation built in MATLAB.
0059   %{
0060   nv = numel(x);
0061   triangulation =  DelaunayTri(x(:), y(:), [1 (2:nv); (2:nv) 1]');
0062   indices = triangulation.inOutStatus;
0063   faces = triangulation.Triangulation(indices, :);
0064   vertices = triangulation.X;
0065   xtri = reshape(vertices(faces, 1), size(faces))';
0066   ytri = reshape(vertices(faces, 2), size(faces))'; 
0067   %}
0068   
0069 end

Generated on Fri 06-Oct-2017 10:47:42 by m2html © 2005