Generalized tubular plots (canal surfaces)

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


plot::Tube([x, y, z], <r>, t = tmin .. tmax, <a = amin .. amax>, options)


plot::Tube creates generalized tubular plots, known as “canal surfaces”, with special cases known as “tube surface”, “pipe surface” or “tubular surfaces.”

Intuitively, canal surfaces are space curves with thickness. More formally, a canal surface plot::Tube([x(t), y(t), z(t)], r(t), t = t_min..t_max) is the envelope of spheres with center [x(t), y(t), z(t)] and radius r(t), i.e., the thickness of the curve can vary with the curve parameter t.


AttributePurposeDefault Value
AffectViewingBoxinfluence of objects on the ViewingBox of a sceneTRUE
AngleEndend of angle range2*PI
AngleBeginbegin of angle range0
AngleRangeangle range0 .. 2*PI
Filledfilled or transparent areas and surfacesTRUE
FillColorcolor of areas and surfacesRGB::Red
FillColor2second color of areas and surfaces for color blendsRGB::CornflowerBlue
FillColorTypesurface filling typesDichromatic
FillColorFunctionfunctional area/surface coloring 
FillColorDirectionthe direction of color transitions on surfaces[0, 0, 1]
FillColorDirectionXx-component of the direction of color transitions on surfaces0
FillColorDirectionYy-component of the direction of color transitions on surfaces0
FillColorDirectionZz-component of the direction of color transitions on surfaces1
Framesthe number of frames in an animation50
Legendmakes a legend entry 
LegendTextshort explanatory text for legend 
LegendEntryadd this object to the legend?TRUE
LineColorcolor of linesRGB::Black.[0.25]
LineWidthwidth of lines0.35
LineColor2color of linesRGB::DeepPink
LineColorTypeline coloring typesFlat
LineColorFunctionfunctional line coloring 
LineColorDirectionthe direction of color transitions on lines[0, 0, 1]
LineColorDirectionXx-component of the direction of color transitions on lines0
LineColorDirectionYy-component of the direction of color transitions on lines0
LineColorDirectionZz-component of the direction of color transitions on lines1
Meshnumber of sample points[60, 11]
Namethe name of a plot object (for browser and legend) 
ParameterEndend value of the animation parameter 
ParameterNamename of the animation parameter 
ParameterBegininitial value of the animation parameter 
ParameterRangerange of the animation parameter 
PointsVisiblevisibility of mesh pointsFALSE
RadiusFunctionradius of a tube plot1/10
Shadingsmooth color blend of surfacesSmooth
Submeshdensity of submesh (additional sample points)[0, 1]
TimeEndend time of the animation10.0
TimeBeginstart time of the animation0.0
TimeRangethe real time span of an animation0.0 .. 10.0
Titleobject title 
TitleFontfont of object titles[" sans-serif ", 11]
TitlePositionposition of object titles 
TitleAlignmenthorizontal alignment of titles w.r.t. their coordinatesCenter
TitlePositionXposition of object titles, x component 
TitlePositionYposition of object titles, y component 
TitlePositionZposition of object titles, z component 
ULinesVisiblevisibility of parameter lines (u lines)TRUE
UMaxfinal value of parameter “u” 
UMeshnumber of sample points for parameter “u”60
UMininitial value of parameter “u” 
UNamename of parameter “u” 
URangerange of parameter “u” 
USubmeshdensity of additional sample points for parameter “u”0
VLinesVisiblevisibility of parameter lines (v lines)TRUE
VMeshnumber of sample points for parameter “v”11
VSubmeshdensity of additional sample points for parameter “v”1
VisibleAfterobject visible after this time value 
VisibleBeforeobject visible until this time value 
VisibleFromToobject visible during this time range 
VisibleAfterEndobject visible after its animation time ended?TRUE
VisibleBeforeBeginobject visible before its animation time starts?TRUE
XFunctionfunction for x values 
YFunctionfunction for y values 
ZFunctionfunction for z values 


Example 1

A torus can be drawn as a tube around a circle:

plot(plot::Tube([cos(t), sin(t), 0], 0.4,
     t = 0..2*PI))

Varying the diameter of the tube, we deform the torus into a cyclide:

