diff --git a/chunkie/+chnk/curvature2d.m b/chunkie/+chnk/curvature2d.m index 7d35c4c..6247e60 100644 --- a/chunkie/+chnk/curvature2d.m +++ b/chunkie/+chnk/curvature2d.m @@ -1,9 +1,9 @@ function kappa = curvature2d(ptinfo) -%CHNKR.CURVATURE2D signed curvature of points on 2D curve +%CHNK.CURVATURE2D signed curvature of points on 2D curve % % kappa = (x'y''-x''y')/( sqrt(x'^2+y'^2)^3 ) % -% Syntax: kappa = chnkr.curvature2d(ptinfo) +% Syntax: kappa = chnk.curvature2d(ptinfo) % % Input: % ptinfo - curve point info struct, with entries @@ -14,9 +14,11 @@ % Output: % nrm - (2,:) array containing corresponding normal information % -% see also CHNKR.NORMAL2D +% see also CHNK.NORMAL2D d = ptinfo.d; +sh = size(d); sh = sh(2:end); d2 = ptinfo.d2; dnrm3 = sqrt(sum(d.^2,1)).^3; -kappa = bsxfun(@rdivide,d(1,:).*d2(2,:)-d(2,:).*d2(1,:),dnrm3); \ No newline at end of file +kappa = bsxfun(@rdivide,d(1,:).*d2(2,:)-d(2,:).*d2(1,:),dnrm3(:).'); +if (length(sh) > 1) kappa = reshape(kappa,sh); end \ No newline at end of file diff --git a/chunkie/+chnk/normal2d.m b/chunkie/+chnk/normal2d.m index 777a900..0500561 100644 --- a/chunkie/+chnk/normal2d.m +++ b/chunkie/+chnk/normal2d.m @@ -1,7 +1,7 @@ function nrm = normal2d(ptinfo) -%CHNKR.NORMAL2D normal vector to curve for 2D curves +%CHNK.NORMAL2D normal vector to curve for 2D curves % -% Syntax: nrm = chnkr.normal2d(ptinfo) +% Syntax: nrm = chnk.normal2d(ptinfo) % % Input: % ptinfo - curve point info struct, with entries @@ -12,8 +12,10 @@ % Output: % nrm - (2,:) array containing corresponding normal information % -% see also CHNKR.CURVATURE2D +% see also CHNK.CURVATURE2D -d = ptinfo.d; -dnrm = sqrt(sum(d.^2,1)); -nrm = bsxfun(@rdivide,[d(2,:);-d(1,:)],dnrm); \ No newline at end of file +nrm = ptinfo.d; +dnrm = sqrt(sum(nrm.^2,1)); +nrm = flipud(nrm); +nrm(2,:) = -nrm(2,:); +nrm = bsxfun(@rdivide,nrm,dnrm); \ No newline at end of file