No BSD License  

Highlights from
Frenet

4.5

4.5 | 2 ratings Rate this file 11 Downloads (last 30 days) File Size: 1.77 KB File ID: #11169
image thumbnail

Frenet

by Daniel Claxton

 

23 May 2006 (Updated 01 Jun 2006)

FRENET - Frenet-Serret Space Curve Invarients

| Watch this File

File Information
Description

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)
       |r'|

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

   k = |T'| (Curvature)

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

   Example:
   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
    
quiver3(x,y,z,T(:,1),T(:,2),T(:,3),'color','r')
quiver3(x,y,z,N(:,1),N(:,2),N(:,3),'color','g')
quiver3(x,y,z,B(:,1),B(:,2),B(:,3),'color','b')
legend('Curve','Tangent','Normal','Binormal')

See also: GRADIENT

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
23 Aug 2007 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?

Thanks!

10 Nov 2008 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.
Thanks!
  

10 Mar 2011 david Fernandez

Thanks it works perfect! but the example is wrong write, you have to transpose the T to use quiver3:
 quiver3(x,y,z,T(:,1)',T(:,2)',T(:,3)','color','r')
   quiver3(x,y,z,N(:,1)',N(:,2)',N(:,3)','color','g')
   quiver3(x,y,z,B(:,1)',B(:,2)',B(:,3)','color','y')

30 Nov 2011 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
N=zeros(size(A,1),1);
for i=1:size(A,1)
    N(i) = dot(A(i,:), B(i,:));
end

Please login to add a comment or rating.
Updates
01 Jun 2006

Summary Change

Tag Activity for this File
Tag Applied By Date/Time
frenet Daniel Claxton 22 Oct 2008 08:26:39
normal Daniel Claxton 22 Oct 2008 08:26:39
binormal Daniel Claxton 22 Oct 2008 08:26:39
curve Daniel Claxton 22 Oct 2008 08:26:39
tangent Daniel Claxton 22 Oct 2008 08:26:39
normal Will 02 Oct 2009 14:35:55

Contact us at files@mathworks.com