1

I want to draw a circle at the end of a semi-cylinder. However I was not able to change the orientation (plane) for this circle. I found this post that suggests to use [x={(0,0, 1)}] but it does not seem to work inside of pgfplots axis environment. I tried to refer to the correct coordinate system axis cs: for the transformation but that also did not help.

MWE:

\documentclass{standalone}

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

\newcommand{\ycenter}{1} \newcommand{\zcenter}{1} \newcommand{\myradius}{1}

\newcommand{\myxmax}{5}

\begin{document} \begin{tikzpicture} \begin{axis}[xmax=\myxmax] \addplot3[ domain y = \ycenter-\myradius:\ycenter+\myradius, surf, ] {-sqrt(\myradius^2 - (y-\ycenter)^2) + \zcenter};

    % center of the circle at the right end of semicylinder
    \node at (\myxmax, \ycenter, \zcenter) {O};

    % this circle is not oriented correctly
    \draw[red] (\myxmax, \ycenter, \zcenter) circle (1);
    % sadly this does not help
    \draw[green] (\myxmax, \ycenter, \zcenter) [x={(0,0,1)}] circle (1);
    % neither does this
    \draw[black] (1, 0, 0) [x={(axis cs: 0,0,1)}] circle (1);


\end{axis}
% this does not refer to the correct coordinate system
\draw[blue] (\myxmax, \ycenter, \zcenter) circle (1);
\draw[blue] (\myxmax, \ycenter, \zcenter) [x={(0,0,1)}] circle (1);

\end{tikzpicture} \end{document}

yields:

enter image description here

Ty for any help,

Franz

Stefan Pinnow
  • 29,535
Franz
  • 175

1 Answers1

2

Here is one simple way to plot the circle(makes many small curves) and an other more complicated way to draw a real circle

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{3d, calc}
\newcommand{\ycenter}{1}
\newcommand{\zcenter}{1}
\newcommand{\myradius}{1}
\newcommand{\myxmax}{5}

\begin{document} \begin{tikzpicture} \begin{axis}[xmax=\myxmax] \addplot3[domain=-\myxmax:\myxmax, domain y=\ycenter-\myradius:\ycenter+\myradius, surf, ] {-sqrt(\myradius^2 - (y-\ycenter)^2) + \zcenter}; \addplot3[ultra thick, domain=0:360, variable=t, smooth] (\myxmax,{\ycenter+\myradiuscos(t)},{\zcenter+\myradiussin(t)}); \begin{scope}[canvas is yz plane at x=\myxmax] \draw[red, thick] let \p1=(\myradius,0), \n1={veclen(\x1,\y1)} in (\ycenter,\zcenter) circle[radius=\n1]; \end{scope} \end{axis} \end{tikzpicture} \end{document}

3D surface with a circle at the end

  • Very nice ty. Totally unrelated but I didn't find an answer in the help center. Is there a standard way to include pdf's from MWEs into questions or answers? Is there a build in tex compiler on this site? – Franz Oct 07 '22 at 21:07
  • 1
    There is no standard way and also not any way to include a pdf. There is no tex compiler on this site. The easiest way is to compile locally or online(e.g. https://www.overleaf.com) and take a screenshot to include. – hpekristiansen Oct 07 '22 at 21:13
  • OK ty. That what I also did. – Franz Oct 09 '22 at 10:31
  • Can you quickly comment on why my approaches did not work? – Franz Oct 09 '22 at 10:32
  • I have trouble to see how you could believe that it would work. -wrong center, wrong coordinate system. axis cs: does nothing, as it is default coordinate system. The red circle is correct, but oriented in the xy plane. I will happily explain further - let me know what/which you do not understand. – hpekristiansen Oct 09 '22 at 14:20