![3D 图 - 阶跃函数](https://linux22.com/image/469148/3D%20%E5%9B%BE%20-%20%E9%98%B6%E8%B7%83%E5%87%BD%E6%95%B0.png)
我想为步进函数生成 3D 图片,如下所示:
但我被卡住了。下面,我尝试了一些方法。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}[scale=0.5]
% Draw the axes
\draw[->] (0,0,0) -- (8,0,0) node[below] {$y$};
\draw[->] (0,0,0) -- (0,8,0) node[left] {$z$};
\draw[->] (0,0,0) -- (0,0,5) node[above] {$x$};
\pgfmathsetmacro{\numlevels}{4}
\pgfmathsetmacro{\levelheight}{4}
\foreach \x in {0,1,2,3,4,5,6,7} {
\foreach \y in {0,...,\numlevels} {
\draw (\x,\y,0) -- (\x,\y,\levelheight) -- (\x+1,\y,\levelheight) -- (\x+1,\y,0) -- cycle;
\draw (\x,\y,0) -- (\x,\y,\levelheight) -- (\x,\y+1,\levelheight) -- (\x,\y+1,0) -- cycle;
\draw (\x,\y+1,0) -- (\x,\y+1,\levelheight) -- (\x+1,\y+1,\levelheight) -- (\x+1,\y+1,0) -- cycle;
\draw (\x+1,\y,0) -- (\x+1,\y,\levelheight) -- (\x+1,\y+1,\levelheight) -- (\x+1,\y+1,0) -- cycle;
}
}
\node[align=center] at (-0.5,-1.1,2) {\resizebox{!}{0.5\height}{\footnotesize{$b=x_{2}$}}};
\node[align=center] at (1.2,1,3) {\resizebox{!}{0.5\height}{\footnotesize{$b=x_{1}$}}};
\end{tikzpicture}
\end{document}
输出为:
任何解决方案或想法都会非常有帮助!