How to Correct Curvature and Torsion in a Frenet-Serret MATLAB Function?

In summary, the conversation discussed a function for calculating the Normal, Binormal, and Tangent vectors of a curve defined by x,y,z coordinates, as well as the curvature and torsion. The speaker mentioned that the curvature values were not correct and asked for help in improving them. The code for the function was also shared and some possible issues with the calculations were discussed, such as using the incorrect norm function and having incorrect input data. The speaker also suggested plotting the vectors to validate their accuracy.
  • #1
mpassman
5
0
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
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 news on Phys.org
  • #2


% Torsion
for i=1:length(x)
t(i) = dot(cross(dT(i,:),dB(i,:)),N(i,:))/norm(dT(i,:),2)^2;
end

% Return the results
T = T';
N = N';
B = B';
k = k';
t = t';

% Display results
disp('Tangent Vector:');
disp(T);
disp('Normal Vector:');
disp(N);
disp('Binormal Vector:');
disp(B);
disp('Curvature:');
disp(k);
disp('Torsion:');
disp(t);

Hello, thank you for sharing your function. I took a look at your code and it seems like you are on the right track. However, there are a few things that might be causing the incorrect curvature and torsion values.

Firstly, I noticed that you are using the norm function to calculate the curvature and torsion. The norm function calculates the Euclidean norm, which is not appropriate for calculating curvature and torsion. Instead, you should be using the norm of the derivative of the tangent and binormal vectors, respectively. This is because curvature and torsion are related to the rate of change of the tangent and binormal vectors, not their magnitude.

Secondly, it might be helpful to check your calculations for the tangent, normal, and binormal vectors. One way to do this is to plot them and see if they make sense in the context of your curve. For example, the tangent vector should always be tangent to the curve, the normal vector should be perpendicular to the tangent vector, and the binormal vector should be perpendicular to both the tangent and normal vectors.

Lastly, make sure that your input data is correct. If your x,y,z coordinates are not ordered correctly or have any missing data, it could affect the accuracy of your results.

I hope this helps. Good luck with your function!
 
  • #3



% Torsion
for i=1:length(x)
t(i) = dot(dT(i,:),cross(T(i,:),N(i,:)))/norm(cross(T(i,:),N(i,:)),2);
end

% Return the vectors and values
T = T;
N = N;
B = B;
k = k;
t = t;

% Display results
disp('Tangent Vector:')
disp(T)
disp('Normal Vector:')
disp(N)
disp('Binormal Vector:')
disp(B)
disp('Curvature:')
disp(k)
disp('Torsion:')
disp(t)

I would first commend the programmer for creating a function to calculate the Frenet-Serret vectors. This is a useful tool in studying curves and their properties.

However, it is important to ensure the accuracy of the results. The programmer acknowledges that the function may have issues with calculating the curvature and torsion. I would suggest checking the mathematical equations used in the function and comparing them to known equations for calculating curvature and torsion. Additionally, it may be helpful to test the function with known curves to verify the results.

Furthermore, it may be beneficial to include comments in the code to explain the steps and equations used. This can help with troubleshooting and improving the function in the future.

Overall, I appreciate the effort put into creating this function and believe with some adjustments and testing, it can be a valuable tool for studying curves.
 

1. What is the Frenet-Serret MatLab function used for?

The Frenet-Serret MatLab function is used for computing the Frenet-Serret frame of a curve in three-dimensional space. This frame consists of three orthonormal vectors that describe the local geometry and orientation of the curve at each point.

2. How does the Frenet-Serret MatLab function work?

The function works by taking in a set of points that define a curve in three-dimensional space and then uses mathematical equations to calculate the tangent, normal, and binormal vectors at each point. These vectors are then used to construct the Frenet-Serret frame.

3. What is the input format for the Frenet-Serret MatLab function?

The input for the function is a set of three-dimensional points, either in the form of a matrix or as separate arrays for the x, y, and z coordinates. These points should be ordered along the curve in a sequential manner.

4. Can the Frenet-Serret MatLab function handle curves with sharp turns or cusps?

Yes, the function is able to handle curves with sharp turns or cusps. However, in these cases, the Frenet-Serret frame may not be well-defined at the point of the turn or cusp, as the tangent, normal, and binormal vectors may not exist or may be discontinuous.

5. How accurate is the Frenet-Serret MatLab function?

The accuracy of the function depends on the smoothness of the curve and the number of points used to define it. In general, the more points used, the more accurate the Frenet-Serret frame will be. However, for highly irregular or discontinuous curves, the accuracy may be limited.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
928
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
Replies
3
Views
572
Replies
3
Views
1K
Replies
8
Views
782
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
Replies
1
Views
2K
Back
Top