# How can I draw a vector diagram that illustrates polar and rectangular coordinates using TikZ?

I was wondering how I can modify the code below so that I get this picture. I'm trying to put together different concepts with the angles, arrows and elements in the diagonal. Any help is very much appreciated.

   \documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=1.25]
\coordinate (A) at (-1.5cm,-1.cm);
\coordinate (C) at (1.5cm,-1.0cm);
\coordinate (B) at (1.5cm,1.0cm);
\draw (A) -- node[below] {$E_{k}$} (B) -- node[right] {$f_{k}$} (C) -- node[below] {$e_{k}$} (A);
\end{tikzpicture}
\end{figure}
\end{document}

• Different coordinate systems are describe in TikZ manual, in paragraph 13 Specifying Coordinates (p129). For example, polar coordinates you can define as (<angle>: distance) . Commented Aug 15, 2016 at 17:56

## 2 Answers

A short exercise from geometry and drawing with TikZ :-) :

    \documentclass[tikz,
border=3mm]{standalone}
\usetikzlibrary{angles, arrows.meta, quotes}

\begin{document}
\centering
% added labels of vertex
\begin{tikzpicture}[scale=1.25]
\coordinate[label=below  left:A] (A) at (-1.5cm,-1.cm);
\coordinate[label=below right:C] (C) at ( 1.5cm,-1.0cm);
\coordinate[label=above right:B] (B) at ( 1.5cm, 1.0cm);
\draw[-Stealth]  (A) edge ["$E_{k}$" '] (B)
(A) edge ["$f_{k}$" '] (C)
(C)  to  ["$e_{k}$" '] (B);
\end{tikzpicture}

% slightly improved your MWE, by use package "quotes"
\begin{tikzpicture}[scale=1.25]
\coordinate[label=below  left:A] (A) at (-1.5cm,-1.cm);
\coordinate[label=below right:C] (C) at ( 1.5cm,-1.0cm);
\coordinate[label=above right:B] (B) at ( 1.5cm, 1.0cm);
\draw[-Stealth]  (A) edge ["$E_{k}$",sloped] (B)
(A) edge ["$f_{k}$" '] (C)
(C)  to  ["$e_{k}$" '] (B);
\end{tikzpicture}

% coordinates and vectors determined by polar coordinates
\begin{tikzpicture}[scale=1.25]
\coordinate[label=below  left:A] (A) at (-1.5cm,-1.cm);
\draw[-Stealth]
(A) to ["$E_{k}$",sloped] ++ ({atan(2/3)}:{sqrt(4+9)}) coordinate[label=above right:B] (B);
\draw[-Stealth]
(A) to ["$f_{k}$" ']      ++ (0:3)           coordinate[label=below right:C] (C);
\draw[-Stealth]
(C) to ["$e_{k}$" ']      ++ (90:2);
\end{tikzpicture}

% added angle label by help of package "angle"
\begin{tikzpicture}[scale=1.25]
\coordinate[label=below  left:A] (A) at (-1.5cm,-1.cm);
\draw[-Stealth]
(A) to ["$E_{k}$",sloped] ++ ({atan(2/3)}:{sqrt(4+9)})  coordinate[label=above right:B] (B);
\draw[-Stealth]
(A) to ["$f_{k}$" ']      ++ (0:3)                      coordinate[label=below right:C] (C);
\draw[-Stealth]
(C) to ["$e_{k}$" ']      ++ (90:2);
\pic ["$\angle\theta_i$", draw, angle radius = 12mm, angle eccentricity=1.3]
{angle = C--A--B};
\end{tikzpicture}

% added measure of magnitude
\begin{tikzpicture}[scale=1.25]
\coordinate[label=below  left:A] (A) at (-1.5cm,-1.cm);
% vector from A in direction of angle "atan(2/3)" (arcus tangens"
% and magnitude "sgrt(2^2+2^2)" (square root)
% end of vector determine coordinate B, which is labeled with "B" north east from it (above right)
\draw[-Stealth]
(A) to ["$\hat{V}_i$" '] ++ ({atan(2/3)}:{sqrt(4+9)})  coordinate[label=above right:B] (B);
\draw[-Stealth]
(A) to ["$f_{k}$" ']     ++ (0:3)                      coordinate[label=below right:C] (C);
\draw[-Stealth]
(C) to ["$e_{k}$" ']     ++ (90:2);
% angle
% drawn with syntax provided by package "angles",
% angles eccentricity determine label position
% B--A--C is outer angle, C--A--B inner (sharp) angle
\pic ["$\angle\theta_i$", draw, angle radius = 12mm, angle eccentricity=1.3]
{angle = C--A--B};
% magnitude
% starting point of magnitude measure is determined by perpendicular distance of 3mm
% from coordinate A calculated by "($(A)!3mm!90:(B)$)";
% end point is determined with adding of vector magnitude and angle: "({atan(2/3)}:{sqrt(4+9)})"

\draw[{Bar[width=3.4mm]Straight Barb[]}-{Straight Barb[]Bar[width=3.4mm]}]
($(A)!3mm!90:(B)$) to ["$\vert\hat{V}_i\vert$",sloped] + ({atan(2/3)}:{sqrt(4+9)});
\end{tikzpicture}
\end{document}


Image below are from example 1, 2--3, 4 and 5 examples in MWE.

• Thank you again, @Zarko. You nailed it. Looks great. I was just wondering how to add the diagonal rule above Ek with the magnitude. Commented Aug 15, 2016 at 18:59
• Well, I will add it soon. For it the library calc is necessary. Commented Aug 15, 2016 at 19:04
• Amazing, @Zarko. I wish I could go to the same TikZ school that you attended - the code is simply cryptic if we have no understanding of the underlying logic. Thank you very much, once again. Commented Aug 15, 2016 at 19:45
• @LeonardoMartins, I add some comments to code of the last example, Hopefully they will help to understand, what some commands and macros do in code. Commented Aug 15, 2016 at 20:25

Because you mentioned in your comment that the TikZ solution seems cryptic, I thought I'd give you an Asymptote solution. The Asymptote language has many commonalities with C++, making it much less cryptic for me.

include markers; // provides the markangle function

unitsize(2cm);

// define vertices
pair A = (-1.5,-1.0);
pair B = ( 1.5,-1.0);
pair C = ( 1.5, 1.0);

// draw and label triangle sides
draw(Label("$e_i$"), A--B, Arrow(HookHead));
draw(Label("$\hat{V}_i$"), A--C, Arrow(HookHead));
draw(Label("$f_i$"), B--C, Arrow(HookHead));

// define, draw, and label offset hypotenuse
real pathAngle = degrees(C-A);
path offsetPath = shift(rotate(pathAngle)*(0,0.2))*(A--C);
draw(Label(rotate(pathAngle)*"$\left|\hat{V}_i\right|$"), offsetPath, NW, Bars);

// draw and label the angle
markangle("$\angle\theta_i$", 50.0, B, A, C);

// label vertices
label("A", A, S);
label("B", B, S);
label("C", C, E);


• thank you very much for this excellent idea. I very much enjoyed this Asymptote syntax. I will learn more about it. Commented Aug 22, 2016 at 17:01