3

I'm new to tikz and LaTeX in general, so sorry if this is a silly question. I'm looking to replicate this:

lina

So far, I have the following.

\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]
    % Axes
    \draw [->] (0,0,0) -- (4,0,0) node [at end, right] {$x$};
    \draw [->] (0,0,0) -- (0,4,0) node [at end, left] {$y$};
    \draw [->] (0,0,0) -- (0,0,4) node [at end, left] {$z$};

    % Vectors
    \draw [->, thick] (0,0,0) -- (0,2,1);
    \draw [->, thick] (0,0,0) -- (2,2,0);

    \draw [loosely dashed] (0,0,1) -- (0,2,1);
    \draw [loosely dashed] (0,2,0) -- (0,2,1);
    \draw [loosely dashed] (2,0,0) -- (2,2,0);
    \draw [loosely dashed] (0,2,0) -- (2,2,0);

    % Labels
    \node [left] at (0,2,1) {$\begin{bmatrix}
                               0\\2\\1
                              \end{bmatrix}$};
    \node [right] at (2,2,0) {$\begin{bmatrix}
                                2\\2\\0
                               \end{bmatrix}$};

\end{tikzpicture}

enter image description here

It is missing the axis ticks and the orientation of the axes is different from the picture (although I guess mathematically it doesn't make too big of a difference). I've been reading the pgf manual and been looking through the forum, but I'm still stumped!

jGaboardi
  • 502
user154396
  • 33
  • 1
  • 4

1 Answers1

6

solution with pure tikz:

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}[x=1cm, y=1cm, z=-0.6cm]
    % Axes
    \draw [->] (0,0,0) -- (4,0,0) node [right] {$x$};
    \draw [->] (0,0,0) -- (0,4,0) node [left] {$y$};
    \draw [->] (0,0,0) -- (0,0,4) node [left] {$z$};
    % Vectors
    \draw [->, thick] (0,0,0) -- (2,2,0);
    \draw [->, thick] (0,0,0) -- (2,0,1);
    % Ticks
        \foreach \i in {1,2}
    {
    \draw (-0.1,\i,0) -- ++ (0.2,0,0);
    \draw (\i,-0.1,0) -- ++ (0,0.2,0);
    \draw (-0.1,0,\i) -- ++ (0.2,0,0);
    }
    % Dashed lines
    \draw [loosely dashed]
        (0,2,0) -- (2,2,0) -- (2,0,0)
        (0,0,1) -- (2,0,1) -- (2,0,0)
        ;
    % Labels
     \node [right] at (2,2,0) {$\begin{bmatrix}
                                2\\2\\0
                               \end{bmatrix}$};
   \node [below] at (2,0,1) {$\begin{bmatrix}
                               2\\0\\1
                              \end{bmatrix}$};

\end{tikzpicture}
\end{document}

gives:

enter image description here

addendum: solution with use of package tikz-3dplot:

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{tikz-3dplot}
\usepackage{amsmath}

\begin{document}
\tdplotsetmaincoords{60}{120}
\begin{tikzpicture}[tdplot_main_coords]
% Axes
\draw [->] (0,0,0) -- (3,0,0) node [below left] {$x$};
\draw [->] (0,0,0) -- (0,3,0) node [right] {$y$};
\draw [->] (0,0,0) -- (0,0,3) node [above] {$z$};
% Vectors
\draw [->, thick] (0,0,0) -- (2,2,0);
\draw [->, thick] (0,0,0) -- (2,0,1);
% Ticks
    \foreach \i in {1,2}
{
\draw (-0.1,\i,0) -- ++ (0.2,0,0);
\draw (\i,-0.1,0) -- ++ (0,0.2,0);
\draw (-0.1,0,\i) -- ++ (0.2,0,0);
}
% Dashed lines
\draw [loosely dashed]
    (0,2,0) -- (2,2,0) -- (2,0,0)
    (0,0,1) -- (2,0,1) -- (2,0,0)
    ;
% Labels
 \node [below right] at (2,2,0) {$\begin{bmatrix}
                                    2\\2\\0
                                \end{bmatrix}$};
 \node [above  left] at (2,0,1) {$\begin{bmatrix}
                                    2\\0\\1
                                \end{bmatrix}$};
\end{tikzpicture}
\end{document}

which gives:

enter image description here

i'm not familiar with tikz-3dpackage so for other projection of 3d-space you need ask new question.

Zarko
  • 296,517
  • 1
    Kind Zarko I do not allow myself to edit a very good user's answer. There is a part of incomplete code. Hi. – Sebastiano Feb 09 '18 at 07:59
  • 1
    of course you can. now i see that my answer has problem with formatting of code. corrected now. – Zarko Feb 09 '18 at 09:56
  • 1
    +1. For me it is a sign of respect for the best users. The vice versa is right that it is so. :-) – Sebastiano Feb 09 '18 at 09:58
  • 1
    @Zarko: Your code is fine! Could you tell me how to get another view of axes, like \tdplotsetmaincoords{60}{120} in tikz-3dplot? More precisely, i want to keep using your code, but vertical axis is Oz, horizontal axis is Oy. – Black Mild Feb 09 '18 at 15:15
  • 1
    see edited answer. however, the simplest way, what you like to obtain, is rename base vectors: x,y,z --> z',y,x'. by this you also need in mind that the transformation matrix is changed to ... – Zarko Feb 09 '18 at 17:14
  • 1
    @Zarko Thank you for your help, great answer. As a follow-up, if it's not a hassle, is there a big difference between using pure tikz vs tikz-3dplot? Is one better than the other? – user154396 Feb 12 '18 at 20:08
  • 1
    @Ions, i can't say this because i used tikz-3dplot first time in my above, but `tikz I use the from its very beginning. if you have a lot 3d images it is worth to familiarize with it. btw, if answer help you, you can accept it (by clicking check mark at top left side of answer) :). – Zarko Feb 12 '18 at 20:39
  • 1
    @Zarko Just accepted it. Once again, thanks for your help :-) – user154396 Feb 12 '18 at 20:47