Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
     \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}

How can I translate every projection of P by ((\x,\y,\z) ?

share|improve this question
2  
If you add \usetikzlibrary{calc} to your preamble, then you can do coordinate calculations with ($(\x,\y,\z)+(\Px,\Py,\Pz)$). But you need to first get values of \Px, \Py, \Pyz. –  Peter Grill Feb 22 '13 at 8:08

1 Answer 1

Not sure if this exactly what you are trying to draw, but here is an illustration of how to translate coordinate using the tikz's calc library. Different colors have been used to simplify relating the code to the diagram and the blue lines are the translation of each of the projections:

enter image description here

Code:

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

Uncommenting out your code, yields the following diagram, and hence the reason I am not sure what exactly is desired:

enter image description here

Code:

\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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.