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.

I'm creating some 3D graphics using TikZ, and I need to apply a transformation matrix to some coordinates I'm specifying in 2D so they end up in 3D. I am going to draw graphics on all three visible sides of a cube, and I have defined macros that work in 2D that I want to be able to use on those sides. Is there any way to do this? I saw that there are some primitive transformations in PGF, but they all work in 2D.

share|improve this question
add comment

1 Answer

up vote 12 down vote accepted

How about this:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{3d}

\begin{document}

\tikzset{xzplane/.style={canvas is xz plane at y=#1,very thin}}
\tikzset{yzplane/.style={canvas is yz plane at x=#1,very thin}}
\tikzset{xyplane/.style={canvas is xy plane at z=#1,very thin}}

\begin{tikzpicture}[x={(0.985cm,-0.174cm)},y={(-0.906cm,-0.423cm)},z={(0cm,1cm)}]
    \draw[xzplane=5] (0,0) -- (5,0) -- (5,5) -- (0,5) -- cycle;
    \draw[yzplane=5] (0,0) -- (5,0) -- (5,5) -- (0,5) -- cycle;
    \draw[xyplane=5] (0,0) -- (5,0) -- (5,5) -- (0,5) -- cycle;
    \foreach \x in {xzplane,yzplane,xyplane}
    {   \draw[\x=5] (1,1) -- (4,1) -- (2.5,4) -- cycle;
        \filldraw[\x=5,red,fill opacity=0.2,draw=black] (1.5,1.5) circle (0.5);
        \filldraw[\x=5,green,fill opacity=0.2,draw=black] (3.5,1.5) circle (0.5);
        \filldraw[\x=5,blue,fill opacity=0.2,draw=black] (1.5,3.5) circle (0.5);
        \filldraw[\x=5,yellow,fill opacity=0.2,draw=black] (3.5,3.5) circle (0.5);
    }
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
That definitely seems like a way to go if you want to make a cube like in my case, thank you very much. What if you want to define an arbitrary plane, like x+2y+z=3 or something like that, is that possible? –  StrawberryFieldsForever Jul 13 '12 at 11:47
    
Hmm, I don't think this will be possible with the mechanism I used. Also, with non-orthogonal another problem arises: you must specify the origin and the axes on the plane. I think you should ask another question about this. –  Tom Bombadil Jul 13 '12 at 16:02
add comment

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.