File Exchange

image thumbnail


version (918 Bytes) by Daniel Claxton
FRENET - Frenet-Serret Space Curve Invarients


Updated 01 Jun 2006

No License

FRENET - Frenet-Serret Space Curve Invarients

[T,N,B,k,t] = frenet(x,y);
[T,N,B,k,t] = frenet(x,y,z);

Returns the 3 vector and 2 scaler
invarients of a space curve defined
by vectors x,y and z. If z is omitted
then the curve is only a 2D,
but the equations are still valid.

_ r'
T = ---- (Tangent)

_ T'
N = ---- (Normal)
_ _ _
B = T x N (Binormal)

k = |T'| (Curvature)

t = dot(-B',N) (Torsion)

theta = 2*pi*linspace(0,2,100);
x = cos(theta);
y = sin(theta);
z = theta/(2*pi);
[T,N,B,k,t] = frenet(x,y,z);
line(x,y,z), hold on


See also: GRADIENT

Cite As

Daniel Claxton (2021). Frenet (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

Maria M.

Output for torsion is incorrect. Decided not to spend time trying to fix it. Try instead!

Graham W Griffiths

Good function. However, I assume that using dx = gradient(x), etc. implies that the spacing in vector x should be uniform. If this is the case it should be made clear, as for many problems this will not be the case. For non-uniform spacing Fornberg's weights() function can be used to obtain an accurate gradient.
Ref: Bengt Fornberg (2010), Finite differences, Scholarpedia, 6(10):9685.






The torsion formula used in the code is not correct. It is not dot(-B,N) but dot(-B',N). Could you please check. Thanks


Marc Cote

With the correction of Peter Vatter, everything is working fine.


Marc Cote

Peter Vatter

Thanks for the very nice code. It's the only piece I know which implements the way back - from a point cloud to the curvature and torsion values. Only the calculation of the torsion is actually incorrect. For an generic helix the calculated torsion is not constant. The fix by G.Z. unfortunately didn't work for me. I corrected the code as following (altough it certainly can be done shorter and easier):

dddx = gradient(ddx);
dddy = gradient(ddy);
dddz = gradient(ddz);
dddr = [dddx dddy dddz];

t = vdot(cross(dr, ddr), dddr) ./ mag(cross(dr, ddr),1).^2;

function N = vdot(A, B)
%row-wise dot-product of A and B
for i=1:size(A,1)
N(i) = dot(A(i,:), B(i,:));

david Fernandez

Thanks it works perfect! but the example is wrong write, you have to transpose the T to use quiver3:

G. Z.

Hi all,
It is a very nice and usefull code, however:
I am no expert on this kind of math, but there may be an error in the torsion calculation in the code:
t = dot(-B,N), instead t = dot(-B',N)
I know that the code as it is now does not give a correct answer for a synthetic helix..
worth checking.

J. Li

It is excellent for a curve that is really smoothly curved.

Do you have any idea how to handle the case that the curve is reduced to a straight line and/or the curved is reduced to a polygon as in the case of a nurb curve of order 2 in the Nurbs toolbox?


MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!