7

I want to draw an angle between two vectors:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles,quotes,babel,plotmarks}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[decoration=brace]


% orthogonal ground line
\draw[thick] (-3,0) -- (3,0);

% Origin
\draw[fill=black] (0,0) node(O)[anchor=north] {$O$};

% vector a
\draw[thick,->] (0,0) -- (-2,2) node(a)[anchor=north east] {$a$};

% vector b
\draw[thick,->] (0,0) -- (2.5,1.5) node(b)[anchor=west] {$b$};


\pic [draw, -, angle eccentricity=1.2, angle radius=1cm,, "$\gamma$"] {angle=b--O--a};

\end{tikzpicture}
\end{document}

For some reasons the angle is draw a big bigger than expected?

enter image description here

Any advice how to do this correct?

1

3 Answers 3

7

The reason for this is that you wrongly define the coordinates for the angle. If you write \draw (0,0) -- (-2,2) node (a) [anchor=north east] {$a$};, then you define (a) as reference to the node for the label $a$, of which the center is, as you define it, north east to the coordinate (-2,2). But it is the coordinate (-2,2) that you actually need for the angle.

So, you should rather do:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}

\begin{document}
\begin{tikzpicture}

% orthogonal ground line
\draw[thick] (-3,0) -- (3,0);

% Origin
\draw[fill=black] (0,0) coordinate (O) node [anchor=north] {$O$};

% vector a
\draw[thick,->] (0,0) -- (-2,2) coordinate (a) node[anchor=north east] {$a$};

% vector b
\draw[thick,->] (0,0) -- (2.5,1.5) coordinate (b) node[anchor=west] {$b$};

\pic[draw, angle eccentricity=1.2, angle radius=1cm,, "$\gamma$"] {angle=b--O--a};

\end{tikzpicture}
\end{document}

As an alternative, you can use labels:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}

\begin{document}
\begin{tikzpicture}

% orthogonal ground line
\draw[thick] (-3,0) -- (3,0);

% Origin
\draw[fill=black] (0,0) coordinate[label={below:$0$}] (O);

% vector a
\draw[thick,->] (0,0) -- (-2,2) coordinate[label={below left:$a$}] (a);

% vector b
\draw[thick,->] (0,0) -- (2.5,1.5) coordinate[label={right:$b$}] (b);

\pic [draw, angle eccentricity=1.2, angle radius=1cm,, "$\gamma$"] {angle=b--O--a};

\end{tikzpicture}
\end{document}

enter image description here

5

This is very easy to do with pstricks – more specifically with pst-eucl:

    \documentclass[pstricks, border=6pt]{standalone}
    \usepackage{pst-eucl}

    \begin{document}

    \begin{pspicture}(-3,-1)(3,3)
    \psset{arrowinset=0.12,labelsep=3pt}
    \pstGeonode[PointSymbol=none, PosAngle={-90,135, 45}](0,0){O}(-2,2){a}(2.5,1.5){b}
    % orthogonal ground line
    \psline (-3,0)(3,0)
    \ncline{->}{O}{a}\ncline{->}{O}{b}
    \pstMarkAngle[linewidth=0.3pt, LabelSep=0.6]{b}{O}{a}{$\gamma$}%
    \end{pspicture}

    \end{document} 

enter image description here

2

The nodes are not at the endpoints, but something beside, you need to specify the coordinates like that

\begin{tikzpicture}[decoration=brace]
% orthogonal ground line
\draw[thick] (-3,0) -- (3,0);

% Origin
\coordinate (O) at (0,0);
\draw[fill=black] (O) node[anchor=north] {$O$};

% vector a
\coordinate (a) at (-2,2);
\draw[thick,->] (O) -- (a) node[anchor=south east] {$a$};

% vector b
\coordinate (b) at (2.5,1.5);
\draw[thick,->] (O) -- (b) node[anchor=south west] {$b$};

\pic [draw, -, angle eccentricity=1.2, angle radius=1cm,, "$\gamma$"] {angle=b--O--a};
\end{tikzpicture}
1
  • Yes, this is also a possible approach! +1 Please consider to extend this code snippet to a full MWE including a \documentclass. Commented Oct 12, 2022 at 14:44

You must log in to answer this question.

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