5

Here is a MWE:

\documentclass[10pt,a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{angles}

\begin{document}

\begin{tikzpicture}
  \coordinate (ey) at (1,0,0);
  \coordinate (ez) at (0,1,0);
  \coordinate (ex) at (0,0,1);
  \begin{scope}[x={(ex)},y={(ey)},z={(ez)},scale=2]

  \def\xM{1.2}
  \def\yM{1.6}
  \def\zM{1.8}
  \def\ech{2}
  
  \coordinate (O) at (0,0,0);
  \coordinate (X) at (\ech,0,0);
  \coordinate (Y) at (0,\ech,0);
  \coordinate (Z) at (0,0,\ech);
  \coordinate (Px) at (\xM,0,0);
  \coordinate (Py) at (0,\yM,0);
  \coordinate (Pz) at (0,0,\zM);
  \coordinate (M) at (\xM,\yM,\zM);
  \coordinate (H) at (\xM,\yM,0); 
  \coordinate (ey) at (1,0,0);
  \coordinate (ez) at (0,1,0);
  \coordinate (ex) at (0,0,1);
  
  \draw[->,thick] (0,0,0) -- (1,0,0) node[above left] {$\vec{\imath}$};
  \draw[->,thick] (0,0,0) -- (0,1,0) node[below] {$\vec{\jmath}$};
  \draw[->,thick] (0,0,0) -- (0,0,1) node[left] {$\vec{k}$};
    \draw (O) -- (X);
    \draw (O) -- (Y);
    \draw (O) -- (Z);
    \draw[dashed] (H) -- (Px) node[left] {$x$};
    \draw[dashed] (H) -- (Py) node[above] {$y$};
    \draw[dashed] (H) -- (Py);
    \draw[->,blue] (O) -- (H);
    \draw[blue] (M) -- node[right,black] {$z$} (H);
    \draw[blue] (M) -- node[above,black] {$r$} (Pz);
    
    \path (H) node[below right] {$H$};
    \path (M) node[above right] {$M$};
    \draw pic [draw,->,angle radius=0.5cm] {angle = X--O--H};
    \draw (23:1) node {$\theta$};
    \end{scope}
\end{tikzpicture}

\end{document}

And here is the result: enter image description here

I am not satisfied with the angle theta. It doesn't seem in the plane (Oxy). Probably because it is a circle instead of an ellipse (I hope I am clear). So is there a way to improve this?

1 Answer 1

6

You can use the 3d library and the option

canvas is xy plane at z=0

that draws precisely in the horizontal plane.

If you want another suggestion I'd use the quotes library too, this way you can specify the angle label as \draw option.

Something like this:

\documentclass[10pt,a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{3d,     % for 'canvas is ... plane at ...' options
                angles,
                quotes} % angle labels

\begin{document}

\begin{tikzpicture}
  \coordinate (ey) at (1,0,0);
  \coordinate (ez) at (0,1,0);
  \coordinate (ex) at (0,0,1);
  \begin{scope}[x={(ex)},y={(ey)},z={(ez)},scale=2]

  \def\xM{1.2}
  \def\yM{1.6}
  \def\zM{1.8}
  \def\ech{2}

  \coordinate (O) at (0,0,0);
  \coordinate (X) at (\ech,0,0);
  \coordinate (Y) at (0,\ech,0);
  \coordinate (Z) at (0,0,\ech);
  \coordinate (Px) at (\xM,0,0);
  \coordinate (Py) at (0,\yM,0);
  \coordinate (Pz) at (0,0,\zM);
  \coordinate (M) at (\xM,\yM,\zM);
  \coordinate (H) at (\xM,\yM,0);
  \coordinate (ey) at (1,0,0);
  \coordinate (ez) at (0,1,0);
  \coordinate (ex) at (0,0,1);

  \draw[->,thick] (0,0,0) -- (1,0,0) node[above left] {$\vec{\imath}$};
  \draw[->,thick] (0,0,0) -- (0,1,0) node[above] {$\vec{\jmath}$};
  \draw[->,thick] (0,0,0) -- (0,0,1) node[left] {$\vec{k}$};
    \draw (O) -- (X);
    \draw (O) -- (Y);
    \draw (O) -- (Z);
    \draw[dashed] (H) -- (Px) node[left] {$x$};
    \draw[dashed] (H) -- (Py) node[above] {$y$};
    \draw[dashed] (H) -- (Py);
    \draw[->,blue] (O) -- (H);
    \draw[blue] (M) -- node[right,black] {$z$} (H);
    \draw[blue] (M) -- node[above,black] {$r$} (Pz);

    \path (H) node[below right] {$H$};
    \path (M) node[above right] {$M$};
    \draw pic [canvas is xy plane at z=0,% draws in the xy plane
               draw=red,->,angle radius=0.75cm,
               "$\theta$",               % angle label (requires quotes library)
               angle eccentricity=1.6    % angle position
              ] {angle = X--O--H};
    \pgfmathsetmacro\angletheta{atan(\yM/\xM)} % rotation angle for OHM plane (theta)
    \draw pic [rotate around z=\angletheta,canvas is xz plane at y=0,% draws in the OHM plane
               draw=red,<-,angle radius=0.75cm,
               "$\varphi$",              % angle label (requires quotes library)
                angle eccentricity=0.7   % angle position
               ] {angle = M--H--O};
    %\draw (23:1) node {$\theta$};
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

12
  • Thank you @Juan. It's brilliant. So I have another question: is it possible to specify any plane? For instance, if I want an angle in the plane (OHM)?
    – Didier
    Jun 7 at 10:31
  • 1
    @Didier, yes, it's possible. You need to compute the angle theta, and then rotate the axes accordingly. See my edit Jun 7 at 10:53
  • Sorry, another question. Is there a way to definitely exchange x,y,z for a 3D figure (I have to do it for each figure, with a scope ...). Maybe with a tikset in the preamble?
    – Didier
    Jun 7 at 11:26
  • Thank you @Juan. I hadn’t seen your answer for my first question. And for my second question, I forgot to say that, of course, I don’t want this exchange to modify my 2D figures
    – Didier
    Jun 7 at 11:50
  • 1
    Thank you @Juan. I will look at that
    – Didier
    Jun 7 at 18:55

You must log in to answer this question.

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