3

I have drawn the following 3D shape in tikz.

\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pgf,tikz}
\usepackage{tkz-tab}
 \usetikzlibrary{shapes,snakes,arrows,backgrounds}
\usetikzlibrary{scopes,svg.path,shapes.geometric,shadows}
\usepackage{graphicx}
\usepackage{xcolor} 
\begin{document}
\begin{tikzpicture}[xscale=1.5, yscale=1.5]

\draw [->](0,0,0) -- (3,0,0) node[anchor=west]{$y$};
\draw [->, dashed](0,0,0) -- (0,3,0) node[anchor=west]{$z$};
\draw [->](0,0,0) -- (0,0,3) node[anchor=west]{$x$};
\draw [thick](1, 0, 0)--(0, 1, 0) -- (0, 0, 1)--(1, 0, 0);
\fill [blue!50!gray!30] (1, 0, 0)--(0, 1, 0) -- (0, 0, 1)--(1, 0, 0);
\draw (1, 0, 0) node[below] {$1$};
\draw (0, 1, 0) node[left] {$1$};
\draw (0, 0, 1) node[below] {$1$};
\end{tikzpicture}
\end{document}

How can I rotate the shape to the right so that I have a better view of the axis? I have read similar questions here but I cannot figure it out. Most of them rotate the axis but not the triangle . I have also seen the 3D plot package but for I don't have it installed so I can't use it.

2 Answers 2

5

You can rotate the entire tikzpicture environment by adding rotate=<angle> as an argument to the environment:

\begin{tikzpicture}[xscale=1.5, yscale=1.5,rotate=45]

However, I don't think that this makes the axes any easier to see. I think that what you want to do is to draw the triangle first and then draw the axes "over" the top of the triangle so that the image becomes:

enter image description here

All that I have done is rearrange your code (so no rotation):

\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{pgf,tikz}
\usepackage{tkz-tab}
 \usetikzlibrary{shapes,snakes,arrows,backgrounds}
\usetikzlibrary{scopes,svg.path,shapes.geometric,shadows}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}[xscale=1.5, yscale=1.5]
  \fill [blue!50!gray!30] (1, 0, 0)--(0, 1, 0) -- (0, 0, 1)--(1, 0, 0);
  \draw [->](0,0,0) -- (3,0,0) node[anchor=west]{$y$};
  \draw [->, dashed](0,0,0) -- (0,3,0) node[anchor=west]{$z$};
  \draw [->](0,0,0) -- (0,0,3) node[anchor=west]{$x$};
  \draw [thick](1, 0, 0)--(0, 1, 0) -- (0, 0, 1)--(1, 0, 0);
  \draw (1, 0, 0) node[below] {$1$};
  \draw (0, 1, 0) node[left] {$1$};
  \draw (0, 0, 1) node[below] {$1$};
\end{tikzpicture}

\end{document}

This said, you can also simplify your code slightly and write:

\begin{tikzpicture}[xscale=1.5, yscale=1.5]
  \draw[thick,fill=blue!50!gray!30] (1, 0, 0)node[below right]{$1$}
                 --(0, 1, 0)node[above left]{$1$} 
                 --(0, 0, 1)node[below right]{$1$}--cycle;
  \draw [->](0,0,0) -- (3,0,0) node[anchor=west]{$y$};
  \draw [->, dashed](0,0,0) -- (0,3,0) node[anchor=west]{$z$};
  \draw [->](0,0,0) -- (0,0,3) node[anchor=west]{$x$};
\end{tikzpicture}

to obtain almost identical output (the 1s move slightly).

1
  • Thank you. Hmm I just played around with the code this evening and I add the command \fill[capacity=0.6] in order to get the shape you added in your answer. Then I dashed the axes behind the triangle and left the other shape unattached. Thank you for your answer.
    – Tolaso
    May 26, 2015 at 13:59
5

To do a rotation about the y axis you can use rotate around y=<degrees>. In the MWE below I used rotate around y=50 to achieve:

enter image description here

Notes:

  • I relabelled the axis to use more standard (x,y,z) which also explains why a rotation around the y axis is needed.
  • No need for a \draw when you just want a \node.
  • The join=round makes the corners smoother.

Code:

\documentclass[10pt]{article}
\usepackage{tikz}
\usepackage{xcolor} 

\begin{document}
\begin{tikzpicture}[xscale=1.5, yscale=1.5, join=round, rotate around y=50]

\draw [->](0,0,0) -- (3,0,0) node[anchor=west]{$x$};
\draw [->, dashed](0,0,0) -- (0,3,0) node[anchor=west]{$y$};
\draw [->](0,0,0) -- (0,0,3) node[anchor=west]{$z$};

\draw [thick](1, 0, 0)--(0, 1, 0) -- (0, 0, 1)--(1, 0, 0);
\fill [blue!50!gray!30] (1, 0, 0)--(0, 1, 0) -- (0, 0, 1)--(1, 0, 0);

\node[below] at (1, 0, 0) {$1$};% <--- simplified
\node[left]  at (0, 1, 0) {$1$};% <--- simplified
\node[below] at (0, 0, 1) {$1$};% <--- simplified

%% since we can now see the y-z axis
\fill [blue!50!gray!30] (0, 0, 0) -- (0, 1, 0) -- (0, 0, 1)-- cycle;
\draw (0,0,0) -- (0, 1, 0) -- (0,0,1) -- cycle;
\end{tikzpicture}%
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .