# How to make a cylinder with bottom that shows hidden part of edge as dashed curve [duplicate]

I am learning a bit about TikZ and found a nice feature in its graphics, that I am having hard time duplicating with Graphics3D. It is making a Cylinder, where the bottom will have part of its edge, that is behind the current view, show up as dashed lines. Ofcourse the Cylinder will have to be a little transparent to see the edge (using Opacity).

Another obstacle I found, is that one can't Inset 3D object inside another 3D object in Mathematica. I hope this will become possible in future versions.

Here is the latex question that shows how this is done in TikZ. Here is screen shot of the final shape (the letter A is not needed)

This is what I tried: Make cylinder, remove its EdgeForm, make another cylinder to use for the bottom part, which is very thin, and have its edge be dashed.

But this does not really solve the problem, as I need to have the edge that is "behind" the current view be dashed.

The reason for asking, is not just for fun, but this will actually make the disk appear more real if it is possible to make the behind view edge dashed (or other color) from the front facing edge. So this can be useful feature for many other 3D objects making.

g1 = Graphics3D[{Opacity[.5], EdgeForm[], Yellow,
Cylinder[{{0, 0, 0}, {0, 0, 1}}, 1]}]


g2 = Graphics3D[{EdgeForm[Directive[Thin, Dashed, Red]], FaceForm[],
Cylinder[{{0, 0, 0}, {0, 0, .01}}, 1]}]


Now combined

   Graphics3D[{First@g1, First@g2}]


Close, but no cigar.

• Take a look at this brilliant answer of Silvia: 45435
– Kuba
Feb 8, 2015 at 20:55
• @Kuba thanks for the link. I did not know about it. But when trying it, it make static raster image. Like this g = Graphics3D[Cylinder[{{0, 0, 0}, {0, 0, 1}}, 1]]; DashedGraphics3D[g, Lighting -> "Neutral"] !Mathematica graphics which works, and is very nice. But I was thinking of an actual 3D graphics, not rasterized version, which I can rotate and move and use in animation, etc.. yet still have this feature. May be I am asking too much come to think about? Feb 8, 2015 at 21:06
• Ok, vote retracted :)
– Kuba
Feb 8, 2015 at 21:10
• This answer 20945 does something kind of similar. You might be interested in the control for rotating it. This one 28600 also has a 3D rotation control which controls the image rendered inside it. Feb 9, 2015 at 2:09
• Related: (20973) Feb 9, 2015 at 6:29

Not just what you requested but perhaps a bit closer to the tikz rendering.

g1 = Graphics3D[{Opacity[.8], EdgeForm[{Thick}], Glow[Pink], Black,
Cylinder[]}, Boxed -> False];
g2 = Graphics3D[{Opacity[.8], EdgeForm[{Thick}], Glow[Pink], Black,
Cylinder[]}];
GraphicsGrid[{{g1, g2}}]


Well, it was fairly quick for such a simple figure. David Carraher's solution is simpler, except that the envelope is not drawn.

DynamicModule[{vv = {0, 0, 1}, vp = {3.2, 2., 4.}},
Graphics3D[{{Opacity[.5], EdgeForm[], Yellow,
Cylinder[{{0, 0, 0}, {0, 0, 1}}, 1]},
{Directive[Thick, Dashed, Red],
Line[Table[{Cos[t], Sin[t], 0}, {t, 0, 2 Pi, 2 Pi/60}]],
Line[Table[{Cos[t], Sin[t], 1}, {t, 0, 2 Pi, 2 Pi/60}]]},
{Directive[Thick, Red],
Dynamic@
With[{angle = ArcTan[vp[[1]], vp[[2]]], width = ArcCos[1/Norm[vp]]},
{If[vp[[3]] > 0,
Line[Table[{Cos[t], Sin[t], 0}, {t, angle - width, angle + width, width/30}]],
Line[Table[{Cos[t], Sin[t], 0}, {t, 0, 2 Pi, 2 Pi/60}]]],
If[vp[[3]] < 0,
Line[Table[{Cos[t], Sin[t], 1}, {t, angle - width, angle + width, width/30}]],
Line[Table[{Cos[t], Sin[t], 1}, {t, 0, 2 Pi, 2 Pi/60}]]],
Line[Append[Through[{Cos, Sin}[angle - width]], #] & /@ {0, 1}],
Line[Append[Through[{Cos, Sin}[angle + width]], #] & /@ {0, 1}]}
]
}
}, ViewPoint -> Dynamic[vp], ViewVertical -> Dynamic[vv]]
]


The dashed lines change as the object is rotated in the front end.

• Oh man, that ViewPoint -> Dynamic[vp] trick is neat. I know I'm going to be using that in the future.
– user484
Feb 9, 2015 at 3:43