# TikZ angle arithmetic

I'm running into a problem when trying to draw vector components in a TikZ picture. I want to be able to have TikZ do the following: 1) Draw a line of length 4 at 0 degrees 2) Draw a line from (4,0) of length 3 at 90 degrees 3) Draw the hypotenuse from (4,3) of length 5 at 210 degrees

However, when using coordinate arithmetic and angles in TikZ, I can't get the hypotenuse right. Here is a minimal working example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\draw (0,0) coordinate (a);
\draw (a) -- ($(a)+(0:4)$) coordinate (b);
\draw (b) -- ($(b)+(90:3)$) coordinate (c);
\draw (c) -- ($(c)+(210:5)$);
\end{tikzpicture}

\end{document}


This produces:

I've been trying to find a solution and run out of ideas. Any help (including the pointing out of boneheaded mistakes) would be greatly appreciated.

Cheers, JLusk

• The final angle is not 210. – Gonzalo Medina Feb 18 '15 at 3:04

The problem is that the final angle is not 210; either use the appropriate value atan(3/4)+180 or use cycle (or (a) since you already named the initial coordinate); notice also that you can use just one \draw and the the use of ++ simplifies your code (no need for the calc library):

\documentclass{article}
\usepackage{tikz}

\begin{document}

\noindent
\begin{tikzpicture}
\draw (0,0) coordinate (a) --
++(0:4) coordinate (b) --
++(90:3) coordinate (c) --
++({atan(3/4)+180}:5);
\end{tikzpicture}\bigskip

\noindent
\begin{tikzpicture}
\draw (0,0) coordinate (a) --
++(0:4) coordinate (b) --
++(90:3) coordinate (c) --
cycle;
\end{tikzpicture}

\end{document}


If you insist on four separate operations, you can do

\begin{tikzpicture}
\coordinate (a) at (0,0);
\draw (a) -- +(0:4) coordinate (b);
\draw (b) -- +(90:3) coordinate (c);
\draw (c) -- +({atan(3/4)+180}:5);
\end{tikzpicture}


or simply

\begin{tikzpicture}
\coordinate (a) at (0,0);
\draw (a) -- +(0:4) coordinate (b);
\draw (b) -- +(90:3) coordinate (c);
\draw (c) -- (a);
\end{tikzpicture}


both options still without calc.

• Thanks for the help! In my head, a 3:4:5 triangle was a 30-60-90 triangle. There is no rational reason why I thought this, but there you go. – JLusk Feb 18 '15 at 4:07