使用 tikz 绘制 3D 插图

使用 tikz 绘制 3D 插图

我正在尝试以 3D 形式绘制以下同心圆柱设计:在此处输入图片描述

但是在给下图的两侧着色以及在中心形成圆形图案方面遇到了困难。

我正在尝试将图纸并排放置,并使 3D 图纸的表面看起来与 2D 图纸相同!如能提供任何帮助,我将不胜感激!

 \documentclass{article}
 \usepackage{pgfplots}
 \usepackage{caption}
 \usepackage{tikz}
 \usetikzlibrary{arrows,backgrounds,patterns,shapes.geometric,arrows.meta}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}
\filldraw[even odd rule,inner color=red,outer color=red, opacity = 0.4] 
(0,0) circle (3cm)
(0,0) circle (3.1cm);
\filldraw[even odd rule,inner color=white,outer color=blue, opacity = 0.1] 
(0,0) circle (1.0cm)
(0,0) circle (3cm);
\draw[thick, fill = gray] (0,0) circle (0.1cm);
\draw[thick] (0,0) circle (3cm);
\draw[thick] (0,0) circle (3.1cm);
\draw[->, rotate around={45:(0,0)}] (0,0) -- (3,0)  node [near end,] {$r_0$};

\draw[-latex] (0,-1.9) arc (274:180:1.5cm) node[thick,midway,right] {$\Omega$};
\draw[thick, opacity = 1] (0,0) circle (1.0cm);

\draw[thick, fill = white]
\foreach \i in {1,2,...,14} {%
    [rotate=(\i-1)*36] 
    (0:1.0)  arc (0:18:1.0) {[rounded corners=8pt] -- ++(18: 0.26)  arc (18:36:1.9) } -- ++(36: -0.26) 
};
\draw[->, rotate around={-40:(0,0)}] (0,0) -- (1.2,0)  node [midway,fill = white] {$r_i$};
\end{tikzpicture}
\end{figure}

\begin{tikzpicture}

 \draw[thick] (-4,4) -- (-4,3) arc (180:360:4cm and 1cm) -- (4,4) ++ (-4,0) 
 circle (4cm and 1cm);
 \draw[thick]  -- (-1.5,3) arc (180:360:1.5cm and 0.25cm) -- (1.5,4) ++ 
 (-1.5,0) circle (1.5cm and 0.25cm);
 \draw[thick] (4,4) ++ (-4,0) circle (3.9cm and 0.9 cm);
 \filldraw[even odd rule,inner color=white,outer color=blue, opacity = 0.2] 
 (4,4) ++ (-4,0) circle (4cm and 1 cm);
 \filldraw[even odd rule,inner color=white,outer color=blue, opacity = 0.2] 
  (4,4) ++ (-4,-1) circle (4cm and 1 cm);
  \filldraw[even odd rule,inner color=white,outer color=white, opacity = 1]
  (1.5,4) ++ (-1.5,0) circle (1.5cm and 0.25cm);

  \filldraw[even odd rule,inner color=red,outer color=red, opacity = 0.2] 
  (4,4) ++ (-4,0) circle (4cm and 1 cm)
  (4,4) ++ (-4,0) circle (3.9cm and 0.9 cm);
  \draw[thick] (1.5,4) ++ (-1.5,0) circle (0.25cm and 0.05cm);
  \fill[color = gray] 
  (1.5,4) ++ (-1.5,0) circle (0.25cm and 0.05cm);
  %\draw[thick,-latex] (5,0,0) -- (9,0,0) node[anchor=north east]{$y$};
  %\draw[thick,-latex] (5,0,0) -- (5,5,0) node[anchor=north west]{$z$};
  %\draw[thick,-latex] (5,0,0) -- (5,0,5) node[anchor=south east]{$x$};

   \end{tikzpicture}  
    \end{document}

答案1

使用tikz-3dplot

这基本上和我在这里做的事情是一样的: XYZ 坐标系绘图

有些事情必须改变,因为rotate似乎不起作用tikz-3dplot(我不明白为什么......)

我对圆形齿轮做了一点小改动,通过设置调整后的角度来伪造连续性。

输出

在此处输入图片描述

代码

\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
%% viewing angles %%
\def\angThe{70}   %%
\def\angPhi{0}    %%
%%%%%%%%%%%%%%%%%%%%

