From 9a750e78e10642fb3cb009ef049cfbbd39131bf7 Mon Sep 17 00:00:00 2001 From: dlegland Date: Fri, 11 Mar 2016 20:05:45 +0100 Subject: [PATCH] polygons2d/polygonSignature.m: returns NaN for non-intersecting edges --- matGeom/polygons2d/polygonSignature.m | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/matGeom/polygons2d/polygonSignature.m b/matGeom/polygons2d/polygonSignature.m index 63f311ca..179b0386 100644 --- a/matGeom/polygons2d/polygonSignature.m +++ b/matGeom/polygons2d/polygonSignature.m @@ -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. @@ -15,7 +17,7 @@ % polygonSignature % % See also -% polygons2d, signatureToPolygon +% polygons2d, signatureToPolygon, intersectRayPolygon % % ------ @@ -46,7 +48,7 @@ % allocate memory nTheta = length(thetaList); -res = zeros(nTheta, 1); +res = NaN * ones(nTheta, 1); % iterate on angles for i = 1:length(thetaList) @@ -54,5 +56,7 @@ 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