5

I know Mathematica has a built in Tube function, but I want to be able to change the parameters of a ribbon and visualize that. Is this possible? How do I do this?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
user37531
  • 59
  • 2

3 Answers3

15

I don't think there is a special ribbon function. But you can plot one pretty easily. Here's an example. The functions x[u] and y[u] define a curve in space and then z[s] gives it width.

x[u_] := Sin[u] u^2
y[u_] := 2 Cos[u] + u^2
z[s_] := s
ParametricPlot3D[{x[u], y[u], z[s]}, {u, 0, 6}, {s, -2, 2}, 
  Boxed -> False, Axes -> False]

enter image description here

Here's another with some extra styling:

ParametricPlot3D[{Sin[u], Cos[u] , u/10 + s}, {u, 0, 20}, {s, -0.1, 0.1}, 
  Mesh -> None, Boxed -> False, Axes -> False, 
  PlotStyle -> Directive[Green, Opacity[0.5], Specularity[White, 20]]]

enter image description here

bill s
  • 68,936
  • 4
  • 101
  • 191
2

Borrowing some of the auxiliary routines from this answer, here is a routine for producing a ribbon:

RibbonPolygons[path_?MatrixQ, {p1_?VectorQ, p2_?VectorQ}] := 
      With[{pts = Flatten[FoldList[
                          Function[{p, t}, 
                                   With[{o = orthogonalDirections[t]}, 
                                   extend[#, t[[2]], t[[2]] - t[[1]], o] & /@ p]], 
                          crossSection[path, 1, {p1, p2}], 
                          Partition[path, 3, 1, {1, 2}, {}]], 1]}, 
           GraphicsComplex[pts, Polygon[Partition[Range[Length[pts]],
                                                  4, 2][[All, {3, 4, 2, 1}]]]]]

path is a list of points on the given space curve, while p1 and p2 are any two points forming a line in the $x$-$y$ plane, which control the width and orientation of your ribbon. Tweak as needed.

Try it out:

path = First @ Cases[ParametricPlot3D[BSplineFunction[
       {{0, 0, 0}, {1, 1, 1}, {2, -1, -1}, {3, 0, 1}, {4, 1, -1}}][u] // Evaluate,
       {u, 0, 1}, MaxRecursion -> 1], Line[l_] :> l, Infinity];

Graphics3D[{EdgeForm[], RibbonPolygons[path, {{0, 0}, {1, 1}}]}, Boxed -> False]

some ribbon

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
0

More of an extended comment for now, rather than an answer (but I'll expand this as soon as I have time).

The answers here so far do not seem to address the fact, that a ribbon is a physical object of sorts, therefore its orientation is not arbitrary.
EDIT Actually I'm probably wrong, and J.M. does seem to do that with the undefined function orthogonaldirections in his answer End edit

In fact, if we start with a flat rectangular ribbon, and force it along a certain curve, the plane of the ribbon at any given point will be perpendicular to the plane of the curve.

To convert an arbitrary 3d parametric curve to a ribbon I use for example:

curve[t_] := {Log[t], Cos[t], Sin[t]};
(.1 w #)/Norm@# &@Cross[curve'[t], curve''[t]];
ParametricPlot3D[curve[t] + %, {t, .1, 10}, {w, -1, 1}]

This ensures that the ribbon is properly oriented in space. Once I have time, I'll see if I can generalize the code a bit for non-curved segments and have the orientation of the ribbon there as a function of t as well.

LLlAMnYP
  • 11,486
  • 26
  • 65