如何在 tikz 3dplot 中翻译坐标?

如何在 tikz 3dplot 中翻译坐标?
     \tdplotsetmaincoords{30}{30}

  \begin{tikzpicture}[scale=5,tdplot_main_coords]

    \def\x{1};
    \def\y{1};
    \def\z{1};

    \coordinate (O) at (\x,\y,\z);
    \tdplotsetcoord{P}{1.414213}{54.68636}{45}

    \draw[fill=gray!50,fill opacity=0.5] (\x,\y,\z) -- ((\x,\y,\z)+Py) -- ((\x,\y,\z)+Pyz) -- ((\x,\y,\z)+Pz) -- cycle;
   % \draw[fill=blue,fill opacity=0.5] (O) -- (Px) -- (Pxy) -- (Py) -- cycle;
%    \draw[fill=green,fill opacity=0.5] (O) -- (Px) -- (Pxz) -- (Pz) -- cycle;
   % \draw[fill=yellow,fill opacity=0.5] (Pz) -- (Pyz) -- (P) -- (Pxz) -- cycle;
    %\draw[fill=red,fill opacity=0.5] (Px) -- (Pxy) -- (P) -- (Pxz) -- cycle;
    %\draw[fill=pink,fill opacity=0.5] (Py) -- (Pxy) -- (P) -- (Pyz) -- cycle;

  \end{tikzpicture}

