Skip to content

Commit a7806a0

Browse files
committed
fix bug in normal/curvature when the arrays are multidimensional
1 parent 5775190 commit a7806a0

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

chunkie/+chnk/curvature2d.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function kappa = curvature2d(ptinfo)
2-
%CHNKR.CURVATURE2D signed curvature of points on 2D curve
2+
%CHNK.CURVATURE2D signed curvature of points on 2D curve
33
%
44
% kappa = (x'y''-x''y')/( sqrt(x'^2+y'^2)^3 )
55
%
6-
% Syntax: kappa = chnkr.curvature2d(ptinfo)
6+
% Syntax: kappa = chnk.curvature2d(ptinfo)
77
%
88
% Input:
99
% ptinfo - curve point info struct, with entries
@@ -14,9 +14,11 @@
1414
% Output:
1515
% nrm - (2,:) array containing corresponding normal information
1616
%
17-
% see also CHNKR.NORMAL2D
17+
% see also CHNK.NORMAL2D
1818

1919
d = ptinfo.d;
20+
sh = size(d); sh = sh(2:end);
2021
d2 = ptinfo.d2;
2122
dnrm3 = sqrt(sum(d.^2,1)).^3;
22-
kappa = bsxfun(@rdivide,d(1,:).*d2(2,:)-d(2,:).*d2(1,:),dnrm3);
23+
kappa = bsxfun(@rdivide,d(1,:).*d2(2,:)-d(2,:).*d2(1,:),dnrm3(:).');
24+
if (length(sh) > 1) kappa = reshape(kappa,sh); end

chunkie/+chnk/normal2d.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function nrm = normal2d(ptinfo)
2-
%CHNKR.NORMAL2D normal vector to curve for 2D curves
2+
%CHNK.NORMAL2D normal vector to curve for 2D curves
33
%
4-
% Syntax: nrm = chnkr.normal2d(ptinfo)
4+
% Syntax: nrm = chnk.normal2d(ptinfo)
55
%
66
% Input:
77
% ptinfo - curve point info struct, with entries
@@ -12,8 +12,10 @@
1212
% Output:
1313
% nrm - (2,:) array containing corresponding normal information
1414
%
15-
% see also CHNKR.CURVATURE2D
15+
% see also CHNK.CURVATURE2D
1616

17-
d = ptinfo.d;
18-
dnrm = sqrt(sum(d.^2,1));
19-
nrm = bsxfun(@rdivide,[d(2,:);-d(1,:)],dnrm);
17+
nrm = ptinfo.d;
18+
dnrm = sqrt(sum(nrm.^2,1));
19+
nrm = flipud(nrm);
20+
nrm(2,:) = -nrm(2,:);
21+
nrm = bsxfun(@rdivide,nrm,dnrm);

0 commit comments

Comments
 (0)