2
$\begingroup$

While trying to improve this answer of mine, I found it difficult to get a smoother edge. Any ideas?

turns = r = 10; 
ParametricPlot3D[
  Piecewise[{{{1, x, 0},  x <= 0}, 
             {{Cos[2 Pi turns x/r], x, Sin[2 Pi turns x/r]}, 0 < x <= r}, 
             {{1, x, 0}, x > r}}], {x, -.5, r + .5}, 
  PlotStyle -> {Gray, Specularity[Gray, 10]},
  Lighting -> "Neutral",
  PlotRange -> {{-10, 10}, {-1, 15}, {-5, 5}},
  Axes -> None, Boxed -> False, ViewPoint -> {10000, 1, 5}] /. 
 Line[pts_, rest___] :> Tube[pts, 0.2, rest]

Mathematica graphics

$\endgroup$
  • $\begingroup$ did you turn on antialiasing? it looks smooth on my computer $\endgroup$ – halmir Mar 30 '15 at 14:28
  • $\begingroup$ @halmir Yup. However, perhaps it isn't working for some reason. If somebody else confirms your comment I'll look deeper into it. Thanks! $\endgroup$ – Dr. belisarius Mar 30 '15 at 14:30
  • 1
    $\begingroup$ In my MMA version 8 on Mac, it looks exactly like what you show in the question. But in version 10, it looks like someone left it in the bathtub too long: all wrinkly... so in other words, on version 10 (Mac) I don't think I can even begin to help in any way because the problem is deeper than antialiasing. $\endgroup$ – Jens Mar 30 '15 at 17:05
  • 1
    $\begingroup$ To avoid the atrocious look I see on version 10 Mac, I would get rid of the replacement Line -> Tube and simply add Tube[0.2] to the PlotStyle options instead, combined with Exclusions -> None. $\endgroup$ – Jens Mar 30 '15 at 17:18
  • $\begingroup$ @Jens Thanks a lot. I'm running v9 on Win32. The v10 wrinkled image is outrageous :) $\endgroup$ – Dr. belisarius Mar 30 '15 at 17:25
3
$\begingroup$

Playing with many options, I find that to remove the jagged edges from the tube, the best solution is to Rasterize with high ImageResolution (which is probably not what you want). Using Antialiasing alone did not do as well a job, but it was still better than the image shown. Here is what I get in windows 7, V 10.02

turns = r = 10;
Rasterize[Style[
  Graphics3D[First@ParametricPlot3D[
      Piecewise[{{{1, x, 0}, x <= 0}, {{Cos[2 Pi turns x/r], x, 
      Sin[2 Pi turns x/r]}, 0 < x <= r}, {{1, x, 0}, x > r}}],
      {x, -.5, r + .5},
      PlotStyle -> {Gray, Specularity[Gray, 10]},
      Lighting -> "Neutral",
      PlotRange -> {{-10, 10}, {-1, 15}, {-5, 5}},
      Axes -> None, PlotPoints -> 1000, ImageSize -> 600,
      Boxed -> False, ViewPoint -> {10000, 1, 5}
      ] /. Line[pts_, rest___] :> Tube[pts, .2, rest], Boxed -> False], 
      Antialiasing -> True], ImageResolution -> 240]

Mathematica graphics

Using Antialiasing -> True alone:

turns = r = 10;
Style[
 Graphics3D[First@ParametricPlot3D[
     Piecewise[{{{1, x, 0}, x <= 0}, {{Cos[2 Pi turns x/r], x, 
     Sin[2 Pi turns x/r]}, 0 < x <= r}, {{1, x, 0}, x > r}}],
     {x, -.5, r + .5},
     PlotStyle -> {Gray, Specularity[Gray, 10]},
     Lighting -> "Neutral",
     PlotRange -> {{-10, 10}, {-1, 15}, {-5, 5}},
     Axes -> None, PlotPoints -> 1000, ImageSize -> 500,
     Boxed -> False, ViewPoint -> {10000, 1, 5}
     ] /. Line[pts_, rest___] :> Tube[pts, .2, rest], 
     Boxed -> False], Antialiasing -> True]

Mathematica graphics

Changing Mesh, PlotPoints and such options had no effect on the jagged problem.

$\endgroup$
  • $\begingroup$ You're right about Rasterize[]. I would rather prefer not to use it :). The second try is nearer (in fact I tried it before posting) but for some reason it displays far worse on my front end (another Mma version, windows version, whatever). Thanks a lot! $\endgroup$ – Dr. belisarius Mar 30 '15 at 15:22

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.