在 tikz 中制作 3D 彩色金字塔

在 tikz 中制作 3D 彩色金字塔

我正在尝试在 tikz 中重新创建以下图像

在此处输入图片描述

抱歉没有包含 MWE,但我在开始绘制这个时遇到了问题。我尝试简单地写入坐标,但结果却错了。(中间的点应该有坐标 (2,3,0))

有人有什么提示或建议吗?我的主要问题是设置它,也许是颜色这是一个非常糟糕的 MWE... 之前没有包括它,因为它太糟糕了

\documentclass[10pt,a4paper]{minimal}
\usepackage{tikz}
\begin{document}
\center
\begin{tikzpicture}
\draw[thick,-stealth] (0,0,0)--(0,0,6); 
\draw[thick,-stealth] (0,0,0)--(0,6,0);
\draw[-stealth] (0,0,0)--(6,0,0);
\coordinate[label=$O$] (O) at (0,0,0);
\coordinate[label=$A1$] (A1) at (0,0,5);
\coordinate[label=$A2$] (A2) at (0,5,0);
\coordinate[label=$A3$] (A3) at (5,0,0);
\coordinate[label=$B1$] (B1) at (3,0,0);
\coordinate[label=$B2$] (B2) at (0,0,2);
\coordinate[label=$B3$] (B3) at (3,0,2);
\coordinate[label=$C2$] (C2) at (0,3,2);
\coordinate[label=$C3$] (C3) at (3,2,0);

\draw[fill=blue,opacity=0.3] (A1)--(C2)--(B3);
draw[fill=black,opacity=0.3] (O)--(B2)--(B3)--(B1)
\draw[fill=red,opacity=0.3] (A3)--(C3)--(B3);
\draw[fill=red,opacity=0.3] (B3)--(B1)--(C3);
\draw[fill=blue,opacity=0.3] (C2)--(B2)--(B3);
\draw[fill=brown,opacity=0.3] (B3)--(C2)--(A2)--(C3);
\end{tikzpicture}
\end{document}

我的尝试

答案1

图片

在此处输入图片描述

代码

第一个宏用于设置视角。本例中不使用所有宏。

\documentclass[10pt,a4paper]{minimal}
\usepackage{tikz}
\begin{document}

\newcommand\pgfmathsinandcos[3]{% 
  \pgfmathsetmacro#1{sin(#3)}% 
  \pgfmathsetmacro#2{cos(#3)}% 
}

\begin{tikzpicture}[scale=1.5] 

\pgfmathsetmacro\AngleFuite{135}
\pgfmathsetmacro\coeffReduc{.8}
\pgfmathsetmacro\clen{2}
\pgfmathsinandcos\sint\cost{\AngleFuite}

\begin{scope} [x     = {(\coeffReduc*\cost,-\coeffReduc*\sint)},
               y     = {(1cm,0cm)}, 
               z     = {(0cm,1cm)}]

\path coordinate (O) at (0,0,0)
      coordinate (B) at (0,5,0)
      coordinate (A) at (5,0,0)
      coordinate (S) at (0,0,5)
      coordinate (O) at (0,0,0)
      coordinate (I) at (2,0,3) coordinate (PI) at (2,0,0)
      coordinate (J) at (0,3,2) coordinate (PJ) at (0,3,0)
      coordinate (K) at (2,3,0); 

\draw[thick,-stealth,blue]  (O)  -- (0,0,6);
\draw[thick,-stealth,red]   (O)  -- (6,0,0);
\draw[thick,-stealth,green] (O)  -- (0,6,0);


\draw (A) -- (B) -- (O) -- (A) -- (S) -- (O) 
      (B) -- (S);         

\fill [blue!20, fill opacity = .5]   (A)--(I)--(K)--cycle;
\fill [blue!20, fill opacity = .5]   (B)--(J)--(K)--cycle;
\fill [brown!40,fill opacity = .5,
       draw = brown,ultra thick] (S)--(I)--(PI)--(K) -- (PJ) --(J) --cycle;  
\draw [brown,ultra thick] (I)  -- (K)  -- (J)  ;  
\draw [blue,ultra thick]  (I)  -- (A)  -- (B) -- (J)  ;  
  \end{scope}  

