Code covered by the BSD License  

Highlights from
Extrude a ribbon/tube and fly through it!

5.0

5.0 | 6 ratings Rate this file 13 Downloads (last 30 days) File Size: 4.32 KB File ID: #25086
image thumbnail

Extrude a ribbon/tube and fly through it!

by Teja Muppirala

 

20 Aug 2009 (Updated 24 Dec 2009)

Extrude a 2D curve along a 3D path to create tubes/ribbons and then fly though it

| Watch this File

File Information
Description

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 cross-section is my favorite. Try changing the colormap as well.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
3d, cylinders, extrude, fly, graphics, ribbons, tubes(2)
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
18 Nov 2012 Francis Chen  
05 Apr 2012 Steeve A.  
02 Jan 2012 ashwin devotta

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 X-Z 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 X-Y 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.

07 Sep 2010 Ramana Govindasamy

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*(1-cos(q))*diag(dot(Z,base));
redr = 0.005*base;
base = base-redr;
camdata = camdata*cos(q) + cross([z z],camdata)*sin(q)+[z z]*(1-cos(q))*diag(dot([z z],camdata));

dCvec_prev = dCvec;
end

07 Sep 2010 Ramana Govindasamy

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

06 Sep 2010 Teja Muppirala

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 * (100-Z) .* cos(P);
Y = R0 * (100-Z) .* 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

06 Sep 2010 Ramana Govindasamy

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

14 Jan 2010 daf

Thanks a lot. Teja.

13 Jan 2010 Teja Muppirala

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

13 Jan 2010 daf

sorry! This message should be to Teja. sorry about that

13 Jan 2010 daf

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*(1-cos(q))*diag(dot(Z,base));
Thank you very much!

12 Jan 2010 Rob Campbell

Very clever!

16 Dec 2009 Teja Muppirala

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

15 Dec 2009 Yuval

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.

09 Sep 2009 Andreas

Wicked Sick!

Updates
08 Sep 2009

Made a few minor changes in the algorithm

08 Sep 2009

Made some minor corrections

18 Dec 2009

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

24 Dec 2009

Fixed a minor bug...

24 Dec 2009

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

Contact us