# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Display a dashed tube in 3D graphics

Contributed by:
Jaroslav Kysela

ResourceFunction["DashedTube"][{{ represents a 3D dashed tube around the line joining a sequence of points. | |

ResourceFunction["DashedTube"][{ represents a dashed tube of radius | |

ResourceFunction["DashedTube"][{ specifies a dashing | |

ResourceFunction["DashedTube"][{ specifies a different tube radius at the position of each of the points | |

ResourceFunction["DashedTube"][{{ represents a collection of dashed tubes. | |

ResourceFunction["DashedTube"][ represents a dashed tube around the specified 3D |

ResourceFunction["DashedTube"] renders as a dashed circular 3D tube in Graphics3D.

The syntax of ResourceFunction["DashedTube"] mimics that of Tube, including its modifications using Arrow.

The radius of the tube can be specified either in absolute coordinates, or as Scaled[*s*].

If no explicit radius is specified, ResourceFunction["DashedTube"] uses a default radius of 0.05.

The dashing of ResourceFunction["DashedTube"] can be specified in two ways: either internally using the third argument, in which case the argument is a positive number or a list of such numbers; or externally using dashing primitives Dashed, Dotted, DotDashed, Dashing, and AbsoluteDashing.

In contrast to the default dashing behavior for Line, the absolute specification AbsoluteDashing is turned by ResourceFunction["DashedTube"] automatically into the relative one.

ResourceFunction["DashedTube"][{*pt*_{1},*pt*_{2},…},…] gives a tube consisting of a sequence of straight segments. It is equivalent to ResourceFunction["DashedTube"][Line[{*pt*_{1},…}],…].

The following *curve* specifications can be used:

Line[…] | piecewise line segments |

BezierCurve[…] | composite Bezier curve |

BSplineCurve[…] | B-spline curve |

The following options can be used:

VertexColors | Automatic | vertex colors to be interpolated |

"Each" | False | whether to apply styling to each dashed segment separately |

PlotPoints | 30 | initial number of sampling points of the input curve |

MaxIterations | 20 | maximum number of subdivisions during the sampling |

To create a dashed line that follows the input curve specification, the algorithm first samples the input curve. Once the sufficiently fine sampling is found, the dashing specification is used to assess which sampling points belong to which dashed segment. The output of ResourceFunction["DashedTube"] consists of a collection of properly styled Tube lines, each corresponding to a dashed segment.

If a segment contains only a single point, Ball is used centered around this point, instead of Tube.

The number of initial sample points is given by PlotPoints. If this number is not sufficient, the sampling is refined iteratively until sufficient number is reached or MaxIterations number of iterations is hit.

Because of the sampling procedure, aliasing artifacts may occur, where different segments have varying lengths, even though the dashing specification tells them to be of the same length.

By default, the joins between tube segments are rounded. Different forms of joining between tube segments can be specified using JoinForm.

By default, the ends of the tube are rounded. Different caps for the tube can be specified using CapForm. CapForm[None] specifies that the end of the tube should be left open.

Colors and other material properties of tubes can be specified using color directives as well as Specularity and Glow. Tubes can be specified as transparent using Opacity directives.

Create a simple dashed tube:

In[1]:= |

Out[1]= |

A dashed tube along a curve:

In[2]:= |

Out[2]= |

A dashed tube with radius 0.1:

In[3]:= |

Out[3]= |

A dashed tube with dashing {0.2,0.05}:

In[4]:= |

Out[4]= |

Add an Arrow:

In[5]:= |

Out[5]= |

Differently styled dashed tubes:

In[6]:= |

In[7]:= |

Out[7]= |

Gradient coloring:

In[8]:= |

In[9]:= |

Out[9]= |

Gradient coloring for each segment independently:

In[10]:= |

In[11]:= |

Out[11]= |

Single dashed tube segment:

In[12]:= |

Out[12]= |

Multiple connected dashed tube segments:

In[13]:= |

Out[13]= |

DashedTube can take a line or curve argument:

In[14]:= |

Out[14]= |

Multiple disconnected dashed tube segments:

In[15]:= |

In[16]:= |

Out[16]= |

Use standard coordinates:

In[17]:= |

Out[17]= |

Use Scaled coordinates:

In[18]:= |

Out[18]= |

Dashed tubes with different radii:

In[19]:= |

In[20]:= |

Out[20]= |

Radii can also be specified at vertices:

In[21]:= |

Out[21]= |

Dashed tubes with scaled radii:

In[22]:= |

In[23]:= |

Out[23]= |

Use uniform dashing specified by 0.1:

In[24]:= |

Out[24]= |

Use non-uniform dashing {0.25,0.1}:

In[25]:= |

Out[25]= |

Use more complicated dashing {0.25,0.1,0.05}:

In[26]:= |

Out[26]= |

Dashing can also be specified outside DashedTube using Dashed, Dotted, DotDashed, Dashing, and AbsoluteDashing primitives:

In[27]:= |

Out[27]= |

AbsoluteDashing[*s*] is internally automatically replaced with *s*:

In[28]:= |

Out[28]= |

When both the external modifier such as Dashed and the explicit dashing specification inside DashedTube is used, the latter gets precedence:

In[29]:= |

Out[29]= |

Colored dashed tubes:

In[30]:= |

In[31]:= |

Out[31]= |

Different properties can be specified for the front and back faces using FaceForm:

In[32]:= |

Out[32]= |

Dashed tube caps can be specified using CapForm:

In[33]:= |

Out[33]= |

Joining of dashed tube segments can be specified using JoinForm:

In[34]:= |

Out[34]= |

Colors can be specified at vertices using VertexColors:

In[35]:= |

Out[35]= |

Specify color gradient over the tube:

In[36]:= |

Out[36]= |

Use the same gradient for each segment separately:

In[37]:= |

Out[37]= |

By default, the styling as well as Arrow are applied to the DashedTube globally:

In[38]:= |

Out[38]= |

To apply the styling and arrows to each segment separately, set "Each" to True:

In[39]:= |

Out[39]= |

To apply an arrow to each segment of a DashedTube that has a global styling, use a simple replacement:

In[40]:= |

In[41]:= |

Out[41]= |

For some combinations of curves and dashing specifications, the sampling process may introduce aliasing artifacts or cusps:

In[42]:= |

Out[42]= |

Increase the initial number of sampling points:

In[43]:= |

Out[43]= |

Manual setting of the sampling number may lead to excessive number of resulting points that make up the tube segments:

In[44]:= |

Out[44]= |

For some combinations of curves and dashing specifications, the sampling process may introduce aliasing artifacts or cusps:

In[45]:= |

Out[45]= |

Increase the number of division steps in the sampling process to adaptively find an optimum number of sampling points:

In[46]:= |

Out[46]= |

The number of points that make up the tube segments is chosen to be minimum and still sufficient:

In[47]:= |

Out[47]= |

Plot a parametric space curve and replace the curve with a dashed tube:

In[48]:= |

Out[48]= |

DashedTube can be used with Arrow for dashed 3D arrows:

In[49]:= |

Out[49]= |

Define a 3D coordinate system with dashed axes:

In[50]:= |

Out[50]= |

When no dashing is specified, the DashedTube gives identical results to Tube:

In[51]:= |

Out[51]= |

Use Arrow with DashedTube to get a dashed 3D arrow:

In[52]:= |

Out[52]= |

Use Dashing specification outside DashedTube to set its dashing:

In[53]:= |

Out[53]= |

Use dashing primitives Dashed, Dotted, and DotDashed to specify the dashing:

In[54]:= |

Out[54]= |

One can readily mimic the action of DashedTube, provided the uniformity of the dashing is not an issue:

In[55]:= |

In[56]:= |

Out[56]= |

DashedTube tries to keep the dashing uniform:

In[57]:= |

Out[57]= |

In some cases, aliasing artifacts may occur:

In[58]:= |

Out[58]= |

Increase the number of sampling iterations:

In[59]:= |

Out[59]= |

From the way how the built-in arrows are handled, undesired behavior may occur when DashedTube is used with Arrow:

In[60]:= |

Out[60]= |

This effect can be mitigated by removing several last segments from the dashed tube:

In[61]:= |

In[62]:= |

Out[62]= |

When Arrow is used together with VertexColors and "Each"→True, the color gradients are ignored and only the last color is used for each segment:

In[63]:= |

In[64]:= |

Out[64]= |

DashedTube makes no difference between the dashing specified using absolute and standard units:

In[65]:= |

Out[65]= |

Compare this with the default behavior for Line:

In[66]:= |

Out[66]= |

When JoinForm is set to "Miter", the result may not be discernible from that for "Bevel":

In[67]:= |

Out[67]= |

The reason is that the dashed tube consists of many points and the joints are effectively smooth, resulting in no visible cusp:

In[68]:= |

In[69]:= |

Out[69]= |

When only the essential points are retained, one recovers the expected behavior:

In[70]:= |

In[71]:= |

Out[71]= |

The external dashing specification has to be in the same List with DashedTube, otherwise it is ignored:

In[72]:= |

Out[72]= |

Flatten the whole list:

In[73]:= |

Out[73]= |

Alternatively, put the Dashing construct into each sublist:

In[74]:= |

Out[74]= |

Dashed tube curves with interpolated radii:

In[75]:= |

Out[75]= |

Using random radii:

In[76]:= |

In[77]:= |

Out[77]= |

Create a curve composed of balls:

In[78]:= |

In[79]:= |

Out[79]= |

- 1.0.0 – 22 November 2021

This work is licensed under a Creative Commons Attribution 4.0 International License