[Tex/LaTex] TiKz. Angle between two vectors and a projection

3dtikz-3dplottikz-pgfvector

I'm having trouble to draw something with TiKz. What I want to draw I think is simple:
The graph

SIM is a vector in the YZ-plane with a Beta = 38ยบ, source is just a random vector with positive x and y components and negative z. Theta is the angle between SIM and source vectors and Phi is the angle formed by the source projection in the XZ-plane with the X-axis.

Thanks a lot in advance

Best Answer

Here is a tikz-3dplot approach. The arcs are drawn using:

% define three points
\tdplotdefinepoints(vx, vy, vz)(ax, ay, az)(bx, by, bz)
% draw arc using the three points and a radius
\tdplotdrawpolytopearc[draw style]{r}{label options}{label}

The viewpoint can be modified using:

\tdplotsetmaincoords{rotation around x}{rotation around z}

The x-axis and z-axis can be exchanged using:

\let\raarotold\raarot \let\rbarotold\rbarot
\let\rabrotold\rabrot \let\rbbrotold\rbbrot
\let\racrotold\racrot \let\rbcrotold\rbcrot

\let\raarot\racrotold \let\rbarot\rbcrotold
\let\rabrot\rabrotold \let\rbbrot\rbbrotold
\let\racrot\raarotold \let\rbcrot\rbarotold

Note: The -z-axis in the following picture is actually the z-axis. I have just changed the label.

See Symbol 1's answer here for details about coordinate system customization.

tikz-3dplot - angle between vectors

\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}

\begin{document}
\tdplotsetmaincoords{60}{120}

% customized coordinate system
\let\raarotold\raarot \let\rbarotold\rbarot
\let\rabrotold\rabrot \let\rbbrotold\rbbrot
\let\racrotold\racrot \let\rbcrotold\rbcrot

\let\raarot\racrotold \let\rbarot\rbcrotold
\let\rabrot\rabrotold \let\rbbrot\rbbrotold
\let\racrot\raarotold \let\rbcrot\rbarotold

\begin{tikzpicture}[tdplot_main_coords]

  % axes
  \draw[thick,->] (0,0,0) -- ( 7,0,0) node[anchor=south]{$x$};
  \draw[thick,->] (0,0,0) -- ( 0,7,0) node[anchor=west]{$y$};
  \draw[thick,->] (0,0,0) -- ( 0,0,7) node[anchor=north east]{$-z$};  
  \draw[thick]    (0,0,0) -- ( 0,-2,0);
  \draw[thick,->] (0,0,0) -- ( 0,0,-7) node[anchor=south west]{$z$};

  % vector 1
  \pgfmathsetmacro{\ax}{5}
  \pgfmathsetmacro{\ay}{5}
  \pgfmathsetmacro{\az}{2}
  \draw[very thick,->,red] (0,0,0) -- (\ax,\ay,\az) node[anchor=west]{source};

   % vector 2
  \pgfmathsetmacro{\bx}{0}
  \pgfmathsetmacro{\by}{3}
  \pgfmathsetmacro{\bz}{4}
  \draw[very thick,->,blue] (0,0,0) -- (\bx,\by,\bz) node[anchor=north]{sim};

   % vector 3 (projection)
  \pgfmathsetmacro{\cx}{\ax*1.2}
  \pgfmathsetmacro{\cy}{0}
  \pgfmathsetmacro{\cz}{\az*1.2}
  \draw[very thick,green] (0,0,0) -- (\cx,\cy,\cz);

   % dashed lines
%  \draw[dashed,gray] (\ax,\ay,\az) -- (\ax,\ay,0);
  \draw[dashed,gray] (\ax,\ay,\az) -- (\ax,0,\az);
  \draw[dashed,gray] (\ax,\ay,\az) -- (0,\ay,\az);
%  \draw[dashed,gray] (\ax,0,0) -- (\ax,\ay,0) -- (0,\ay,0);
  \draw[dashed,gray] (\ax,0,0) -- (\ax,0,\az) -- (0,0,\az);
  \draw[dashed,gray] (0,0,\az) -- (0,\ay,\az) -- (0,\ay,0);

  % arcs
  \tdplotdefinepoints(0,0,0)(\ax,\ay,\az)(\bx,\by,\bz)
  \tdplotdrawpolytopearc[<->]{2}{anchor=north west}{$\theta$}
  \tdplotdefinepoints(0,0,0)(0,0,1)(\bx,\by,\bz)
  \tdplotdrawpolytopearc[<->]{3}{anchor=north}{$\beta$}
  \tdplotdefinepoints(0,0,0)(1,0,0)(\cx,\cy,\cz)
  \tdplotdrawpolytopearc[<->]{4}{anchor=north}{$\phi$}

\end{tikzpicture}
\end{document}
Related Question