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.(adsbygoogle = window.adsbygoogle || []).push({});

Code (Text):

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

% 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

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Frenet-Serret MatLab Function

Can you offer guidance or do you also need help?

**Physics Forums | Science Articles, Homework Help, Discussion**