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!

1
  • Thank you guys, sorry for the duplicate, I did not see that post.
    – user154396
    Commented Feb 12, 2018 at 20:09

1 Answer 1

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.

8
  • 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
    Commented Feb 9, 2018 at 7:59
  • 1
    of course you can. now i see that my answer has problem with formatting of code. corrected now.
    – Zarko
    Commented Feb 9, 2018 at 9: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
    Commented Feb 9, 2018 at 9: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
    Commented Feb 9, 2018 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
    Commented Feb 9, 2018 at 17:14

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