4

I want to rotate picture using 3D tikz like below picture. Is it possible?

enter image description here

\documentclass{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}‎‎
\begin{tikzpicture}
\draw[->] (0,0,0)--++(5,0,0) node[right]{$x$};
\draw[->] (0,0,0)--++(0,5,0) node[above]{$y$};
\draw[->] (0,0,0)--++(0,0,10) node[below left]{$z$};
\draw[ultra thick] (4,0,0) arc[start angle=0, end angle=90, radius=4] -- 
    ++(0,0,8.5) arc[start angle=90, end angle=0, radius=4]--cycle;‎‎
\draw[ultra thick] (0,0,8.5) --++(4,0,0) --cycle;‎
\draw[ultra thick] (0,0,8.5) --++(0,4,0) --cycle;
\end{tikzpicture}
\end{document}
sayros
  • 2,629

1 Answers1

5

You can use the rotate around x/y/z options

\documentclass{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}‎‎
\begin{tikzpicture}
\draw[->] (0,0,0)--++(5,0,0) node[right]{$x$};
\draw[->] (0,0,0)--++(0,5,0) node[above]{$y$};
\draw[->] (0,0,0)--++(0,0,10) node[below left]{$z$};
\begin{scope}[rotate around x=20]
\draw[ultra thick] (4,0,0) arc[start angle=0, end angle=90, radius=4] -- 
++(0,0,8.5) arc[start angle=90, end angle=0, radius=4]--cycle;‎‎
\draw[ultra thick] (0,0,8.5) --++(4,0,0) --cycle;‎
\draw[ultra thick] (0,0,8.5) --++(0,4,0) --cycle;
\draw[ultra thick] (0,0,0)--++(0,4,0)node(n1){};
\end{scope}
\draw[dashed,very thick] (0,4,0)--(n1);
\end{tikzpicture}
\end{document}

rotated object


You have to split the paths, if you only want to rotate parts of it. Use the shift= key to establish correct rotation of the second arc:

\documentclass{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}‎‎
\begin{tikzpicture}
    \draw[->] (0,0,0)--++(5,0,0) node[right]{$x$};
    \draw[->] (0,0,0)--++(0,5,0) node[above]{$y$};
    \draw[->] (0,0,0)--++(0,0,10) node[below left]{$z$};

    \begin{scope}[rotate around x=20]‎‎
        \draw[ultra thick] (4,0,0) arc[start angle=0, end angle=90, radius=4]node[inner sep=0](n1){};
    \end{scope}
    \begin{scope}[shift={(0,0,8.5)},rotate around x=20]
        \draw[ultra thick] (4,0,0) arc[start angle=0, end angle=90, radius=4]node[inner sep=0](n2){};
    \end{scope}

    \draw[ultra thick] (n1.center)--(n2.center)--(0,0,8.5)--(4,0,8.5)--(4,0,0);
    \draw[dashed, very thick](0,4,0)--(n1.center);
\end{tikzpicture}
\end{document}

2


The filling of the top area is a bit tricky now, to be honest, because the path is split into several parts. The easiest way of filling would be to concatenate the different paths but I don't know, how to achieve this. Actually, here, Loop Space gives a solution to that task, but I don't know how to use the new syntax of spath3.

So my solution is a bit more "quick and dirty", as paths are not closed, which is why the corners are not as nice. However, the top area is filled.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[line cap=round]
    %coordinate system
    \draw[->] (0,0,0)--++(5,0,0) node[right]{$x$};
    \draw[->] (0,0,0)--++(0,5,0) node[above]{$y$};
    \draw[->] (0,0,0)--++(0,0,10) node[below left]{$z$};

    % draw and save arcs    
    \begin{scope}[rotate around x=20]
        \draw[ultra thick,save path=\arcone] (4,0,0) arc[start angle=0, end angle=90, radius=4]node[inner sep=0](n1){};
    \end{scope}
    \begin{scope}[shift={(0,0,8.5)},rotate around x=20]
        \draw[ultra thick,save path=\arctwo] (4,0,0) arc[start angle=0, end angle=90, radius=4]node[inner sep=0](n2){};
    \end{scope}
    % draw and save connecting lines
    \draw[save path=\lineleft,ultra thick](n1.center)--(n2.center);
    \draw[save path=\lineright,ultra thick](4,0,0)--(4,0,8.5);
    % draw additional lines    
    \draw[ultra thick] (n2.center)--(0,0,8.5)--(4,0,8.5);
    \draw[dashed, very thick](0,4,0)--(n1.center);

    % fill the top area:
    \makeatletter
        \begin{scope}[even odd rule]% to achieve "inverse" clipping
                \pgfsyssoftpath@setcurrentpath{\arctwo}
                \clip--(0,0,8.5)--(4,0,8.5) (-10,-10)rectangle(10,10); % any bigger rectangle
                \pgfsyssoftpath@setcurrentpath{\arcone}
                \fill[red, opacity=0.5]--(n2.center)--(4,0,8.5);
        \end{scope} 
    \makeatother
\end{tikzpicture}
\end{document}

filled top area

Ktree
  • 688