4

I would like the surface of the cylinder to reach the blue arcs towards left (y-axis) but not passing through them.

How can I achieve that?

enter image description here

\documentclass[border=3mm]{standalone}

\usepackage{pgfplots}
    \pgfplotsset{compat=1.15}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[%
    axis lines=middle, ticks=none,
    zmin=-2, zmax=2,
    xmin=-3, xmax=3,
    ymin=-1, ymax=3,
    view/h=125, view/v=25
    ]

    \addplot3[%
    opacity = 0.02,
    fill opacity=0.5,
    mesh/interior colormap name=hot,
    surf,
    colormap/hot,
    faceted color=black,
    z buffer = sort,
    samples = 50,
    variable = \u,
    variable y = \v,
    domain = 0:360,
    y domain = -3:3,
    ]
    ({cos(u)}, {max(v,cos(v))}, {sin(u)});

    % ARCS
    \addplot3[%
    variable= \t,
    mesh,
    blue!80!,
    semithick,
    samples=30,
    opacity = 0.025,
    z buffer = sort,
    domain= 0:180,
    ] 
    ({sin(t)}, {sin(t)}, {cos(t)});

    \addplot3[%
    variable= \t,
    mesh,
    blue!80!,
    semithick,
    samples=30,
    opacity = 0.025,
    z buffer = sort,
    domain= 0:-180,
    ] 
    ({sin(t)}, {-sin(t)}, {cos(t)});

  \end{axis}
\end{tikzpicture}

\end{document} 

1 Answer 1

5

I think you were almost there. I just replaced cos(v) by abs(cos(u)). (EDIT: I also removed one \addplot3, which was redundant after replacing sin(u) by abs(sin(u)) and extending the range to 0:360 in the other.)

\documentclass[border=3mm]{standalone}

\usepackage{pgfplots}
    \pgfplotsset{compat=1.15}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[%
    axis lines=middle, ticks=none,
    zmin=-2, zmax=2,
    xmin=-3, xmax=3,
    ymin=-1, ymax=3,
    view/h=125, view/v=25
    ]

    \addplot3[%
    opacity = 0.02,
    fill opacity=0.5,
    mesh/interior colormap name=hot,
    surf,
    colormap/hot,
    faceted color=black,
    z buffer = sort,
    samples = 50,
    variable = \u,
    variable y = \v,
    domain = -180:180,
    y domain = 0:3,
    ]
    ({cos(u)}, {max(v,abs(cos(u)))}, {sin(u)});

    % ARCS
    \addplot3[%
    variable= \t,
    mesh,
    blue!80!,
    semithick,
    samples=30,
    opacity = 0.025,
    z buffer = sort,
    domain= 0:360,
    ] 
    ({sin(t)}, {abs(sin(t))}, {cos(t)});

  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

1
  • Excellent! I have to admit that I could not find out how to achieve that with LaTeX code but did not look for a mathematical solution either. The absolute value of the second parametric function is just brilliant! Thank you.
    – Cragfelt
    Dec 16, 2017 at 1:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .