Home > matGeom > polygons2d > polylineSubcurve.m

polylineSubcurve

PURPOSE ^

Extract a portion of a polyline.

SYNOPSIS ^

function [res, inds] = polylineSubcurve(poly, t0, t1)

DESCRIPTION ^

 Extract a portion of a polyline.

   POLY2 = polylineSubcurve(POLYLINE, POS0, POS1)
   Create a new polyline, by keeping vertices located between positions
   POS0 and POS1, and adding points corresponding to positions POS0 and
   POS1 if they are not already vertices.

   [POLY2, INDS] = polylineSubcurve(POLYLINE, POS0, POS1)
   Also returns the indices of the original polyline that were selected.
   The size of the array INDS may be smaller than the array POLY, due to
   the addition of new vertices at the extremities.

   Example
     Nv = 100;
     poly = circleAsPolygon([10 20 30], Nv);
     poly2 = polylineSubcurve(poly, 15, 65);
     drawCurve(poly2);

   See also
     polygons2d, polygonSubCurve

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [res, inds] = polylineSubcurve(poly, t0, t1)
0002 % Extract a portion of a polyline.
0003 %
0004 %   POLY2 = polylineSubcurve(POLYLINE, POS0, POS1)
0005 %   Create a new polyline, by keeping vertices located between positions
0006 %   POS0 and POS1, and adding points corresponding to positions POS0 and
0007 %   POS1 if they are not already vertices.
0008 %
0009 %   [POLY2, INDS] = polylineSubcurve(POLYLINE, POS0, POS1)
0010 %   Also returns the indices of the original polyline that were selected.
0011 %   The size of the array INDS may be smaller than the array POLY, due to
0012 %   the addition of new vertices at the extremities.
0013 %
0014 %   Example
0015 %     Nv = 100;
0016 %     poly = circleAsPolygon([10 20 30], Nv);
0017 %     poly2 = polylineSubcurve(poly, 15, 65);
0018 %     drawCurve(poly2);
0019 %
0020 %   See also
0021 %     polygons2d, polygonSubCurve
0022 %
0023 
0024 % ------
0025 % Author: David Legland
0026 % e-mail: david.legland@inrae.fr
0027 % Created: 2009-04-30,    using Matlab 7.7.0.471 (R2008b)
0028 % Copyright 2009 INRAE - Cepia Software Platform.
0029 
0030 % number of vertices
0031 Nv = size(poly, 1);
0032 
0033 if t0 < t1
0034     % format positions
0035     t0 = max(t0, 0);
0036     t1 = min(t1, Nv-1);
0037 end
0038 
0039 % indices of extreme vertices inside subcurve
0040 ind0 = ceil(t0)+1;
0041 ind1 = floor(t1)+1;
0042 
0043 % get the portion of polyline between 2 extremities
0044 if t0 < t1
0045     inds = ind0:ind1;
0046 else
0047     inds = [ind0:Nv 1:ind1];
0048 end
0049 
0050 res = poly(inds, :);
0051 
0052 % add first point if it is not already a vertex
0053 if t0 ~= ind0-1
0054     res = [polylinePoint(poly, t0); res];
0055 end
0056 
0057 % add last point if it is not already a vertex
0058 if t1 ~= ind1-1
0059     res = [res; polylinePoint(poly, t1)];
0060 end
0061

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