Discontinuous Tube visualization
Update: You can use your function TR
with RegionFunction
:
a = 2; h = 0.4 a; thmax = 10;
ParametricPlot3D[{a Cos[th], a Sin[th], h th/(2 Pi)}, {th, 0, thmax},
PlotStyle -> {Red, Tube[.2]}, Axes -> False, Boxed -> False, PlotRange -> All,
RegionFunction-> (TR[#4] == .2&)]
Alternatively, use it with ConditionalExpression
(or with Piecewise
) to change the first argument of ParametricPlot3D
:
ParametricPlot3D[ConditionalExpression[{a Cos[th], a Sin[th], h th/(2 Pi)}, TR[th]==.2],
{th, 0, thmax},
PlotStyle -> {Red,Tube[.2]}, Axes -> False, Boxed -> False, PlotRange -> All]
same picture
Original answer:
Using MeshFunctions
+ Mesh
+ MeshShading
:
n = 1000;
ParametricPlot3D[{Cos[th], Sin[th], th/5}, {th, 0, thmax},
PlotStyle -> Yellow, Axes -> False, Boxed -> False, PlotRange -> All,
BaseStyle -> Directive[CapForm["Butt"], JoinForm["Round"]],
MeshFunctions -> {#4 &},
Mesh -> {Subdivide[0, thmax, n]},
MeshStyle -> Opacity[0],
MeshShading -> {Red, None}] /. Line -> (Tube[#, .18] &)
Neat Examples:
Play with combinations of CapForm["Butt"]
/CapForm[None]
and MeshShading -> {Red, None}
/ MeshShading -> Dynamic @ {RandomColor[], None}
to get nice effects like:
With n = 500
, change the replacement rule to
Line -> (Dynamic[Tube[#, RandomReal[{.05, .3}]]] &)
to make the tube radii random to get effects like:
Note: MichaelE2 brought to my attention that in version 12 the code above produces tube segments with rounded caps like this.
Changing MeshShading
to
MeshShading -> {Opacity[.99999, Red], None}
or changing the post-processing rule to
{Line -> (Tube[#, .18]& ), r_RGBColor :> Opacity[.999, r] }
or to
Line-> (Tube[#, .18] & /@ Partition[#, 2, 1]& )
fixes this issue (don't know why/how though). Perhaps, the issue reported in this q/a that is supposed to be fixed in v10.2 lingers.
Yet another fix is to add the option
Method -> {"TubePoints" -> 50}
to ParametricPlot3D
.
It works for me if you add more PlotPoints
and let MaxRecursion
wild
ParametricPlot3D[
{Cos[th], Sin[th], th/5}
, {th, 0, thmax}
, PlotStyle -> {Red, Tube[TR[th]]}
, Axes -> False
, Boxed -> False
, PlotRange -> All
, PlotPoints -> 5000
, MaxRecursion -> Infinity
]