9

I have a diagram I'd like to reproduce in TikZ:

enter image description here

Picture a can (cylinder of radius r and height L) that has liquid in it. In each diagram, the can is tilted so that the surface of the liquid just touches where the top meets the sides. In the first diagram, the liquid covers the entire bottom, while in the second, only half.

Edit: Yes, I could do this myself given the time, but I'd like to see how others would handle the 3D aspect. Is there a better way to draw a projected circle than to draw an ellipse? [There you go @Andrew.]

The optimal code would use styles and named coordinates so that one could alter the diagram by changing only a few parameters.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195

2 Answers2

22

Do you want something a bit like this?

cylinders with liquid

If so, I'm afraid I don't know how to do that.


(Added in edit after question was closed. The above was produced using TikZ, contrary to my comment below. However, the code is messy and not elegant - it was a quick hack to make the joke. I've sent it privately to Matthew but I am not going to post it here. There are some interesting aspects in doing a drawing such as this one, so if anyone is interested in producing diagrams like this one then I encourage them to think carefully about which bits they could do and which would be hard, and then ask a focussed question specifically about the hard bits.)

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
  • 4
    I guess Matthew wants it in grey and it should have a look as photo copied. (Or it's just my dirty display.) – topskip Oct 12 '11 at 15:32
  • 3
    No +15 for you until I see your code. :-) – Matthew Leingang Oct 12 '11 at 15:46
  • 1
    Wow, that's awesome Ansdrew. Can't recall ever laughing so much from something on this site. Now I know how to quickly post solutions here and build up a reputation. :-) – Peter Grill Oct 12 '11 at 16:34
  • 3
    Code? What code? I don't have any code for that. I just took your diagram, added some colour using GIMP, and reposted it. Now, if you'd asked a sensible question like "How do you get proper 3D-looking circles in TikZ?" then maybe I could have provided some code to answer that. – Andrew Stacey Oct 12 '11 at 18:32
  • 2
    I'm also waiting for the codes – Regis Santos Oct 12 '11 at 19:45
3

This example could be a good start for you, but it uses pst-solides3d (I found here...) and maybe you may get something similar with tikz.

\documentclass{minimal}
\usepackage{pst-solides3d}
\pagestyle{empty}
\SpecialCoor
\begin{document}
\begin{pspicture}(-5,-5)(7,9)
  \psset{viewpoint=20 10 10,Decran=40,lightsrc=20 10 5,solidmemory}
  \defFunction{cone}(u,v){u v Cos mul}{u v Sin mul}{u}
  \psSolid[object=surfaceparametree,base=-2 2 0 2 pi mul,
     inhue=0.8 0.2,hue=0.8 0.2,
     function=cone,linewidth=0.5\pslinewidth,
     ngrid=25 40,fillcolor=cyan!50,
     intersectionplan={[1 0 0 -1]},
     intersectioncolor=(bleu),
     intersectionlinewidth=3,
     intersectiontype=0,
     name=XYZ,action=none]%
  \psSolid[object=plan,definition=equation,
    args={[1 0 0 0]},
%    args={[1 0 0 -1]},
    fillcolor=blue!50,
    base=-2 2 -2.5 2.5,ngrid=30 30,action=none,name=Plane]
  \psSolid[object=fusion,base=XYZ Plane_s]
  \gridIIID[Zmin=-2,Zmax=2](-2,2)(-2,2)
\end{pspicture}
\end{document} 

enter image description here