From: Matt Passman on
Below is my function:

[code]
function [T,N,B,k,t] = frenet(x,y,z),
% Frenet - Serret Vecotrs
% T = Tangent
% N = Normal
% B = Binormal
% k = curvature
% t = torsion

% If only x and y inputted, set z to all zeros
if nargin == 2,
z = zeros(size(x));
end

% If x, y and z are row vectors, make them colums
x = x(:);
y = y(:);
z = z(:);

%Set up a dr vector
dx = gradient(x);
dy = gradient(y);
dz = gradient(z);
dr = [dx dy dz];

%Compute double derivatives
ddx = gradient(dx);
ddy = gradient(dy);
ddz = gradient(dz);
ddr = [ddx ddy ddz];

% The tangent vector
for i=1:size(x)
T(i,:) = dr(i,:)/norm(dr(i,:),2);
end

dTx = gradient(T(:,1));
dTy = gradient(T(:,2));
dTz = gradient(T(:,3));

dT = [dTx dTy dTz];

% The Normal vecotr
for j=1:size(x)
N(j,:) = dT(j,:)/norm(dT(j,:),2);
end

% The binormal vector
B = cross(T,N);

dBx = gradient(B(:,1));
dBy = gradient(B(:,2));
dBz = gradient(B(:,3));

dB = [dBx dBy dBz];

% Curvature

for i=1:length(x)
k(i) = norm(dT(i,:),2);
t(i) = norm(dB(i,:),2);
end
[/code]

I thought this was working but it seems that at the least the curvature returned is incorrect. When tested with a unit circle, it returns a constant k of 0.01 instead of 1.
I can't for the life of me work out why it's not working.

Any help would be MUCH appreciated,

Regards,

Matt
From: Matt Passman on
Any help someone could provide would be great.

Thanks very much.
 | 
Pages: 1
Prev: Array
Next: Multiple improfile