\foreach \v in {A,B,I,J,S}  \draw[fill=gray] (\v) circle (2pt);
\end{tikzpicture}   

\end{document} 

答案2

所以我被这个问题迷住了,并在我的本科期间找到了一个数字的旧解决方案。近三年的时间......那时我还没有发现这个calc图书馆,它还没有现在这么多功能!:)

好的,所以我也有同样的想法,即创建一个设置图来举例说明一些计算。这需要一些三角形、一些平面角和一些角度符号。

我真正想要的是标出其平面内的角度。这样读者就能立即看出它属于哪个角度(好吧,这个图中的几个角度并不能证明这一点,但这很有趣!)。

不用多说,以下是代码:

% Toy with these to get some feel for alignment
\def\angEl{25} % elevation angle
\def\angAz{-125} % azimuth angle
\begin{tikzpicture}[>=latex,%
  % Create the xy-plane
  xyplane/.estyle={%
      cm={%
          cos(\angAz)  , sin(\angAz)*sin(\angEl),%
          -sin(\angAz) , cos(\angAz)*sin(\angEl),%
          (0,0)%
      }%
  },
  % Create the yz-plane
  yzplane/.estyle={%
      cm={%
          cos(\angAz+90) , sin(\angAz+90)*sin(\angEl),%
          0              , cos(\angEl)            ,%
          (0,0)%
      }%
  },
  % Create the tilted-plane
  tplane/.estyle={%
      cm={%
          cos(\angAz)             , -sin(\angAz),%
          sin(\angAz)*sin(\angEl) , cos(\angAz)*sin(\angEl),%
          (0,0)%
      }%
  }]
  % Draw base rectangle, and its notation of current
  \draw[xyplane,dashed] (-3,-3) rectangle (3,3);
  \draw[xyplane,rounded corners,->] (-2.5,3.5) -| node[above] {$I$} (-3.5,2.5);
  \draw[xyplane,rounded corners,->] (2.5,-3.5) -| node[below] {$I$} (3.5,-2.5);
  % Denote coordinates
  \draw[xyplane,<->] (4,0) node[below] {$y$} -| (0,4) node[right] {$x$};
  % Create side lengths
  \draw[xyplane,<->] (1.5,3)  -- node[below left=.5ex] {$a$} ++(0,-3);
  % Coordinates in the plane
  \path[xyplane] (0,3) coordinate (XO);
  \path[xyplane] (3,3) coordinate (X1);
  \path[xyplane] (-3,3) coordinate (X2);
  \draw[xyplane,<->] (-3,3.2) -- node[below right=.5ex] {$a$} (0,3.2);
  \draw[xyplane,<->] (3,3.2) -- node[below right=.5ex] {$a$} (0,3.2);
  % Create coordinate
  \path (0,3) coordinate (X) node[above left] {$P$};
  \fill (X) circle (1.5pt);
  \fill[fill opacity=.25,color=red] (X) -- (X1) -- (X2) -- cycle;
  \draw (X) -- node[pos=0.6,right] {$s$} (XO);
  \draw[<->] (-.2,0) -- node[below left=1ex] {$h$} ++(X);
  \draw (X) -- (X1) (X) -- (X2);
  \draw[->] (0,0) -- (X) -- ++(0,1) node[above] {$z$};
  % Draw in the yzplane
  \path[yzplane] (3,0)+(180:.5) coordinate (BETA1);
  \path[yzplane] (3,0)+(180-48:.5) coordinate (BETA2);
  % Create \beta angle, the notation of yzplane in the node makes the text subsequent to the coordinate transformation
  \draw[yzplane] (BETA1) to[bend left=46] node[pos=0.5,left,yzplane] {$\beta$} (BETA2);
  \draw[yzplane,-stealth] (X) -- ++(90-42:1.3) node[right,yzplane] {$\mathbf B$};
  % Create the angle denotation, this could be made more explicit (it is currently just eye-measured)
  \path[yzplane] (X)+(90:.5) coordinate (B Top 1)
                 (X)+(90-42:.5) coordinate (B Top 2);
  \draw[yzplane] (B Top 1) to[bend left=46] node[pos=0.5,above,yzplane] {$\beta$} (B Top 2);
  \fill[fill opacity=.25,color=black] (X) -- (XO) -- (0,0) -- cycle;
  % Create the \theta angles, these are also approximated by the eye.
  % It was easier at the time... :)
  \path[tplane] (X)+(-.5,-.485) coordinate (Right);
  \draw[tplane] (X)+(-.5,.577) to[out=-160,in=180] (Right);
  % We need large as it is so much transformed that it looks smaller
  \draw[tplane] (X)+(-1,.5) node[tplane,rotate=-90] {\large$\theta_1$}; 
  \draw[tplane] (X)+(-1,-.5) node[tplane,rotate=-90] {\large$\theta_2$}; 
