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

according to http://latex-community.org/tikz-3dplot_example.pdf instead of

      \tdplotsetmaincoords{70}{115}

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

I can do

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

Why might this not be working in my case?

I want to do this so that I can change the style per \draw command.


The problem seems to be with \tdplotsetcoord{P}{1.414213}{54.68636}{45}

even if I use the tdplot_main_coords style \draw[fill=gray!50,fill opacity=0.5,tdplot_main_coords] the position of P, Px...etc is returned same as to when the style is not used

How to counter this?

share|improve this question
3  
Please refrain from using minimal class. It's not meant to provide a minimal document but a minimal available TeX instruction set (for more technical purposes) which can give completely different results than, say from article. You can use preview or standalone classes or simply use article. –  percusse Feb 22 '13 at 9:56

1 Answer 1

I don't exactly know the inner workings but a quick test shows that it has to do something with the transformation matrix of the tikzpicture. Hence, scoping the relevant parts gives a result which looks like what you are after.

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

enter image description here

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.