评论

评论
\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}

我想要两个立方体有不同的方向,但又位于同一个图形中?我该怎么做?

答案1

评论

您可以scope在一幅图纸中使用多个坐标系。

执行

\documentclass[tikz]{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\begin{tikzpicture}[scale=4]
    \tdplotsetmaincoords{70}{115}
    \begin{scope}[tdplot_main_coords]
        \coordinate (O) at (0,0,0);
        \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}

    \tdplotsetmaincoords{10}{10}
    \begin{scope}[tdplot_main_coords,xshift=1cm]
        \coordinate (M) at (0,0,0);
        \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}

输出

在此处输入图片描述

相关内容