通过 Tikz 绘制实体物体

通过 Tikz 绘制实体物体

我是绘图新手tikz。我只能用它画一些简单的图表,但现在我想为我的项目画两张如下图。我不知道如何使用它tikz来画这么复杂的图形。 在此处输入图片描述 在此处输入图片描述

这是我迄今为止尝试绘制的四面体

\begin{tikzpicture}[line join = round, line cap = round]
\pgfmathsetmacro{\factor}{1/sqrt(2)};
\coordinate [label=right:A] (A) at (2,0,0*\factor);
\coordinate [label=left:B] (B) at (0,0,0*\factor);
\coordinate [label=above:C] (C) at (0,2,0*\factor);
\coordinate [label=below:D] (D) at (0,0,2*\factor);

\draw[->] (0,0) -- (3,0,0) node[right] {$x$};
\draw[->] (0,0) -- (0,3,0) node[above] {$y$};
\draw[->] (0,0) -- (0,0,3) node[below left] {$z$};
\foreach \i in {A,B,C,D}
    \draw[dashed] (0,0)--(\i);
\draw[-, fill=red!30, opacity=.5] (A)--(D)--(B)--cycle;
\draw[-, fill=green!30, opacity=.5] (A) --(D)--(C)--cycle;
\draw[-, fill=purple!30, opacity=.5] (B)--(D)--(C)--cycle;
\end{tikzpicture}

谁能给我一些想法,或者更好的LaTeX代码示例。

答案1

如果您需要进一步的帮助,请针对您遇到的具体问题提出新问题。这里的问题太多了,无法用一个问答来回答。作为起点,我将您现有的图表转换为基于 的形式tikz-3dplot,它会自动进行一些计算。这简化了代码,使添加下面序列中的第二个图表变得更加容易。

注意 TiZ 不适合 3D,因为它对 3D 一无所知。在简单的情况下,你可以成功伪造东西,但对于更复杂的图表,使用了解 3D 的软件会容易得多。

具体来说,要以 3D 形式绘制,您必须进行计算。tikz-3dplot可以自动执行其中的一些操作,但您仍然需要考虑从 3D 到 2D 的转换。 具体来说,如果较远的物体与较近的物体有重叠,则需要先绘制它们。 在这种情况下,如果您想获得合理的结果,则需要按适当的顺序绘制和填充实体的侧面。

第二序列的两个阶段

