How do I plot a space curve as a ribbon?

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?

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Feb 7 '16 at 0:38
• A tube and a ribbon are different things. Would you clarify? – Michael E2 Feb 7 '16 at 0:41
• This link might be useful. – Daniel Lichtblau Feb 7 '16 at 1:10

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]


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]]]


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]


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.

• "undefined function" - I did link to the generalized tube routines in my other answer, tho. ;) – J. M. will be back soon Feb 12 '16 at 9:50
• @J.M. true, I'm just not sure if it does, what it's meant to do -- in my understanding of what's meant to be done :-) – LLlAMnYP Feb 13 '16 at 7:36