Home > matGeom > polygons2d > resamplePolygon.m

resamplePolygon

PURPOSE ^

RESAMPLEPOLYGON Distribute N points equally spaced on a polygon.

SYNOPSIS ^

function poly2 = resamplePolygon(poly, n)

DESCRIPTION ^

RESAMPLEPOLYGON  Distribute N points equally spaced on a polygon.

   POLY2 = resamplePolygon(POLY, N)
   Resample the input polygon POLY such that the resulting polygon POLY2
   has N vertices. All points of POLY2 belong to the initial polygon, but
   are not necessarily vertices of the original polygon.


   Example
     % creates a polygon from an ellipse
     elli = [20 30 40 20 30];
     poly = ellipseToPolygon(elli, 500);
     figure; drawPolygon(poly, 'b');
     % resample the polygon with a fixed number of vertices
     poly2 = resamplePolygon(poly, 20);
     drawPolygon(poly2, 'm');
     drawPoint(poly2, 'mo');
     axis equal; axis([-20 60 0 60]);

   See also
     polygons2d, resamplePolygonByLength, smoothPolygon, resamplePolyline

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function poly2 = resamplePolygon(poly, n)
0002 %RESAMPLEPOLYGON  Distribute N points equally spaced on a polygon.
0003 %
0004 %   POLY2 = resamplePolygon(POLY, N)
0005 %   Resample the input polygon POLY such that the resulting polygon POLY2
0006 %   has N vertices. All points of POLY2 belong to the initial polygon, but
0007 %   are not necessarily vertices of the original polygon.
0008 %
0009 %
0010 %   Example
0011 %     % creates a polygon from an ellipse
0012 %     elli = [20 30 40 20 30];
0013 %     poly = ellipseToPolygon(elli, 500);
0014 %     figure; drawPolygon(poly, 'b');
0015 %     % resample the polygon with a fixed number of vertices
0016 %     poly2 = resamplePolygon(poly, 20);
0017 %     drawPolygon(poly2, 'm');
0018 %     drawPoint(poly2, 'mo');
0019 %     axis equal; axis([-20 60 0 60]);
0020 %
0021 %   See also
0022 %     polygons2d, resamplePolygonByLength, smoothPolygon, resamplePolyline
0023 %
0024 
0025 % ------
0026 % Author: David Legland
0027 % e-mail: david.legland@inra.fr
0028 % Created: 2011-12-09,    using Matlab 7.9.0.529 (R2009b)
0029 % Copyright 2011 INRA - Cepia Software Platform.
0030 
0031 poly2 = resamplePolyline(poly([1:end 1],:), n+1);
0032 poly2(end, :) = [];

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019