这个问题与我之前的问题相关 如何在 TikZ 上绘制加泰罗尼亚数图
我希望能够使用 Tikz 绘制广义加泰罗尼亚数图。更具体地说,我想要一个以前二维版本的三维版本。三维加泰罗尼亚数定义为从原点到点 (n,n,n) 的步长 (1,0,0)、(0,1,0) 和 (0,0,1) 的三维格子路径,路径中的点满足 0 ≤ x_1 ≤ x_2 ≤ x_3。
答案1
就我的口味而言,保罗·加博利的答案有点太不雅了,这里还有另一个:
代码
\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\begin{document}
\newcommand{\xangle}{-10}
\newcommand{\yangle}{230}
\newcommand{\zangle}{270}
\newcommand{\xlength}{1}
\newcommand{\ylength}{1}
\newcommand{\zlength}{1}
\pgfmathsetmacro{\xx}{\xlength*cos(\xangle)}
\pgfmathsetmacro{\xy}{\xlength*sin(\xangle)}
\pgfmathsetmacro{\yx}{\ylength*cos(\yangle)}
\pgfmathsetmacro{\yy}{\ylength*sin(\yangle)}
\pgfmathsetmacro{\zx}{\zlength*cos(\zangle)}
\pgfmathsetmacro{\zy}{\zlength*sin(\zangle)}
\begin{tikzpicture}
[ x={(\xx cm,\xy cm)},
y={(\yx cm,\yy cm)},
z={(\zx cm,\zy cm)},
]
\foreach \a in {0,...,3}
{ \draw[help lines]
(\a,0,0) -- (\a,0,3)
(0,0,\a) -- (3,0,\a)
node at (\a,0,-0.2) {\tiny\a}
node at (\a,3,3.2) {\tiny\a}
(0,\a,0) -- (0,\a,3)
(0,0,\a) -- (0,3,\a)
node at (0,\a,-0.2) {\tiny\a}
node at (3,\a,3.2) {\tiny\a}
(0,\a,3) -- (3,\a,3)
(\a,0,3) -- (\a,3,3)
node at (3.2,0,\a) {\tiny\a}
node at (0,3.2,\a) {\tiny\a};
}
\node at (1.5,0,-0.5) {x};
\node at (1.5,3,3.5) {x};
\node at (0,1.5,-1) {y};
\node at (3,1.5,4) {y};
\node at (3.6,0,1.5) {z};
\node at (0,3.6,1.5) {z};
\draw[red,thin] (0,0,0) -- (0,0,3);
\draw[red,thin] (0,0,0) -- (0,3,3);
\draw[red,thin] (0,0,0) -- (3,3,3);
\draw[red,thin] (0,0,3) -- (0,3,3);
\draw[red,thin] (0,0,3) -- (3,3,3);
\draw[red,thin] (0,3,3) -- (3,3,3);
\draw[very thick,blue]
(0,0,0)
-- ++(0,0,1)
-- ++(0,1,0)
-- ++(0,0,1)
-- ++(1,0,0)
-- ++(0,1,0)
-- ++(0,0,1)
-- ++(1,0,0)
-- ++(0,1,0)
-- ++(1,0,0);
\draw[dashed,blue]
(1,1,2) -- (1,1,3);
\end{tikzpicture}
\end{document}
结果
答案2
以下是 3D 路径的示例:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \a in {0,...,3}{
\draw[help lines]
(\a,0,0) -- (\a,0,-3)
(0,0,-\a) -- (3,0,-\a)
%
(0,\a,0) -- (0,\a,-3)
(0,0,-\a) -- (0,3,-\a)
%
(0,\a,-3) -- (3,\a,-3)
(\a,0,-3) -- (\a,3,-3)
;
}
\draw[dashed,blue]
(1,0,-1) -- (1,1,-1)
(3,0,-1) -- (3,1,-1)
(3,0,-2) -- (3,2,-2)
;
\draw[line width=1pt,blue]
(0,0,0)
-- ++(1,0,0)
-- ++(0,1,0)
-- ++(0,0,-1)
-- ++(1,0,0)
-- ++(1,0,0)
-- ++(0,1,0)
-- ++(0,0,-1)
-- ++(0,1,0)
-- ++(0,0,-1)
;
\end{tikzpicture}
\end{document}