我想建立一个倒金字塔,其顶点位于 x、y、z 轴的原点。我的尝试
\definecolor{cof}{RGB}{219,144,71}
\definecolor{pur}{RGB}{186,146,162}
\definecolor{greeo}{RGB}{91,173,69}
\definecolor{greet}{RGB}{52,111,72}
\begin{document}
\begin{tikzpicture}[thick,scale=5]
\coordinate (A1) at (0,0);
\coordinate (A2) at (0.6,0.2);
\coordinate (A3) at (1,0);
\coordinate (A4) at (0.4,-0.2);
\coordinate (B2) at (0.5,-0.5);
\begin{scope}[thick,dashed,,opacity=0.6]
\draw (A2) -- (B2);
\end{scope}
\draw[fill=cof,opacity=0.6] (A1) -- (A4) -- (A3) -- (A2);
\draw[fill=pur,opacity=0.6] (A1) -- (A4) -- (B2);
\draw[fill=greeo,opacity=0.6] (A3) -- (A4);
\draw[fill=greet,opacity=0.6] (A3) -- (A4) -- (B2);
\draw (A1) -- (B2) -- (A3);
\draw (A1) -- (A2) -- (A3);
\end{tikzpicture}
\end{document}
产生图片
但我无法添加轴。
答案1
我会用tikz-3dplot
它。然后您可以使用 3d 坐标,添加轴等就变得很简单了。
\documentclass[tikz,border=3.14mm]{standalone}
\definecolor{cof}{RGB}{219,144,71}
\definecolor{pur}{RGB}{186,146,162}
\definecolor{greeo}{RGB}{91,173,69}
\definecolor{greet}{RGB}{52,111,72}
\usepackage{tikz-3dplot}
\begin{document}
\begin{tikzpicture}[thick,scale=5]
\tdplotsetmaincoords{70}{60}
\begin{scope}[tdplot_main_coords]
\coordinate (A1) at (-0.5,-0.5,0);
\coordinate (A2) at (-0.5,0.5,0);
\coordinate (A3) at (0.5,0.5,0);
\coordinate (A4) at (0.5,-0.5,0);
\coordinate (B2) at (0,0,-0.5);
\begin{scope}[thick,dashed,,opacity=0.6]
\draw (A2) -- (B2);
\end{scope}
\draw[fill=cof,opacity=0.6] (A1) -- (A4) -- (A3) -- (A2) -- cycle;
\draw[fill=pur,opacity=0.6] (A1) -- (A4) -- (B2);
%\draw[fill=greeo,opacity=0.6] (A3) -- (A4);
\draw[fill=greet,opacity=0.6] (A3) -- (A4) -- (B2);
\draw (A1) -- (B2) -- (A3);
\draw (A1) -- (A2) -- (A3);
\draw[-stealth] (0,0,0) -- (1,0,0) node[pos=1.1]{$x$};
\draw[-stealth] (0,0,0) -- (0,1,0) node[pos=1.1]{$y$};
\draw[-stealth] (0,0,0) -- (0,0,1) node[pos=1.1]{$z$};
\end{scope}
\end{tikzpicture}
\end{document}
或者
\documentclass[tikz,border=3.14mm]{standalone}
\definecolor{cof}{RGB}{219,144,71}
\definecolor{pur}{RGB}{186,146,162}
\definecolor{greeo}{RGB}{91,173,69}
\definecolor{greet}{RGB}{52,111,72}
\usepackage{tikz-3dplot}
\begin{document}
\begin{tikzpicture}[thick,scale=5]
\tdplotsetmaincoords{80}{60}
\begin{scope}[tdplot_main_coords]
\coordinate (A1) at (-0.5,-0.5,0);
\coordinate (A2) at (-0.5,0.5,0);
\coordinate (A3) at (0.5,0.5,0);
\coordinate (A4) at (0.5,-0.5,0);
\coordinate (B2) at (0,0,-0.5);
\begin{scope}[thick,dashed,,opacity=0.6]
\draw (A2) -- (B2);
\end{scope}
\draw[fill=cof,opacity=0.6] (A1) -- (A4) -- (A3) -- (A2) -- cycle;
\draw[fill=pur,opacity=0.6] (A1) -- (A4) -- (B2);
%\draw[fill=greeo,opacity=0.6] (A3) -- (A4);
\draw[fill=greet,opacity=0.6] (A3) -- (A4) -- (B2);
\draw (A1) -- (B2) -- (A3);
\draw (A1) -- (A2) -- (A3);
\draw[-stealth] (A1) -- ++ (0.5,0,0) node[above]{$x$};
\draw[-stealth] (A1) -- ++ (0,0.5,0) node[above]{$y$};
\draw[-stealth] (A1) -- ++ (0,0,0.5) node[pos=1.1]{$z$};
\end{scope}
\end{tikzpicture}
\end{document}
至于您旋转坐标轴的请求:
\documentclass[tikz,border=3.14mm]{standalone}
\definecolor{cof}{RGB}{219,144,71}
\definecolor{pur}{RGB}{186,146,162}
\definecolor{greeo}{RGB}{91,173,69}
\definecolor{greet}{RGB}{52,111,72}
\usepackage{tikz-3dplot}
\begin{document}
\foreach \X in {0,5,...,355}
{\begin{tikzpicture}[thick,scale=5]
\path (-1.4,-0.6) rectangle (0.7,0.7);
\tdplotsetmaincoords{80}{60}
\begin{scope}[tdplot_main_coords]
\coordinate (A1) at (-0.5,-0.5,0);
\coordinate (A2) at (-0.5,0.5,0);
\coordinate (A3) at (0.5,0.5,0);
\coordinate (A4) at (0.5,-0.5,0);
\coordinate (B2) at (0,0,-0.5);
\begin{scope}[thick,dashed,,opacity=0.6]
\draw (A2) -- (B2);
\end{scope}
\draw[fill=cof,opacity=0.6] (A1) -- (A4) -- (A3) -- (A2) -- cycle;
\draw[fill=pur,opacity=0.6] (A1) -- (A4) -- (B2);
\draw[fill=greet,opacity=0.6] (A3) -- (A4) -- (B2);
\draw (A1) -- (B2) -- (A3);
\draw (A1) -- (A2) -- (A3);
\tdplotsetrotatedcoords{\X}{0}{0}
\begin{scope}[tdplot_rotated_coords]
\draw[-stealth] (A1) -- ++ (0.5,0,0) node[above]{$x$};
\draw[-stealth] (A1) -- ++ (0,0.5,0) node[above]{$y$};
\draw[-stealth] (A1) -- ++ (0,0,0.5) node[pos=1.1]{$z$};
\end{scope}
\end{scope}
\end{tikzpicture}}
\end{document}
当然,三维空间中可能存在不止一种旋转。这反映在以下事实中:\tdplotsetrotatedcoords{<angle 1>}{<angle 2>}{<angle 3>}
具有三个参数(角度)的事实上。如果你对这些参数的解释感到困惑,你可能需要看看这个问题。