MATLAB Frenet-Serret MatLab Function

mpassman

Hello, I have a function to return the Normal, Binormal and Tangent vectors of a curve defined by lots of x,y,z coordinates. It should also return torsion and curvature but I know that the curvature is certainly not correct. I'm pretty sure the vectors are right, but the curvature and possible torsion is not right. Any help much, much appreciated.

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
dr = [dx dy dz];

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

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);

dB = [dBx dBy dBz];

% Curvature

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

Related Math Software Workshop News on Phys.org

"Frenet-Serret MatLab Function"

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving