3

I want to reproduce the following figure in TikZ:

enter image description here

The two vectors are $(-1/5, 2/5), (2/5, 1/5)$. Is there a way to have TikZ draw the dotted lines till the intersection with the thick outer box, and avoid having to actually calculate the intersection points and explicitly input the nodes? So far I have:

\begin{tikzpicture}
    \node (a) at (-1, 2) {};
    \node (b) at (2, 1) {};

    \draw [very thick] (-5, 0) -- (5, 0);
    \draw [very thick] (-5, -5) -- (5, -5);
    \draw [very thick] (-5, 5) -- (5, 5);

    \draw [very thick] (-5, -5) -- (-5, 5);
    \draw [very thick] (0, -5) -- (0, 5);
    \draw [very thick] (5, -5) -- (5, 5);

    \draw [very thick, ->] (0, 0) -- (a);
    \draw [very thick, ->] (0, 0) -- (b);

    \node[label=right:{$1$}] at (5,0) {};
    \node[label=above:{$1$}] at (0,5) {};
\end{tikzpicture}

which produces

enter image description here

1
4

Probably you'd get a better result using polar coordinates (and especially not using node to define points a and b, but coordinate instead).

tilted grid

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
    \begin{tikzpicture}
        
        \begin{scope}
            \clip (-5,-5) rectangle (5,5);
            \draw[rotate=30,dotted,orange,cap=round] (-10,-10) grid[step=2cm] (10,10);
        \end{scope}
        \coordinate (a) at (30:2) {};
        \coordinate (b) at (120:2) {};
    
        \draw [very thick]  (-5, -5) rectangle (5, 5)
                            (-5,0) -- (5,0) node[right] {$1$}
                            (0,-5) -- (0,5) node [above] {$1$};
    
        \draw [very thick, ->] (0, 0) -- (a);
        \draw [very thick, ->] (0, 0) -- (b);
    
    \end{tikzpicture}
\end{document}
2
  • The vectors are no longer at the coordinates given in the question. atan(1/2)=26.57° Sep 14 at 17:15
  • 1
    Yes, I know, and your version is more accurate on this point, but it was not clear if their coordinates were mandatory. The whole thing gives the idea.
    – SebGlav
    Sep 14 at 17:27
4

Here is a solution using grid:

\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (-1, 2);
\coordinate (b) at (2, 1);    
\draw [very thick, ->] (0, 0) -- (a);
\draw [very thick, ->] (0, 0) -- (b);
\node[label=right:{$(1,0)$}] at (5,0) {};
\node[label=above:{$(0,1)$}] at (0,5) {};
\draw[very thick, step=5] (-5,-5) grid (5,5);
\clip (-5,-5) rectangle (5,5);
\draw[dashed, very thick, step=sqrt(5), rotate=atan(1/2)] (-10,-10) grid (10,10);
\end{tikzpicture}
\end{document}

Rotated grid with two vectors

1
  • dashed can be replaced by dotted Sep 14 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.