# Using vectors in TikZ?

Is there a way to define vectors in TikZ? By that I mean the ability to add and scalar multiply coordinate tuples, for example for drawing a parallelogram:

% Just pseudocode:
P := (0,1);
Q := (1,1);
\draw[-] (0,0) -- P -- (P+Q) -- Q -- (0,0);


Coordinates are already some kind of vectors. Library calc provides the addition of coordinates:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\tikz\draw
(0, 1) coordinate (P)
(1, 1) coordinate (Q)
(0, 0) -- (P) -- ($(P) + (Q)$) -- (Q) -- cycle
;
\end{document}


BTW: Closed paths should use cycle to get a proper line join at the starting point.

• Thank you very much, that is an excellent answer! Also thanks for the cycle hint! – flawr Oct 26 '16 at 21:19
• A follow up question: Is there some way to use the defined P and Q in more than one (that particular) \draw command? – flawr Oct 26 '16 at 21:56
• @flawr For more than one \draw command, use environment use environment tikzpicture. – Heiko Oberdiek Oct 27 '16 at 4:36