\documentclass[border=10pt]{standalone}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{calc,arrows.meta}
\begin{document}
\tdplotsetmaincoords{50}{110}
\begin{tikzpicture}[tdplot_main_coords, >=Latex]
  \draw[->] (0,0,0) -- (3,0,0) node[below left] {$x$};
  \draw[->] (0,0,0) -- (0,3,0) node[right] {$y$};
  \draw[->] (0,0,0) -- (0,0,3) node[above] {$z$};
  \begin{scope}[fill opacity=.5, draw opacity=.5, text opacity=1]
    \draw [fill=blue!50!cyan] (2,0,0) coordinate [label=left:D] (D) -- (0,0,2) coordinate [label=above right:C] (C) -- (0,0,0) coordinate [label={[xshift=-10pt]above left:B}] (B) -- cycle;
    \draw [fill=magenta] (B) -- (C) -- (0,2,0) coordinate [label=above right:A] (A) -- cycle;
    \draw [fill=yellow] (D) -- (C) -- (A) -- cycle;
  \end{scope}
  \begin{scope}[xshift=45mm]
    \draw[->] (0,0,0) -- (3,0,0) node[below left] {$x$};
    \draw[->] (0,0,0) -- (0,3,0) node[right] {$y$};
    \draw[->] (0,0,0) -- (0,0,3) node[above] {$z$};
    \begin{scope}[fill opacity=.5, draw opacity=.5, text opacity=1]
      \draw [fill=blue!50!cyan] (0,0,0) coordinate [label={[anchor=north west,xshift=-5pt]below:$E_0$}] (E0) -- (0,0,2) coordinate [label=above right:$E_0'$] (E0') -- (0,2,2) coordinate [label={right:$E_2'$}] (E2') -- (0,2,0) coordinate [label=above right:$E_2$] (E2) -- cycle;
      \draw [fill=purple] (E0) -- (E0') -- (2,0,2) coordinate [label=left:$E_1'$] (E1') -- (2,0,0) coordinate [label=left:$E_1$] (E1) -- cycle;
      \draw [fill=green!50!cyan] (E0) -- (E2) -- (E1) -- cycle;
      \draw [densely dashed] (E1') -- (E0) -- (E2');
      \draw [fill=yellow] (E1) -- (E2) -- (E2') -- (E1') -- cycle;
      \draw [fill=magenta] (E1') -- (E2') -- (E0') -- cycle;
      \draw [densely dashed] (E1) -- (E2');
    \end{scope}
  \end{scope}
  \draw [->, shorten >=5mm, shorten <=5mm] ($(C)!.5!(A)$) [bend left] to node [midway, above] {$G_{i,2}$} ($(E1')!.5!(E0')$) ;
\end{tikzpicture}    
\end{document}

tikz-3dplot曲线比较棘手,但在手册中有所介绍,所以我建议从那里合适的例子开始。

答案2

对于这个简单的绘图,您实际上不需要 3D 图形;它可以在 2D 中模仿。

在此处输入图片描述

\documentclass[border=2mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}

\newcommand\blobA[3][]%
  {\draw (#3) coordinate (#2-1)
     to [out=-90,in=-180] ++(0.5,-0.3) coordinate (#2-2)
     to [out=0,in=-180] ++(1.0,0.1) coordinate (#2-3)
     to [out=0,in=-180] ++(0.3,-0.1) coordinate (#2-4)
     to [out=0,in=-90] ++(0.2,0.2) coordinate (#2-5);
   \draw[#1] (#2-5)
     to [out=90,in=0] ++(-1,0.5)  coordinate (#2-6)
     to [out=180,in=90] (#2-1);
   \node[shape=ellipse,minimum width=3cm,minimum height=1.3cm,outer sep=2pt] 
     (#2) at ($0.5*(#2-1)+0.5*(#2-5)+(0,0.05)$) {};  
  }
\newcommand\blobB[3][]%
  {\draw (#3) coordinate (#2-1)
     to [out=-90,in=135] ++(0.2,-0.4)
     to [out=-45,in=-135] ++(0.5,0.1)
     to [out=45,in=-90] ++(0.4,1.4)
     to [out=90,in=-45] ++(-0.2,0.4)
     to [out=135,in=45] ++(-1,0) coordinate(#2-2)
     to [out=-135,in=90] ++(0.2,-0.9)
     to [out=-90,in=90] (#2-1);
   \node[shape=ellipse,minimum width=1.8cm,minimum height=3.3cm,outer sep=2pt] 
     (#2) at ($(#2-1)+(0.5,0.65)$) {};  
  }
\begin{document}
\begin{tikzpicture}[>=stealth,scale=1.5]
\small
  \blobA{a}{0,0}
  \blobA[dashed]{b}{2.8,0}
  \blobA{c}{2.8,0.9}
  \blobB{d}{5.6,0}
  \draw (b-1) -- (c-1) (b-5) -- (c-5);
  \draw[->] (a) --node[above]{$\iota_0$} (b); 
  \draw[->,shorten >=1pt] (a) --node[above]{$\iota_1$} (c-1);
  \node at (a) {$X$};
  \node at (c) {$X\times I$};
  \node at (d) {$Y$};
  \draw[->,shorten >=2pt,shorten <=2pt] (a) to[bend left] node[above]{$f_1$} (d-2);
  \draw[->,shorten >=2pt,shorten <=2pt] (a) to[bend right] node[below]{$f_0$} (d-1);
  \draw[->,shorten <=2pt] (c-5|-d) --node[above]{$H$} (d);
\end{tikzpicture}
\end{document}

相关内容