\tdplotsetmaincoords{\angThe}{\angPhi}
\begin{tikzpicture}[tdplot_main_coords, scale=1.7]
  \def\topDisk
  {
    \filldraw
    [
      even odd rule,
      inner color=red,
      outer color=red,
      fill opacity = 0.4,
      draw=black, thick,
    ]
    (0,0) circle (3)
    (0,0) circle (3.1);

    \filldraw
    [
      even odd rule,
      inner color=white,
      outer color=blue,
      fill opacity = 0.1,
      draw=black, thick,
    ]
    (0,0) circle (1.0)
    (0,0) circle (3);

    \foreach \i in {1,2,...,14} 
    {
      \pgfmathsetmacro{\a}{(\i-1)*36}
      \draw[thick, fill = white] (\a:1) circle (.26) ;
    }
    \fill [white] (0,0) circle (1) ;
    \foreach \i in {1,2,...,14} 
    {
      \pgfmathsetmacro{\a}{(\i-1)*36}
      \draw[thick] (\a:1) arc (\a:\a+21:1);
    }

    \filldraw[thick, fill = gray] (0,0) circle (0.1);

    \draw[-latex] (0,-1.9) arc (274:180:1.5) node[thick,midway,below] {$\Omega$};
    \draw[->, ] (0,0) -- (45:3)  node [below=5pt,near end,] {$r_0$};
    \draw[->, ] (0,0) -- (-40:1.2)  node [midway,fill = white] {$r_i$};
  }

  \topDisk

  \def\r{3.1}
  \def\z{-1}
  \pgfmathsetmacro{\angPhiOpp}{\angPhi-180}

  \draw [fill=pink] (\angPhi:\r) arc (\angPhi:\angPhiOpp:\r) 
  {[shift={(0,0,\z)}]
                    -- (\angPhiOpp:\r) arc (\angPhiOpp:\angPhi:\r) 
  } -- cycle;

  \begin{scope}[x=1cm,y=1cm,yshift=5cm]
    \topDisk
  \end{scope}
\end{tikzpicture}

\end{document}

审美的

在此处输入图片描述

\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
%% viewing angles %%
\def\angThe{70}   %%
\def\angPhi{0}    %%
%%%%%%%%%%%%%%%%%%%%

