[Tex/LaTex] tikz-3dplot: Drawing an arc with the let syntax in 3d

3dtikz-pgf

How can I use the let syntax to draw an arc when using tikz-3dplot? At the present, the arc is drawn but doesn't look right.

\documentclass[tikz, convert = false]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc}
\begin{document}
\tdplotsetmaincoords{60}{130}
\begin{tikzpicture}[tdplot_main_coords]
  \coordinate (O) at (0, 0, 0);
  \node[coordinate] (P) at (3, 4, 5) {};

  \draw[-latex] (O) -- +(4, 0, 0) node[font = \small, pos = 1.1] {\(x\)}
  coordinate (X);

  \draw[dashed, gray] (P) -- +(0, 0, -5) coordinate (P1) -- (O);

  \draw[-latex] let
    \p0 = (O),
    \p1 = (X),
    \p2 = (P1),
    \n1 = {atan2(\x1 - \x0, \y1 - \y0)},
    \n2 = {atan2(\x2 - \x0, \y2 - \y0)},
    \n3 = {1cm},
    \n4 = {(\n1 + \n2) / 2}
  in (O) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2];
\end{tikzpicture}
\end{document}

enter image description here

Best Answer

This can now be solved with the combination of the arrows.meta and bending libraries of TikZ/pgf v3.0.0. Switch -latex to -Latex (the comparable arrows.meta variant). Loading bending automatically sets /pgf/arrow keys/flex=1, which is what's needed to make the arrowed path follow the non-arrowed path (red, dashed path in the sample) exactly.

I also had to swap the arguments of atan2 in your example for use with v3.0.0

\documentclass[tikz, convert = false]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,arrows.meta,bending}
\begin{document}
\tdplotsetmaincoords{60}{130}
\begin{tikzpicture}[tdplot_main_coords]
  \coordinate (O) at (0, 0, 0);
  \node[coordinate] (P) at (3, 4, 5) {};

  \draw[-latex] (O) -- +(4, 0, 0) node[font = \small, pos = 1.1] {\(x\)}
  coordinate (X);

  \draw[dashed, gray] (P) -- +(0, 0, -5) coordinate (P1) -- (O);

  \draw[-Latex] let
    \p0 = (O),
    \p1 = (X),
    \p2 = (P1),
    \n1 = {atan2(\y1 - \y0,\x1 - \x0)},
    \n2 = {atan2(\y2 - \y0,\x2 - \x0)},
    \n3 = {1cm},
    \n4 = {(\n1 + \n2) / 2}
  in (O) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2];
  \draw[red,dashed] let
    \p0 = (O),
    \p1 = (X),
    \p2 = (P1),
    \n1 = {atan2(\y1 - \y0,\x1 - \x0)},
    \n2 = {atan2(\y2 - \y0,\x2 - \x0)},
    \n3 = {1cm},
    \n4 = {(\n1 + \n2) / 2}
  in (O) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2];
\end{tikzpicture}
\end{document}

enter image description here