Skip to content

Commit

Permalink
polygons2d/polygonSignature.m: returns NaN for non-intersecting edges
Browse files Browse the repository at this point in the history
  • Loading branch information
dlegland committed Mar 11, 2016
1 parent 793c52a commit 9a750e7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions matGeom/polygons2d/polygonSignature.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
%
% DISTS = polygonSignature(POLY, THETALIST)
% Computes the polar signature of a polygon, for a set of angles in
% degrees.
% 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.
% 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.
Expand All @@ -15,7 +17,7 @@
% polygonSignature
%
% See also
% polygons2d, signatureToPolygon
% polygons2d, signatureToPolygon, intersectRayPolygon
%

% ------
Expand Down Expand Up @@ -46,13 +48,15 @@

% allocate memory
nTheta = length(thetaList);
res = zeros(nTheta, 1);
res = NaN * ones(nTheta, 1);

% iterate on angles
for i = 1:length(thetaList)
theta = deg2rad(thetaList(i));
ray = [center cos(theta) sin(theta)];

ptInt = intersectRayPolygon(ray, poly);
res(i) = distancePoints(center, ptInt(1,:));
if ~isempty(ptInt)
res(i) = distancePoints(center, ptInt(1,:));
end
end

0 comments on commit 9a750e7

Please sign in to comment.