根据pgf 手册,语法
<coordinate>!<projection coordinate!<angle>:<second coordinate>
可用于正交投影到从到 的<projection coordinate>
线上 。<coordinate>
<second coordinate>
我可以在两个维度上使它正常工作:
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[
, line join=round
, line cap=round
]
\coordinate (O) at (0, 0);
\coordinate (v) at (2, 0);
\coordinate (b) at (1, 1);
\coordinate (p) at ($ (O)!(b)!(v) $);
\draw[ultra thick, ->, blue] (O) -- (v) node[right] {$\vec{v}$};
\draw[ultra thick, ->, red] (O) -- (b) node[above] {$\vec{b}$};
\draw[ultra thick, ->, purple] (O) -- (p) node[below] {$\vec{p}$};
\end{tikzpicture}
\end{document}
然而在三维空间中,事情就出现了问题
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[
, line join=round
, line cap=round
]
\coordinate (O) at (0, 0, 0);
\coordinate (v) at (0, 0, 1);
\coordinate (b) at (1, 2, 1);
\coordinate (p) at ($ (O)!(b)!(v) $);
\draw[ultra thick, ->, blue] (O) -- (v) node[right] {$\vec{v}$};
\draw[ultra thick, ->, red] (O) -- (b) node[above] {$\vec{b}$};
\draw[ultra thick, ->, purple] (O) -- (p) node[below] {$\vec{p}$};
\end{tikzpicture}
\end{document}
(1, 2, 1)
在 所跨越的线上的投影(0, 0, 1)
是(0, 0, 1)
,这在图中显然是不正确的。
我做错什么了吗或者这是一个限制tikz
?
答案1
答案是:不,公共库尚不支持 3d 计算。但是,有一个实验图书馆3d工具,您可能想查看一下。保存这个文件位于tikzlibrary3dtools.code.tex
LaTeX 可以找到它的地方,例如,在下面的 MWE 所在的同一目录中。此库支持标量产品等。
\documentclass[tikz]{standalone}
\usetikzlibrary{3dtools}
\begin{document}
\begin{tikzpicture}[
, line join=round
, line cap=round
]
\path (0, 0, 0) coordinate (O)
(0, 0, 2) coordinate (v)
(1, 2, 1) coordinate (b);
\pgfmathsetmacro{\myproj}{TD("(b)o(v)")/TD("(v)o(v)")}
\path[3d coordinate={(p)=\myproj*(v)}];
\draw[ultra thick, ->, blue] (O) -- (v) node[right] {$\vec{v}$};
\draw[ultra thick, ->, red] (O) -- (b) node[above] {$\vec{b}$};
\draw[ultra thick, ->, purple] (O) -- (p) node[below] {$\vec{p}$};
\end{tikzpicture}
\end{document}