我怎样才能将 P 的每个投影平移 ((\x,\y,\z) ?

答案1

不确定这是否正是您想要绘制的,但这里有一个使用 tikzcalc库平移坐标的示例。我们使用了不同的颜色来简化将代码与图表关联起来的过程,蓝线是每个投影的平移:

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{calc}

%\tdplotsetmaincoords{30}{30}

\begin{document}
\begin{tikzpicture}%[tdplot_main_coords]

    \def\x{3};
    \def\y{2};
    \def\z{2};

    \def\Px{2};
    \def\Py{3};
    \def\Pz{3};

    \coordinate (O) at (\x,\y,\z);

    \tdplotsetcoord{P}{\Px}{\Py}{\Pz};

    % Translated prohections
    \coordinate (Pxy) at ($(\x,\y,0) + (\Px,\Py,\Pz)$);
    \coordinate (Pyz) at ($(0,\y,\z) + (\Px,\Py,\Pz)$);
    \coordinate (Pxz) at ($(\x,0,\z) + (\Px,\Py,\Pz)$);

    % Draw axis
    \draw [gray, thin, ->] (-1,0,0) -- (4,0,0) node [right] {$x$};gray
    \draw [gray, thin, ->] (0,-1,0) -- (0,4,0) node [left] {$y$}; 
    \draw [gray, thin, ->] (0,0,-1) -- (0,0,3) node [left] {$z$}; 

    % Draw (O)
    \draw [red, ultra thick, -latex] (0,0,0) -- (O);

    % so that we can see where the projection are on each plane:
    \draw [green,   thin  ] (O)      -- (\x,\y,0);
    \draw [green,   dotted] (\x,0,0) -- (\x,\y,0);
    \draw [green,   dotted] (0,\y,0) -- (\x,\y,0);

    \draw [brown,   thin  ]  (O)      -- (0,\y,\z);
    \draw [brown,   dotted] (0,\y,0) -- (0,\y,\z);
    \draw [brown,   dotted] (0,0,\z) -- (0,\y,\z);

    \draw [magenta, thin  ] (O)      -- (\x,0,\z);
    \draw [magenta, dotted] (\x,0,0) -- (\x,0,\z);
    \draw [magenta, dotted] (0,0,\z) -- (\x,0,\z);


    \draw [blue, -latex] (\x,\y,0) -- (Pxy);
    \draw [blue, -latex] (0,\y,\z) -- (Pyz);
    \draw [blue, -latex] (\x,0,\z) -- (Pxz);

    \draw [fill=gray!50,fill opacity=0.5, ultra thick]
        (Pxy) -- (Pyz) -- (Pxz) -- cycle;


%   \draw[fill=blue,fill opacity=0.5] (O) -- (Px) -- (Pxy) -- (Py) -- cycle;
%   \draw[fill=green,fill opacity=0.5] (O) -- (Px) -- (Pxz) -- (Pz) -- cycle;
%   \draw[fill=yellow,fill opacity=0.5] (Pz) -- (Pyz) -- (P) -- (Pxz) -- cycle;
%   \draw[fill=red,fill opacity=0.5] (Px) -- (Pxy) -- (P) -- (Pxz) -- cycle;
%   \draw[fill=pink,fill opacity=0.5] (Py) -- (Pxy) -- (P) -- (Pyz) -- cycle;

\end{tikzpicture}
\end{document}

取消注释代码,得到下图,因此我不确定到底想要什么:

在此处输入图片描述

代码:

\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{calc}

%\tdplotsetmaincoords{30}{30}

\begin{document}
\begin{tikzpicture}%[tdplot_main_coords]

    \def\x{3};
    \def\y{2};
    \def\z{2};

    \def\Px{2};
    \def\Py{3};
    \def\Pz{3};

    \coordinate (O) at (\x,\y,\z);

    \tdplotsetcoord{P}{\Px}{\Py}{\Pz};

    % Translated prohections
    \coordinate (Pxy) at ($(\x,\y,0) + (\Px,\Py,\Pz)$);
    \coordinate (Pyz) at ($(0,\y,\z) + (\Px,\Py,\Pz)$);
    \coordinate (Pxz) at ($(\x,0,\z) + (\Px,\Py,\Pz)$);

    % Draw axis
    \draw [gray, thin, ->] (-1,0,0) -- (4,0,0) node [right] {$x$};gray
    \draw [gray, thin, ->] (0,-1,0) -- (0,4,0) node [left] {$y$}; 
    \draw [gray, thin, ->] (0,0,-1) -- (0,0,3) node [left] {$z$}; 

%   % Draw (O)
%   \draw [red, ultra thick, -latex] (0,0,0) -- (O);
%
%   % so that we can see where the projection are on each plane:
%   \draw [green,   thin  ] (O)      -- (\x,\y,0);
%   \draw [green,   dotted] (\x,0,0) -- (\x,\y,0);
%   \draw [green,   dotted] (0,\y,0) -- (\x,\y,0);
%
%   \draw [brown,   thin  ]  (O)      -- (0,\y,\z);
%   \draw [brown,   dotted] (0,\y,0) -- (0,\y,\z);
%   \draw [brown,   dotted] (0,0,\z) -- (0,\y,\z);
%
%   \draw [magenta, thin  ] (O)      -- (\x,0,\z);
%   \draw [magenta, dotted] (\x,0,0) -- (\x,0,\z);
%   \draw [magenta, dotted] (0,0,\z) -- (\x,0,\z);
%
%
%   \draw [blue, -latex] (\x,\y,0) -- (Pxy);
%   \draw [blue, -latex] (0,\y,\z) -- (Pyz);
%   \draw [blue, -latex] (\x,0,\z) -- (Pxz);
%
%   \draw [fill=gray!50,fill opacity=0.5, ultra thick]
%       (Pxy) -- (Pyz) -- (Pxz) -- cycle;


   \draw[fill=blue,fill opacity=0.5] (O) -- (Px) -- (Pxy) -- (Py) -- cycle;
   \draw[fill=green,fill opacity=0.5] (O) -- (Px) -- (Pxz) -- (Pz) -- cycle;
   \draw[fill=yellow,fill opacity=0.5] (Pz) -- (Pyz) -- (P) -- (Pxz) -- cycle;
   \draw[fill=red,fill opacity=0.5] (Px) -- (Pxy) -- (P) -- (Pxz) -- cycle;
   \draw[fill=pink,fill opacity=0.5] (Py) -- (Pxy) -- (P) -- (Pyz) -- cycle;

\end{tikzpicture}
\end{document}

相关内容