Re: Tube plot function in Mathematica???
- To: mathgroup at smc.vnet.net
- Subject: [mg108579] Re: Tube plot function in Mathematica???
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Wed, 24 Mar 2010 04:42:01 -0500 (EST)
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 <cosmicvoyager at 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