-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcurvature.m
More file actions
35 lines (33 loc) · 1009 Bytes
/
Copy pathcurvature.m
File metadata and controls
35 lines (33 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function [L,R,k] = curvature(X)
% Radius of curvature and curvature vector for 2D or 3D curve
% [L,R,k] = curvature(X)
% X: 2 or 3 column array of x, y (and possibly z) coordiates
% L: Cumulative arc length
% R: Radius of curvature
% k: Curvature vector
% The scalar curvature value is 1./R
% Version 2.6: Calculates end point values for closed curve
N = size(X,1);
dims = size(X,2);
if dims == 2
X = [X,zeros(N,1)]; % Use 3D expressions for 2D as well
end
L = zeros(N,1);
R = NaN(N,1);
k = NaN(N,3);
for i = 2:N-1
[R(i),~,k(i,:)] = circumcenter(X(i,:)',X(i-1,:)',X(i+1,:)');
L(i) = L(i-1)+norm(X(i,:)-X(i-1,:));
end
if norm(X(1,:)-X(end,:)) < 1e-10 % Closed curve.
[R(1),~,k(1,:)] = circumcenter(X(end-1,:)',X(1,:)',X(2,:)');
R(end) = R(1);
k(end,:) = k(1,:);
L(end) = L(end-1) + norm(X(end,:)-X(end-1,:));
end
i = N;
L(i) = L(i-1)+norm(X(i,:)-X(i-1,:));
if dims == 2
k = k(:,1:2);
end
end