MATLAB Frenet-Serret MatLab Function

  • Thread starter mpassman
  • Start date
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.

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

% 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];

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

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

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

Want to reply to this thread?

"Frenet-Serret MatLab Function" You must log in or register to reply here.

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