8

J.M.'s answer to Extruding along a path related to custom cross-sections appears to answer a question I have been puzzling over for some time. I am interested in producing a tube with the stadium or stadion cross-section of oblong ductwork. I look at the code and am lost as to how to use it. Any suggestions?

rexacoatl
  • 81
  • 1
  • 1
    You only have to provide a path and a cross section to @J.M.'s TubePolygons[]. Please be more specific about your doubts. – Dr. belisarius Feb 19 '13 at 19:09
  • Try ListPlot@cs you can see the cross section @J.M is using! So what you need to do is discretize your custom cross-section into some 2D points and declare it as cs. And you will be done. – PlatoManiac Feb 19 '13 at 19:21
  • +1 simply for drawing my attention to a really cool answer I'd previously missed – Mr.Wizard Feb 19 '13 at 21:18

1 Answers1

14

I'll just dissect a little @J.M.'s answer for you:

First define a path:

path = ParametricPlot3D[
        BSplineFunction[{{0, 0, 0}, {1, 1, 1}, {2, -1, -1}, {3, 0, 1}, {4, 1, -1}}][u] 
                        // Evaluate, {u, 0, 1}, MaxRecursion -> 1]

Mathematica graphics

Now extract the Line[] definitions from that plot:

pathL = First@Cases[path, Line[l_] :> l, Infinity]

Do the same with the cross section:

cs = ParametricPlot[BSplineFunction[{{0., 0.}, {1/4, 0.}, {1/2, 1/8}, {1/4, 1/4}, {0., 1/4}},
                            SplineClosed -> True][u] // Evaluate, {u, 0, 1}, MaxRecursion->1]

Mathematica graphics

Get those lines:

csL = First@Cases[cs, Line[l_] :> l, Infinity]

Now use @JM's function:

Graphics3D[{EdgeForm[], TubePolygons[pathL, csL]}, Boxed -> False]

Mathematica graphics

Edit

Another example:

path = First@Cases[ParametricPlot3D[5 {Sin[u u], Cos[u u], u}, {u, 0, 2 Pi}, 
                                    MaxRecursion -> 1], Line[l_] :> l, Infinity];

cs = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};

Graphics3D[{EdgeForm[], TubePolygons[path, cs]}, Boxed -> False]

Mathematica graphics

...And a last one:

path = First@ Cases[ParametricPlot3D[5 {Sin[u ], Cos[u ], 0}, {u, 0, Pi}, 
                    MaxRecursion -> 1], Line[l_] :> l, Infinity];

cs = First@ Cases[ParametricPlot[{Sin[2 u], Cos@u}, {u, 0, 2 Pi}, 
                  MaxRecursion -> 1], Line[l_] :> l, Infinity];

Graphics3D[{EdgeForm[], TubePolygons[path, cs]}, Boxed -> False]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453