如何旋转 3D tikz 图片的一部分(如图片)并且底部区域固定(不旋转)?

如何旋转 3D tikz 图片的一部分(如图片)并且底部区域固定(不旋转)?

我想使用 3D tikz 旋转图片,如下图所示。可以吗?

在此处输入图片描述

\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}

答案1

您可以使用rotate around x/y/z选项

\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}

旋转的物体


如果只想旋转部分路径,则必须分割路径。使用shift=键确定第二条弧的正确旋转:

\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


说实话,现在顶部区域的填充有点棘手,因为路径被分成了几个部分。最简单的填充方法是连接不同的路径,但我不知道如何实现这一点。实际上,这里循环空间给出了该任务的解决方案,但我不知道如何使用新的语法spath3

因此,我的解决方案有点“草率而粗暴”,因为路径没有闭合,这就是为什么角落不太好看。但是,顶部区域被填充了。

\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}

填充顶部区域

相关内容