5
$\begingroup$
Clear["`.*"]
a = 2; h = 0.4 a ; z[th_] = a th/6; thmax = 10; tr = 0.1 a  ;
aa = ParametricPlot3D[{ a Cos[th], a Sin[th],  h th/( 2 Pi)}, {th, 0, 
   thmax}, PlotStyle -> {Red, Tube[tr]}, Axes -> False, 
  Boxed -> False, PlotRange -> All]
lamb = Pi /2 ;
TR[t_] = tr (SquareWave[t/lamb]/2 + 1/2)
Plot[tr (SquareWave[t/lamb]/2 + 1/2), {t, 0, thmax}, 
 Exclusions -> None]
Plot[TR[t], {t, 0, thmax}]
bb = ParametricPlot3D[{ a Cos[th], a Sin[th],  h th/( 2 Pi)}, {th, 0, 
   thmax}, PlotStyle -> {Red, Tube[TR[th]]}, Axes -> False, 
  Boxed -> False, PlotRange -> All]

enter image description here

An attempt was made to visualize Tube segments cut away at regular intervals of $\theta = (2 k-1)\pi/4$ by function definition (1-0-1-0- amplitude ) type. Expected Tube division image is sketched. Getting such an image was not successful because variable tube radii $( 0.2,0,0.2,0,..)$ as coded here does not work.

Earlier Reap&Sow also did not help.

Please help.

$\endgroup$
  • $\begingroup$ Apologies, the question did not convey properly. So I have redone the entire question with graphics. Hope it is now clearer. $\endgroup$ – Narasimham Jul 20 at 21:31
13
$\begingroup$

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

enter image description here

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

enter image description here

Neat Examples:

Play with combinations of CapForm["Butt"]/CapForm[None] and MeshShading -> {Red, None} / MeshShading -> Dynamic @ {RandomColor[], None} to get nice effects like:

enter image description here

With n = 500, change the replacement rule to

 Line -> (Dynamic[Tube[#, RandomReal[{.05, .3}]]] &)

to make the tube radii random to get effects like:

enter image description here

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.

$\endgroup$
  • 1
    $\begingroup$ It does not work for me :( -- i.stack.imgur.com/YklQ7.png It's more obvious with fewer sections: i.stack.imgur.com/564Gd.png Close-up: i.stack.imgur.com/Uqc3N.png (Version 12.0, Mac) $\endgroup$ – Michael E2 Jul 21 at 1:48
  • $\begingroup$ @MichaelE2, it works in v9./windows10. In v12 (Wolfram Cloud) i got similar issues, but when i copy paste the output into a v9 desktop notebook it renders fine, so i thought the issue is related to browser version. Changing the replacement rule to Line-> (Tube[#, .18]&/@Partition[#,2,1]& ) seems to fix it on the browser version; can you check if it works in v12 desktop? $\endgroup$ – kglr Jul 21 at 2:07
  • 1
    $\begingroup$ Yes, the cylindrical disks are properly separated. However, there is a yellow line threading through them: i.stack.imgur.com/jhdQS.png - Is that supposed to be there? I thought it would have been the Line that was replaced. $\endgroup$ – Michael E2 Jul 21 at 3:09
  • $\begingroup$ @MichaelE2, those are mesh points styled wrong; MeshStyle -> Opacity[0] fixes it. $\endgroup$ – kglr Jul 21 at 4:02
  • $\begingroup$ Yes, it does. Thanks. $\endgroup$ – Michael E2 Jul 21 at 4:22
5
$\begingroup$

It works for me if you add more PlotPointsand let MaxRecursionwild

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
 ]

enter image description here

enter image description here

$\endgroup$
  • $\begingroup$ Thanks. But there should be regularly many segments of complete disconnection. $\endgroup$ – Narasimham Jul 20 at 9:46
  • 1
    $\begingroup$ @Narasimham can you be more specific about the problem? I do see "regularly many segments of complete disconnect. ", as you ask. There are just very thinly sliced. See edit. $\endgroup$ – rhermans Jul 20 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.