POLYGONSIGNATURE Polar signature of a polygon (polar distance to origin). DISTS = polygonSignature(POLY, THETALIST) Computes the polar signature of a polygon, for a set of angles in degrees. If a ray at a given angle does not intersect the polygon, the corresponding distance value is set to NaN. DISTS = polygonSignature(POLY, N) When N is a scalar, uses N angles equally distributed between 0 and 360 degrees. [DISTS, THETA] = polygonSignature(...) Also returns the angle set for which the signature was computed. Example polygonSignature See also polygons2d, signatureToPolygon, intersectRayPolygon
0001 function [res, thetaList] = polygonSignature(poly, varargin) 0002 %POLYGONSIGNATURE Polar signature of a polygon (polar distance to origin). 0003 % 0004 % DISTS = polygonSignature(POLY, THETALIST) 0005 % Computes the polar signature of a polygon, for a set of angles in 0006 % degrees. If a ray at a given angle does not intersect the polygon, the 0007 % corresponding distance value is set to NaN. 0008 % 0009 % DISTS = polygonSignature(POLY, N) 0010 % When N is a scalar, uses N angles equally distributed between 0 and 360 0011 % degrees. 0012 % 0013 % [DISTS, THETA] = polygonSignature(...) 0014 % Also returns the angle set for which the signature was computed. 0015 % 0016 % Example 0017 % polygonSignature 0018 % 0019 % See also 0020 % polygons2d, signatureToPolygon, intersectRayPolygon 0021 % 0022 0023 % ------ 0024 % Author: David Legland 0025 % e-mail: david.legland@nantes.inra.fr 0026 % Created: 2013-03-14, using Matlab 7.9.0.529 (R2009b) 0027 % Copyright 2013 INRA - Cepia Software Platform. 0028 0029 % default angle list 0030 thetaList = 0:359; 0031 0032 % get user-defined angle list 0033 if ~isempty(varargin) 0034 var = varargin{1}; 0035 if isscalar(var) 0036 thetaList = linspace(0, 360, var+1); 0037 thetaList(end) = []; 0038 else 0039 thetaList = var; 0040 end 0041 end 0042 0043 % also extract reference point if needed 0044 center = [0 0]; 0045 if nargin > 2 0046 center = varargin{2}; 0047 end 0048 0049 % allocate memory 0050 nTheta = length(thetaList); 0051 res = NaN * ones(nTheta, 1); 0052 0053 % iterate on angles 0054 for i = 1:length(thetaList) 0055 theta = deg2rad(thetaList(i)); 0056 ray = [center cos(theta) sin(theta)]; 0057 0058 ptInt = intersectRayPolygon(ray, poly); 0059 if ~isempty(ptInt) 0060 res(i) = distancePoints(center, ptInt(1,:)); 0061 end 0062 end