\end{tikzpicture}

其中一些可以借助 calc 缩短,但不会缩短太多。为了获得文本转换,只需添加cm与该节点描述相对应的内容。但人们应该对粗糙的转换保持警惕,正如在角度方面所注意到的那样\theta,我不得不放大字体,否则它看起来会太小。

请注意,在输出中,\beta\theta_i和 都\mathrm B变换到了其平面。

最终输出结果为:

输出

答案3

如果希望轴z垂直,可以更改图像的坐标系。x={(a,b)}作为参数定义图像中坐标的tikzpicture单位向量。请记住,TikZ 仅在 2D 中工作,因此标准组件只是平面中的投影(或其他东西)。xzxy

下面例子中的单位向量可能需要进行微调,但我想你会明白的。(我借用了 cmhughes 代码,只是改变了坐标。

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x={(-5mm,-3.85mm)},z={(0,1cm)},y={(1cm,-.3cm)}]
\draw [->] (0,0) -- (6,0,0) node [right] {$x$};
\draw [->] (0,0) -- (0,6,0) node [above] {$y$};
\draw [->] (0,0) -- (0,0,6) node [below left] {$z$};
\draw[fill=blue,opacity=.5] (0,5,0)--(0,3,3)--(2,3,0);
\draw[fill=blue,opacity=.5] (5,0,0)--(2,0,2)--(2,3,0);
\draw[fill=orange,opacity=.5] (0,3,3)--(0,0,5)--(2,0,2)--(2,3,0);
\draw[fill=red!50,opacity=.5] (2,0,2)--(2,3,0)--(2,0,0);
\draw[fill=red!50,opacity=.5] (0,3,3)--(2,3,0)--(0,3,0);
\end{tikzpicture}
\end{document}

答案4

我认为采用tikz-3dplot这里不应该缺少包。

% !TeX program = pdflatex
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{tikz,tikz-3dplot}

\tdplotsetmaincoords{60}{120}

\begin{document}
  \begin{tikzpicture}[>=stealth,tdplot_main_coords]
    \coordinate (O) at (0,0,0);
    \coordinate[label=above right:{$(0,0,5)$}] (A) at (0,0,5);
    \coordinate[label=above left:{$(2,0,2)$}] (B) at (2,0,2);
    \coordinate[label=above right:{$(0,3,3)$}] (C) at (0,3,3);
    \coordinate[label=above left:{$(5,0,0)$}] (D) at (5,0,0);
    \coordinate[label=above right:{$(0,5,0)$}] (E) at (0,5,0);

    \draw[->] (O) -- (6,0,0);
    \draw[->] (O) -- (0,6,0);
    \draw[->] (O) -- (0,0,6);

    \filldraw[draw=brown,fill=brown,fill opacity=0.1] (A) -- (B) -- (2,3,0) -- (C) -- cycle;
    \filldraw[draw=brown,fill=brown,fill opacity=0.1] (B) -- (2,0,0) -- (2,3,0)-- cycle;
    \filldraw[draw=brown,fill=brown,fill opacity=0.1] (C) -- (0,3,0) -- (2,3,0)-- cycle;
    \fill[fill=blue,fill opacity=0.1] (B) -- (D) -- (2,3,0)-- cycle;
    \fill[fill=blue,fill opacity=0.1] (C) -- (E) -- (2,3,0)-- cycle;
    \draw[blue] (B) -- (D) -- (E) -- (C);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容