8
$\begingroup$

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?

$\endgroup$
3
  • 1
    $\begingroup$ You only have to provide a path and a cross section to @J.M.'s TubePolygons[]. Please be more specific about your doubts. $\endgroup$ Feb 19, 2013 at 19:09
  • $\begingroup$ 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. $\endgroup$ Feb 19, 2013 at 19:21
  • $\begingroup$ +1 simply for drawing my attention to a really cool answer I'd previously missed $\endgroup$
    – Mr.Wizard
    Feb 19, 2013 at 21:18

1 Answer 1

14
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ That's great, Belisarius, got it to work. Many thanks. Any thoughts on how to make TubePolygons have the equivalent of CapForm["Round"] for Tube? $\endgroup$
    – rexacoatl
    Feb 25, 2013 at 23:53
  • $\begingroup$ @rexacoatl That doesn't seem trivial at all $\endgroup$ Feb 26, 2013 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.