Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tube plot function in Mathematica???

425 views
Skip to first unread message

NeuroPulse

unread,
Mar 23, 2010, 6:52:47 AM3/23/10
to
Greetings,

New to Mathematica. Can't seem to find a way to plot a line as a tube
like this:

http://facstaff.unca.edu/mcmcclur/java/LiveMathematica/trefoil.html

Seems such an obvious function to have built in. Is there one?

If not, can someone point me to one I can use in Mathematica?

Thanks

dr DanW

unread,
Mar 24, 2010, 5:30:57 AM3/24/10
to
Umm...its called Tube[]. It's a 3D graphics primitive, so you do
Graphics3D[{Tube[...],...}]. It's a new function in version 7.

Daniel

Hans Michel

unread,
Mar 24, 2010, 5:32:15 AM3/24/10
to
NeuroPulse:

See

http://reference.wolfram.com/mathematica/ref/Tube.html

New in version 7.

Hans
"NeuroPulse" <cosmic...@gmail.com> wrote in message
news:hoa6hv$hr0$1...@smc.vnet.net...

Peltio

unread,
Mar 24, 2010, 5:32:04 AM3/24/10
to
NeuroPulse wrote :

>Can't seem to find a way to plot a line as a tube
> like this:
>
> http://facstaff.unca.edu/mcmcclur/java/LiveMathematica/trefoil.html
>
> Seems such an obvious function to have built in. Is there one?
>
> If not, can someone point me to one I can use in Mathematica?

How about that very function?
http://facstaff.unca.edu/mcmcclur/java/LiveMathematica/tubes.html

(first result in google)

cheers,
Peltio


Mark McClure

unread,
Mar 24, 2010, 5:32:59 AM3/24/10
to
On Tue, Mar 23, 2010 at 6:52 AM, NeuroPulse <cosmic...@gmail.com> wrote:

> New to Mathematica. Can't seem to find a way to plot a line as a tube
> like this:
> http://facstaff.unca.edu/mcmcclur/java/LiveMathematica/trefoil.html

The TubePlotFrenet command and the TubePlot command are defined on this webpage:
http://facstaff.unca.edu/mcmcclur/java/LiveMathematica/tubes.html

I did all that quite some time ago and quite a lot of things have
changed since then. There is now a Tube primitive that can generate
nice tubes like so:

trefoil[t_] == {Sin[3 t], Sin[t] + 2 Sin[2 t], Cos[t] - 2 Cos[2 t]};
Graphics3D[{Tube[BezierCurve[Table[trefoil[t],
{t, 0., 2 Pi, Pi/200}]], 0.4]}]


If you still want to try my old TubePlot functions, there are a couple
of things that should be changed. First, a few Simplify commands will
speed things up again. Second, the Lighting specificiations on my
webpage are obsolete. Putting it all together, you can generate a
nice image like so:

TubePlotFrenet[curve_List, {var_, min_, max_}, radius_, opts___] :==
Module[{tangent, unitTangent, normal, unitNormal, biNormal},
tangent == D[curve, t];
unitTangent == Simplify[tangent/Sqrt[tangent.tangent]];
normal == D[unitTangent, t];
unitNormal == Simplify[normal/Sqrt[normal.normal]];
biNormal == Simplify[Cross[unitTangent, unitNormal]];
ParametricPlot3D[Evaluate[curve +
radius Cos[s] unitNormal + radius Sin[s] biNormal],
{var, min, max}, {s, 0, 2 Pi}, opts]];

trefoil[t_] == {Sin[3 t], Sin[t] + 2 Sin[2 t], Cos[t] - 2 Cos[2 t]};
TubePlotFrenet[trefoil[t], {t, 0, 2*Pi}, 0.3,
Axes -> None, Mesh -> Full, Boxed -> False,
ViewPoint -> {10, 0, 0}, PlotPoints -> {64, 16}]

Hope that helps,
Mark McClure

Bob Hanlon

unread,
Mar 24, 2010, 5:33:10 AM3/24/10
to

