\documentclass{minimal}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{115}
\begin{tikzpicture}[scale=4,tdplot_main_coords]
\coordinate (O) at (1,1,1);
\tdplotsetcoord{P}{1.414213}{54.68636}{45}
\draw[fill=gray!50,fill opacity=0.5] (O) -- ($(O) + (Py)$) -- ($(O) + (Pyz)$) -- ($(O) + (Pz)$) -- cycle;
\draw[fill=blue,fill opacity=0.5] (O) -- ($(O) + (Px)$) -- ($(O) + (Pxy)$) -- ($(O) + (Py)$) -- cycle;
\draw[fill=green,fill opacity=0.5] (O) -- ($(O) + (Px)$) -- ($(O) + (Pxz)$) -- ($(O) + (Pz)$) -- cycle;
\draw[fill=yellow,fill opacity=0.5] ($(O) + (Pz)$) -- ($(O) + (Pyz)$) -- ($(O) + (P)$) -- ($(O) + (Pxz)$) -- cycle;
\draw[fill=red,fill opacity=0.5] ($(O) + (Px)$) -- ($(O) + (Pxy)$) -- ($(O) + (P)$) -- ($(O) + (Pxz)$) -- cycle;
\draw[fill=pink,fill opacity=0.5] ($(O) + (Py)$) -- ($(O) + (Pxy)$) -- ($(O) + (P)$) -- ($(O) + (Pyz)$) -- cycle;
\tdplotsetmaincoords{10}{10}%%%%%%%%%%%%this is not changing the rotation since the begin tikzpicture has alread used it once
\coordinate (M) at (3,2,1);
\tdplotsetcoord{P}{1.414213}{54.68636}{45}
\draw[fill=gray!50,fill opacity=0.5] (M) -- ($(M) + (Py)$) -- ($(M) + (Pyz)$) -- ($(M) + (Pz)$) -- cycle;
\draw[fill=blue,fill opacity=0.5] (M) -- ($(M) + (Px)$) -- ($(M) + (Pxy)$) -- ($(M) + (Py)$) -- cycle;
\draw[fill=green,fill opacity=0.5] (M) -- ($(M) + (Px)$) -- ($(M) + (Pxz)$) -- ($(M) + (Pz)$) -- cycle;
\draw[fill=yellow,fill opacity=0.5] ($(M) + (Pz)$) -- ($(M) + (Pyz)$) -- ($(M) + (P)$) -- ($(M) + (Pxz)$) -- cycle;
\draw[fill=red,fill opacity=0.5] ($(M) + (Px)$) -- ($(M) + (Pxy)$) -- ($(M) + (P)$) -- ($(M) + (Pxz)$) -- cycle;
\draw[fill=pink,fill opacity=0.5] ($(M) + (Py)$) -- ($(M) + (Pxy)$) -- ($(M) + (P)$) -- ($(M) + (Pyz)$) -- cycle;
\end{document}
根据http://latex-community.org/tikz-3dplot_example.pdf 代替
\tdplotsetmaincoords{70}{115}
\begin{tikzpicture}[scale=4,tdplot_main_coords]
我可以
\tdplotsetmaincoords{70}{115}
\draw[fill=gray!50,fill opacity=0.5,tdplot_main_coords] (O) -- ($(O) + (Py)$) -- ($(O) + (Pyz)$) -- ($(O) + (Pz)$) -- cycle;%inlcude the style for every draw separately.
为什么这对于我的情况可能不起作用?
我想这样做以便我可以按照\draw
命令改变样式。
问题似乎在于
\tdplotsetcoord{P}{1.414213}{54.68636}{45}
即使我使用该tdplot_main_coords
样式\draw[fill=gray!50,fill opacity=0.5,tdplot_main_coords]
,P、Px……等的位置也会返回与不使用该样式时相同的位置。
如何应对这种情况?
答案1
我不太清楚内部工作原理,但快速测试表明它与 的变换矩阵有关tikzpicture
。因此,确定相关部分的范围会得到您想要的结果。
\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{115}
\begin{tikzpicture}[scale=4]
\begin{scope}[tdplot_main_coords]
\coordinate (O) at (1,1,1);
\tdplotsetcoord{P}{1.414213}{54.68636}{45}
\draw[fill=gray!50,fill opacity=0.5] (O) -- ($(O) + (Py)$) -- ($(O) + (Pyz)$) -- ($(O) + (Pz)$) -- cycle;
\draw[fill=blue,fill opacity=0.5] (O) -- ($(O) + (Px)$) -- ($(O) + (Pxy)$) -- ($(O) + (Py)$) -- cycle;
\draw[fill=green,fill opacity=0.5] (O) -- ($(O) + (Px)$) -- ($(O) + (Pxz)$) -- ($(O) + (Pz)$) -- cycle;
\draw[fill=yellow,fill opacity=0.5] ($(O) + (Pz)$) -- ($(O) + (Pyz)$) -- ($(O) + (P)$) -- ($(O) + (Pxz)$) -- cycle;
\draw[fill=red,fill opacity=0.5] ($(O) + (Px)$) -- ($(O) + (Pxy)$) -- ($(O) + (P)$) -- ($(O) + (Pxz)$) -- cycle;
\draw[fill=pink,fill opacity=0.5] ($(O) + (Py)$) -- ($(O) + (Pxy)$) -- ($(O) + (P)$) -- ($(O) + (Pyz)$) -- cycle;
\end{scope}
\begin{scope}
\tdplotsetmaincoords{10}{10}
\coordinate (M) at (3,2,1);
\tdplotsetcoord{P}{1.414213}{54.68636}{45}
\draw[fill=gray!50,fill opacity=0.5] (M) -- ($(M) + (Py)$) -- ($(M) + (Pyz)$) -- ($(M) + (Pz)$) -- cycle;
\draw[fill=blue,fill opacity=0.5] (M) -- ($(M) + (Px)$) -- ($(M) + (Pxy)$) -- ($(M) + (Py)$) -- cycle;
\draw[fill=green,fill opacity=0.5] (M) -- ($(M) + (Px)$) -- ($(M) + (Pxz)$) -- ($(M) + (Pz)$) -- cycle;
\draw[fill=yellow,fill opacity=0.5] ($(M) + (Pz)$) -- ($(M) + (Pyz)$) -- ($(M) + (P)$) -- ($(M) + (Pxz)$) -- cycle;
\draw[fill=red,fill opacity=0.5] ($(M) + (Px)$) -- ($(M) + (Pxy)$) -- ($(M) + (P)$) -- ($(M) + (Pxz)$) -- cycle;
\draw[fill=pink,fill opacity=0.5] ($(M) + (Py)$) -- ($(M) + (Pxy)$) -- ($(M) + (P)$) -- ($(M) + (Pyz)$) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}