Skip to content

Commit

Permalink
fix bug in normal/curvature when the arrays are multidimensional
Browse files Browse the repository at this point in the history
  • Loading branch information
askhamwhat committed Jun 17, 2021
1 parent 5775190 commit a7806a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions chunkie/+chnk/curvature2d.m
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
kappa = bsxfun(@rdivide,d(1,:).*d2(2,:)-d(2,:).*d2(1,:),dnrm3(:).');
if (length(sh) > 1) kappa = reshape(kappa,sh); end
14 changes: 8 additions & 6 deletions chunkie/+chnk/normal2d.m
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
nrm = ptinfo.d;
dnrm = sqrt(sum(nrm.^2,1));
nrm = flipud(nrm);
nrm(2,:) = -nrm(2,:);
nrm = bsxfun(@rdivide,nrm,dnrm);

0 comments on commit a7806a0

Please sign in to comment.