The code to which you linked works if you take out the outdated option LightSources. You can use Lighting instead (I didn't bother).

TubePlotFrenet[curve_List, {var_, min_, max_},
radius_, opts___] :=

Module[
{tangent, unitTangent, normal, unitNormal, biNormal},

tangent = D[curve, t];
unitTangent = tangent/Sqrt[tangent.tangent];
normal = D[unitTangent, t];
unitNormal = normal/Sqrt[normal.normal];
biNormal = Cross[unitTangent, unitNormal];
ParametricPlot3D[curve + radius Cos[s] unitNormal +
radius Sin[s] biNormal // Evaluate,


{var, min, max}, {s, 0, 2 Pi}, opts]]

trefoil = {Sin[3 t], Sin[t] + 2 Sin[2 t], Cos[t] - 2 Cos[2 t]};

TubePlotFrenet[trefoil, {t, 0, 2*Pi}, 0.3,
Axes -> None,


Boxed -> False,
ViewPoint -> {10, 0, 0},

PlotPoints -> {64, 16},
PlotLabel -> "The Trefoil Knot"]

TubePlot[curve_List, {var_, min_, max_}, radius_,
crossVector_List: {1, 1, 1}, opts___] :=


Module[
{tangent, unitTangent, normal, unitNormal, biNormal},

tangent = D[curve, t];
unitTangent = tangent/Sqrt[tangent.tangent];
normal = Cross[tangent, crossVector];
unitNormal = normal/Sqrt[normal.normal];
biNormal = Cross[unitTangent, unitNormal];
ParametricPlot3D[curve + radius Cos[s] unitNormal +
radius Sin[s] biNormal // Evaluate,


{var, min, max}, {s, 0, 2 Pi}, opts]]

TorusKnotPlot[p_, q_, opts___] :=
TubePlot[{Cos[t] (1 + .5 Cos[(q/p) t]),
Sin[t] (1 + .5 Cos[(q/p) t]), .5 Sin[(q/p) t]},
{t, 0, 2 Pi p}, .1, {0, 0, 1},
ViewPoint -> {0, 0, 1}, Boxed -> False, Axes -> False, opts]

TorusKnotPlot[3, 5,
PlotPoints -> {128, 16},
PlotLabel -> "The (3,5) Torus Knot"]

Alternatively, in a 3D plot replace Line with Tube. Example from Doc Center
http://reference.wolfram.com/mathematica/ref/Tube.html

ParametricPlot3D[
{Cos[2 t], Sin[2 t], Cos[t]}, {t, 0, 2 Pi},
PlotStyle -> Directive[Opacity[0.7], CapForm[None],
JoinForm["Miter"], Red],
PlotRange -> All,
ColorFunction -> Hue,
Boxed -> False,
MaxRecursion -> 0,
PlotPoints -> 100,
Axes -> None,
Method -> {"TubePoints" -> 30}] /.
Line[pts_, rest___] :> Tube[pts, 0.2, rest]


Bob Hanlon

---- NeuroPulse <cosmic...@gmail.com> wrote:

=============
Greetings,

New to Mathematica. Can't seem to find a way to plot a line as a tube
like this:

http://facstaff.unca.edu/mcmcclur/java/LiveMathematica/trefoil.html

Seems such an obvious function to have built in. Is there one?

If not, can someone point me to one I can use in Mathematica?

Thanks

Jaebum Jung

unread,
Mar 24, 2010, 5:34:50 AM3/24/10
to
On 3/23/10 5:52 AM, NeuroPulse wrote:
> Greetings,
>
> New to Mathematica. Can't seem to find a way to plot a line as a tube
> like this:
>
> http://facstaff.unca.edu/mcmcclur/java/LiveMathematica/trefoil.html
>
> Seems such an obvious function to have built in. Is there one?
>
> If not, can someone point me to one I can use in Mathematica?
>
> Thanks
>
>
Check graphics primitive Tube:

http://reference.wolfram.com/mathematica/ref/Tube.html

Here's example,

ParametricPlot3D[{Sin[3t],Sin[t]+2Sin[2t],Cos[t]-2Cos[2t]},{t,0,2
Pi},PlotStyle->Directive[Opacity[0.7],CapForm[None],JoinForm["Miter"],Red],PlotRange->All,ColorFunction->Hue,Boxed->False,MaxRecursion->0,PlotPoints->100,Axes->None,Method->{"TubePoints"->30}]/.Line[pts_,rest___]:>Tube[pts,0.2,rest]

- Jaebum

M.Roellig

unread,
Mar 24, 2010, 5:34:17 AM3/24/10
to
Hi,

actually, if you search for Tube in the Mathematica-Help you will
find all you need. Concerning your example:

ParametricPlot3D[trefoil, {t, 0, 2*Pi}, Axes -> None, Boxed -> False,
PlotRange -> All, ViewPoint -> {10, 0, 0}, PlotPoints -> {64, 16},
PlotLabel -> "The Trefoil Knot"] /.


Line[pts_, rest___] :> Tube[pts, 0.2, rest]


Cheers,

Markus

dh

unread,
Mar 24, 2010, 5:35:01 AM3/24/10
to
Hi,
there is e.g.: Tube. here is an example:
myLine[d_] := Tube[ d, 0.2];
Graphics3D@myLine@Table[{Sin[x], Cos[x], 0.1 x}, {x, 0, 4 Pi, Pi/8}]

Daniel


--

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:d...@metrohm.com>
Internet:<http://www.metrohm.com>


Sjoerd C. de Vries

unread,
Mar 24, 2010, 6:03:05 AM3/24/10
to
Well you probably have not been looking in the documentation for long
as typing the word 'tube' already provides you with the answer.
Something like

Graphics3D[
Tube[Table[{Sin[3 t], Sin[t] + 2 Sin[2 t], Cos[t] - 2 Cos[2 t]}, {t,
0, 2 \[Pi], \[Pi]/40}], 0.1]]

should work for you (at least, if you have version 7). Otherwise you
have to resort to ParametricPlot3D and have a parametric description
of the surface of your object available.

Cheers -- Sjoerd

0 new messages