\tdplotsetmaincoords{\angThe}{\angPhi}
\begin{tikzpicture}[tdplot_main_coords, scale=1.7]
  \def\topDisk
  {
    \filldraw
    [
      even odd rule,
      fill=purple!79!blue,
      fill opacity = 0.6,
      draw=black, thick,
    ]
    (0,0) circle (3)
    (0,0) circle (3.1);

    \filldraw
    [
      even odd rule,
      inner color=white,
      outer color=teal,
      fill opacity = 0.2,
      draw=black, thick,
    ]
    (0,0) circle (1.0)
    (0,0) circle (3);

    \foreach \i in {1,2,...,14} 
    {
      \pgfmathsetmacro{\a}{(\i-1)*36}
      \draw[thick, fill = white] (\a:1) circle (.26) ;
    }
    \fill [white] (0,0) circle (1) ;
    \foreach \i in {1,2,...,14} 
    {
      \pgfmathsetmacro{\a}{(\i-1)*36}
      \draw[thick] (\a:1) arc (\a:\a+21:1);
    }

    \filldraw[thick, fill = gray] (0,0) circle (0.1);

  }

  \topDisk

  \def\r{3.1}
  \def\z{-1}
  \pgfmathsetmacro{\angPhiOpp}{\angPhi-180}
  \pgfmathsetmacro{\angPhiMid}{\angPhi-90}

  \def\around[#1]<#2:#3>
  {
    \path
    [
      #1
    ]
    (#2:\r) arc (#2:#3:\r) 
    {[shift={(0,0,\z)}]
                      -- (#3:\r) arc (#3:#2:\r) 
    } -- cycle;
  }
  \begin{scope}[transparency group,opacity=.35]
    \around
    [
      fill,
      left color=blue,
      right color=red,
    ]<\angPhi:\angPhiMid>

    \around
    [
      fill,
      left color=red,
      right color=blue,
    ]<\angPhiMid+1:\angPhiOpp>
  \end{scope}
  \around[draw=thick]<\angPhi:\angPhiOpp>


  \begin{scope}[x=1cm,y=1cm,yshift=5cm]
    \topDisk
     \draw[-latex] (0,-1.9) arc (274:180:1.5) node[thick,midway,below] {$\Omega$};
     \draw[->, ] (0,0) -- (45:3)  node [below=5pt,near end,] {$r_0$};
     \draw[->, ] (0,0) -- (-40:1.2)  node [midway,fill = white] {$r_i$};
  \end{scope}
\end{tikzpicture}

\end{document}

或者像这样?

在此处输入图片描述

\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
%% viewing angles %%
\def\angThe{70}   %%
\def\angPhi{0}    %%
%%%%%%%%%%%%%%%%%%%%

\tdplotsetmaincoords{\angThe}{\angPhi}
\begin{tikzpicture}[tdplot_main_coords, scale=1.7]
  \definecolor{blueish}{HTML}{2AA198}
  \definecolor{backg}{HTML}{EC93D3}

  \def\topDisk
  {
    \filldraw
    [
      even odd rule,
      inner color=red,
      outer color=red,
      fill opacity = 0.4,
      draw=black, thick,
    ]
    (0,0) circle (3)
    (0,0) circle (3.1);

    \filldraw
    [
      even odd rule,
      inner color=white,
      outer color=blue,
      fill opacity = 0.1,
      draw=black, thick,
    ]
    (0,0) circle (1.0)
    (0,0) circle (3);

    \foreach \i in {1,2,...,14} 
    {
      \pgfmathsetmacro{\a}{(\i-1)*36}
      \draw[thick, fill = white] (\a:1) circle (.26) ;
    }
    \fill [white] (0,0) circle (1) ;
    \foreach \i in {1,2,...,14} 
    {
      \pgfmathsetmacro{\a}{(\i-1)*36}
      \draw[thick] (\a:1) arc (\a:\a+21:1);
    }

    \filldraw[thick, fill = gray] (0,0) circle (0.1);
  }

  \topDisk

  \def\r{3.1}
  \def\z{-1}
  \pgfmathsetmacro{\angPhiOpp}{\angPhi-180}

  \def\around[#1]<#2:#3>
  {
    \path[#1] (#2:\r) arc (#2:#3:\r) 
    {[shift={(0,0,\z)}]
                      -- (#3:\r) arc (#3:#2:\r) 
    } -- cycle;
  }
  \begin{scope}[transparency group,opacity=.65]
    \def\thet{20}
    \pgfmathsetmacro{\by}{\angPhiOpp+\thet}
    \pgfmathsetmacro{\to}{\angPhi-\thet}
    \foreach \k [evaluate=\k as \kk using \k+.5*\thet, evaluate=\k as \kkk using \k+\thet] in {\angPhiOpp,\by,...,\to}
    {
      \around[fill=blue]<\k:\kk>
      \around[fill=red]<\kk:\kkk>
    }
  \end{scope}
  \around[draw,thick]<\angPhi:\angPhiOpp>

\end{tikzpicture}

\end{document}

作为堆栈

在此处输入图片描述

\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
%% viewing angles %%
\def\angThe{70}   %%
\def\angPhi{0}    %%
%%%%%%%%%%%%%%%%%%%%

\tdplotsetmaincoords{\angThe}{\angPhi}
\begin{tikzpicture}[tdplot_main_coords, scale=1.7]
  \definecolor{blueish}{HTML}{2AA198}
  \definecolor{backg}{HTML}{EC93D3}

  \def\topDisk
  {
    \filldraw
    [
      even odd rule,
      inner color=red,
      outer color=red,
      fill opacity = 0.4,
      draw=black, thick,
    ]
    (0,0) circle (3)
    (0,0) circle (3.1);

    \filldraw
    [
      even odd rule,
      inner color=white,
      outer color=blue,
      fill opacity = 0.1,
      draw=black, thick,
    ]
    (0,0) circle (1.0)
    (0,0) circle (3);

    \foreach \i in {1,2,...,14} 
    {
      \pgfmathsetmacro{\a}{(\i-1)*36}
      \draw[thick, fill = white] (\a:1) circle (.26) ;
    }
    \fill [white] (0,0) circle (1) ;
    \foreach \i in {1,2,...,14} 
    {
      \pgfmathsetmacro{\a}{(\i-1)*36}
      \draw[thick] (\a:1) arc (\a:\a+21:1);
    }

    \filldraw[thick, fill = gray] (0,0) circle (0.1);
  }

  \def\r{3.1}
  \def\h{-.3}
  \pgfmathsetmacro{\angPhiOpp}{\angPhi-180}

  \def\around[#1]|#2,#3|
  {
    \begin{scope}[shift={(0,0,\h*(#2))}]
      \path [#1] (\angPhi:\r) arc (\angPhi:\angPhiOpp:\r) 
      {[shift={(0,0,\h*(#3))}]
                        -- (\angPhiOpp:\r) arc (\angPhiOpp:\angPhi:\r) 
      } -- cycle;
    \end{scope}
  }
    \def\N{5}
  \begin{scope}[transparency group,opacity=.65]
    \foreach \k  in {0,...,\N}
    {
      \around[fill=blue]|\k,.5|
      \around[fill=red]|\k+.5,.5|
    }
  \end{scope}
  \around[draw,thick]|0,\N+1|

  \topDisk

\end{tikzpicture}
\end{document}

相关内容