我正在尝试声明一个新的 tikz 形状来绘制 3d 坐标轴。我终于完成了基础知识,但仍有一些细节我无法弄清楚
为什么比例这么大?在上图中,轴长定义为
0.5mm
但实际上要大一个数量级以上。我如何定位 x、y、z 标签,使它们位于相应锚点的中心?
\documentclass{letter}
\usepackage{tikz}
\usetikzlibrary{3d}
\tikzset{length/.initial=1mm}
\tikzset{sep/.initial=0mm}
\makeatletter
\newbox\pgfnodepartxbox
\newbox\pgfnodepartybox
\newbox\pgfnodepartzbox
\pgfdeclareshape{axis}{
\nodeparts{x,y,z}
\saveddimen{\length} {\pgf@x=\pgfkeysvalueof{/tikz/length}}
\saveddimen{\sep} {\pgf@x=\pgfkeysvalueof{/tikz/sep}}
\anchor{center}{\pgfpointorigin}
\anchor{text}{\pgfpointxyz{\sep}{\sep}{0}}
\anchor{x}{\pgfpointxyz{\length + \sep}{0}{0}}
\anchor{y}{\pgfpointxyz{0}{\length + \sep}{0}}
\anchor{z}{\pgfpointxyz{0}{0}{\length + \sep}}
\backgroundpath{%
\pgfsetarrowsend{to}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpointxyz{\length}{0}{0}}
\pgfusepath{stroke}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpointxyz{0}{\length}{0}}
\pgfusepath{stroke}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpointxyz{0}{0}{\length}}
\pgfusepath{stroke}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node [shape=axis, length=0.5mm, sep=0.1mm]
(p0) at (0,0,0)
{
\nodepart{x} \(x\)
\nodepart{y} \(y\)
\nodepart{z} \(z\)
};
\draw[|-|] (0,-2mm) -- node[below] {14mm} ++(14mm, 0);
\end{tikzpicture}
\end{document}