plot(plot::Tube([cos(t), sin(t), 0], 0.4 + 0.3*cos(t),
     t = 0..2*PI))

Example 2

All surfaces of revolution are special cases of canal surfaces:

plot(plot::Scene3d(plot::XRotate(sin(u), u = 0..10)),
     plot::Scene3d(plot::ZRotate(sin(u), u = 0..10)),
     plot::Scene3d(plot::Tube([u, 0, 0], sin(u), u = 0..10)),
     plot::Scene3d(plot::Tube([0, 0, sin(u)], u, u = 0..10)),
     Width = 180 * unit::mm)

The last image shows that the defaults for the mesh are not always adequate and should be changed:

plot(plot::Tube([0, 0, sin(u)], u, u = 0..10,
                Mesh = [20, 20]))

Example 3

The famous Klein bottle can be obtained from a “drop silhouette” by using an appropriate radius parametrization:

plot(plot::Tube([6*cos(u)*(sin(u) - 1), 0, 14*sin(u)],
                4 - 2*cos(u), u = -PI..PI))

Example 4

Re-using the cyclide from above, we demonstrate coloring a canal surface:

color := (t, phi) -> RGB::fromHSV([(t+sin(4*phi))*180/PI, 1, 1]):
plot(plot::Tube([sin(t), cos(t), 0], 0.4 + 0.3*cos(t), t=0..2*PI,
                FillColorFunction = color))

Example 5

Yet another variation of the cyclide, we use a non-constant AngleRange to “slice” it:

plot(plot::Tube([sin(t), cos(t), 0], 0.4 - 0.3*sin(t), t=0..2*PI,
                AngleRange = 0 .. 2*PI*sin(abs(t-PI/2)/2)),
     Axes = None, CameraDirection = [14, 1, 5])

Combining more than one tubular plot with identical spine curves but different angle ranges, we can achieve a braid-like effect:

braid := i ->
   plot::Tube([sin(u), cos(u), 0], 0.2, u=0..2*PI,
              AngleRange = i*PI/3 + 3*u .. i*PI/3 + 3*u + 1/2,
              Color = RGB::EmeraldGreen, Mesh = [60, 2]):
torus := plot::Tube([sin(u), cos(u), 0], 0.18, u=0..2*PI,
                    Color = RGB::BlueLight,
                    Name = "Torus"):
plot(braid(i) $ i = 0..5,
     ULinesVisible = FALSE, VLinesVisible = FALSE,
     FillColorType = Flat,
     Axes = None, CameraDirection = [0, 7, 10])

Example 6

The spine curve, the radius function, color functions etc. can be animated as usual:

plot(plot::Tube([sin(t)*sin(a), cos(t)*cos(a), sin(a)],
                0.4 - 0.3*sin(t-a),
                t = 0..2*PI, a = 0..2*PI,
                Frames = 20, TimeRange = 0..5))

Example 7

Note that in the presence of a sharp bend (in relation to the tube diameter), the surface plotted my plot::Tube may self-intersect:

plot(plot::Tube([x, 0, x^2], 1.2, x = -1.4..1.4,
                Mesh = [20, 10]),
     Axes = None, CameraDirection = [-3, 1, 2])

This effect is unavoidable. Sharp bends also cause another effect which can be avoided by increasing the mesh density: The tube might not follow the curve quickly enough:

plot(plot::Tube([sin(x^2), x, 0], x = -5..0))

In this situation, you can set USubmesh to a positive value to request additional function evaluations:

plot(plot::Tube([sin(x^2), x, 0], x = -5..0, USubmesh = 5))


x, y, z

The spine curve coordinates: real-valued expressions in t and the animation parameter.

x, y, z are equivalent to the attributes XFunction, YFunction, ZFunction.


The tube radius: a real-valued expression in t and the animation parameter. Default is the constant .

r is equivalent to the attribute RadiusFunction.


The curve parameter: an (indexed) identifier.

t is equivalent to the attribute UName.

tmin .. tmax

The range of the curve parameter: real-valued expressions in the animation parameter.

tmin .. tmax is equivalent to the attributes URange, UMin, UMax.


Animation parameter, specified as a = amin..amax, where amin is the initial parameter value, and amax is the final parameter value.

See Also

MuPAD Functions

MuPAD Graphical Primitives