Sweeps out a 2D cross section (a circle, square, whatever, doesn't even have to be a closed path) through a 3D curve, and returns the generated surface as [X,Y,Z] for use with SURF.
Also, as a fun option, it will fly through the path generated, which looks really cool if you have a fast computer and you maximize the figure. In the DEMO mode, the ROAD crosssection is my favorite. Try changing the colormap as well.
Teja Muppirala (2020). Extrude a ribbon/tube and fly through it! (https://www.mathworks.com/matlabcentral/fileexchange/25086extrudearibbontubeandflythroughit), MATLAB Central File Exchange. Retrieved .
1.7.0.1  Updated license 

1.7.0.0  Sorry, one more fix (this time it's really OK) 

1.5.0.0  Fixed a minor bug... 

1.4.0.0  I added an option to close off the ends. I also changed the order of the input arguments. 

1.2.0.0  Made some minor corrections 

1.1.0.0  Made a few minor changes in the algorithm 
Create scripts with code, output, and formatted text in a single executable document.
Is there a way I can animate the extrusion? Thanks.
Hi Teja,
that is an excelent work
i would like to extrude a tube from a 3D curve along a 3d path, tin order to create a tube take into account the warping of the crosssections , could you help me ?
best regards
Hamza
Hi Teja,
I'm a student and I'm working on bar's profile. I would extrude a bar from a line, that I draw on MRI slice and I don't want a twisted one. Could you help me?
Thanks
Rosanna
Hi Teja,
That is a great work.
I have a slightly different problem at hand. I am trying to parametrically model a twist drill.
http://en.wikipedia.org/wiki/Drill_bit
In order to create this, I have a 2 dimensional curve in a plane (A). Plane A is obtained by rotating XZ Plane about Y axis by theta degree. In this case, my base curve contains points in X,Y and Z.
In my case, the trajectory curve is a helical curve.
I want to take the resulting the 3 d curve and obtain a 2 d section in the XY plane.
Is there a way to accomodate this situation in your program. I would be using the Algorithm 2 for this purpose. I want this for academic purpose.
Thanks in advance
Ashwin.
Hi Guys, modification of the code to create a narrowing tube along the axis of extrusion: Additional lines are 169 and 170. Pretty simple!
if norm(z) ~= 0
z = z/norm(z);
q = real(acos(dot(dCvec_prev,dCvec)/norm(dCvec_prev)/norm(dCvec)));
Z = repmat(z,1,npt);
base = base*cos(q) + cross(Z,base)*sin(q)+Z*(1cos(q))*diag(dot(Z,base));
redr = 0.005*base;
base = baseredr;
camdata = camdata*cos(q) + cross([z z],camdata)*sin(q)+[z z]*(1cos(q))*diag(dot([z z],camdata));
dCvec_prev = dCvec;
end
Thanks Teja! It is the latter that I am trying to achieve i.e. a curved axis. The curve is defined by 12 (x,y,z) data points which I have interpolated to generate a curve. I will look at modifying the code and give feedback!
Ramana
Hi Ramana,
I guess there are a couple of things you could do.
If the line to extrude along is straight, you could do something like this using basic MATLAB commands:
[Z,P] = meshgrid(0:1:100,linspace(0,2*pi,101));
R0 = 0.1;
X = R0 * (100Z) .* cos(P);
Y = R0 * (100Z) .* sin(P);
h = surf(X,Y,Z)
rotate(h,[0,0],45)
axis equal
This is an example that just makes a cone along a constant axis.
If you needed the cone to twist around, then I think you would probably have to modify my program a little bit to make the base curve change (get smaller) as you build the surface.
Teja
Hey Teja! Great work. Quick question, how could one extrude a cone along the newly defined 'z' axis? i'.e. I want the radius of the tube to vary along the length of 'z'.
Thanks!
Ramana
Thanks a lot. Teja.
Hi daf,
That line of code is Rodrigues' Rotation Formula:
http://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
Look at the first equation on that wikipedia page. It is how you rotate a point around an axis of unit length. In my case, instead of using a loop to go over all the base the points one by one, I have kind of vectorized it and done it in one line with a little bit of linear algebra.
Teja
sorry! This message should be to Teja. sorry about that
Hi Yuval, thank you for your sharing.But would you please help me the explain the principle of the followwing code:
base = base*cos(q) + cross(Z,base)*sin(q)+Z*(1cos(q))*diag(dot(Z,base));
Thank you very much!
Very clever!
Hi Yuval, thanks for the feedback. I'll update this when I get a chance in the next few days, but all that you need to do to add caps to the ends is add the following in at line 175.
SUR = cat(3,repmat(C(:,1),1,npt),SUR,repmat(C(:,K),1,npt));
Super useful tool for making 3D figures !
Thanks Teja, may the gods of graphics smile upon you.
Feature request: The option to "cap" the end of the tube, so it doesn't look hollow.
Wicked Sick!