4

I recently discovered the angles TikZ library which is very convenient when one needs to annotate angles.

I encountered a problem when I tried to use it in with the 3d library, since the arc is drawn without using the defined canvas plane. Here is an illustration (the alpha angle should be plotted as the green arc):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes,3d}

\begin{document}
\begin{tikzpicture}
    \draw[blue,->] (0,0)coordinate(O) --  (1,0,0)node[below right]{$\vec{x}$};
    \draw[blue,->] (O) --  (0,1)node[above]{$\vec{y}$};    
    \draw (2,0) coordinate (A) -- (0,0) coordinate (B) -- (1,1) coordinate (C);
    \draw[red] pic ["$\alpha$", draw, ->] {angle};
\end{tikzpicture}

\def\w{40} \def\aa{30}
\begin{tikzpicture}[x={({cos(\w)*1cm},{-sin(\w)*sin(\aa)*1cm})},
        y={({sin(\w)*1cm},{cos(\w)*sin(\aa)*1cm})},
        z={(0,{cos(\aa)*1cm})}]
    \draw[blue,->] (0,0,0)coordinate(O) --  (1,0,0)node[below right]{$\vec{x}$};
    \draw[blue,->] (O) --  (0,1,0)node[above]{$\vec{y}$};    
    \draw[blue,->] (O) --  (0,0,1)node[above]{$\vec{z}$};

    \begin{scope}[canvas is xy plane at z=0]
        \draw[dashed] (0,0) circle (1);
        \draw (2,0) coordinate (A) -- (0,0) coordinate (B) -- (1,1) coordinate (C);
        \draw[red] pic ["$\alpha$", draw, ->] {angle}; % incorrect
        \draw[green] (0:0.6) arc (0:45:0.6); % correct 
    \end{scope}

\end{tikzpicture}
\end{document}

exemple Is there a simple hack to have it work correctly?

Note that there is no problem with the right angle command, since the plot consist in parallel segments.

Tobard
  • 1,189
  • Use tikz-3dplot for angles in three dimensions. – Henri Menke Jun 02 '20 at 10:25
  • 1
    @HenriMenke transform shape is sufficient. Internally tikz-3dplot also does nothing but drawing arcs. You only have to make sure the angle pic knows which coordinate system to use. –  Jun 02 '20 at 10:58

1 Answers1

6

Use transform shape.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes,3d}

\begin{document}
\begin{tikzpicture}
    \draw[blue,->] (0,0)coordinate(O) --  (1,0,0)node[below right]{$\vec{x}$};
    \draw[blue,->] (O) --  (0,1)node[above]{$\vec{y}$};    
    \draw (2,0) coordinate (A) -- (0,0) coordinate (B) -- (1,1) coordinate (C);
    \draw[red] pic ["$\alpha$", draw, ->] {angle};
\end{tikzpicture}

\def\w{40} \def\aa{30}
\begin{tikzpicture}[x={({cos(\w)*1cm},{-sin(\w)*sin(\aa)*1cm})},
        y={({sin(\w)*1cm},{cos(\w)*sin(\aa)*1cm})},
        z={(0,{cos(\aa)*1cm})}]
    \draw[blue,->] (0,0,0)coordinate(O) --  (1,0,0)node[below right]{$\vec{x}$};
    \draw[blue,->] (O) --  (0,1,0)node[above]{$\vec{y}$};    
    \draw[blue,->] (O) --  (0,0,1)node[above]{$\vec{z}$};

    \begin{scope}[canvas is xy plane at z=0]
        \draw[dashed] (0,0) circle (1);
        \draw (2,0) coordinate (A) -- (0,0) coordinate (B) -- (1,1) coordinate (C);
        \draw[red] pic ["$\alpha$", draw, ->,transform shape] {angle}; % correct
        \draw[green] (0:0.6) arc (0:45:0.6); % correct 
    \end{scope}

\end{tikzpicture}
\end{document}

enter image description here

You may also transform the angle arc but not the text.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes,3d}

\begin{document}
\begin{tikzpicture}
    \draw[blue,->] (0,0)coordinate(O) --  (1,0,0)node[below right]{$\vec{x}$};
    \draw[blue,->] (O) --  (0,1)node[above]{$\vec{y}$};    
    \draw (2,0) coordinate (A) -- (0,0) coordinate (B) -- (1,1) coordinate (C);
    \draw[red] pic ["$\alpha$", draw, ->] {angle};
\end{tikzpicture}

\def\w{40} \def\aa{30}
\begin{tikzpicture}[x={({cos(\w)*1cm},{-sin(\w)*sin(\aa)*1cm})},
        y={({sin(\w)*1cm},{cos(\w)*sin(\aa)*1cm})},
        z={(0,{cos(\aa)*1cm})}]
    \draw[blue,->] (0,0,0)coordinate(O) --  (1,0,0)node[below right]{$\vec{x}$};
    \draw[blue,->] (O) --  (0,1,0)node[above]{$\vec{y}$};    
    \draw[blue,->] (O) --  (0,0,1)node[above]{$\vec{z}$};

    \begin{scope}[canvas is xy plane at z=0]
        \draw[dashed] (0,0) circle [radius=1];
        \draw (2,0) coordinate (A) -- (0,0) coordinate (B) -- (1,1) coordinate (C);
        \draw[red] pic ["$\alpha$", draw, ->,transform shape,angle radius=0.8cm,
        pic text options={transform shape=false}] {angle}; % correct
        \draw[green] (0:0.9) arc[start angle=0,end angle=45,radius=0.9]; % correct 
    \end{scope}

\end{tikzpicture}
\end{document}

enter image description here

  • Thank you, I didn't know about transform shape, and your trick to not transform the text is welcome. Any chance to see such a modification natively implemented in the angles library someday, as @Kpym did here? – Tobard Jun 02 '20 at 14:45
  • 1
    @Tobard The right angle is already part of the angles library, see the example on p. 569 of pgfmanual v3.1.5. Which changes would you like to implement? (You can also use \draw[red] pic ["$\alpha$" {transform shape=false}, draw, ->,transform shape,angle radius=0.8cm,] {angle}; to not project the text on the plane.) –  Jun 02 '20 at 17:04
  • Yes, the right angle is part of the angles library. My point is that right angle works natively in a 3d picture, but it is not the case for angle as one may expect. It should be great to improve the angle macro to work in that situation as well, avoiding to use the hack you proposed. – Tobard Jun 03 '20 at 09:57
  • 1
    @Tobard It is the purpose of the transform shape key to make a pic or a node pick up the ambient transformation, which they by default do not. If you want to project a node text on the plane, you need to say transform shape as well. It is a design choice by TikZ, which one may argue about. But comparing adding the prescription of adding transform shape to Kpym's code, I may want to call the other one the "hack", yet this is a matter of taste. You can just build the transform shape key in the definition of your personal angle key, is this what you want? –  Jun 03 '20 at 13:41
  • It seems to me that the purpose of the angles library is to facilitate angles annotation with less code and more readability. Under this hypothesis, following the 3d projection while keeping text intact seem to be the logical result and would be worth implementing it. For now, I will then create my own macro. Thanks. – Tobard Jun 03 '20 at 14:07
  • 2
    @Tobard Fair enough. You could also just say \tikzset{pics/angle/.append style={/tikz/transform shape,/tikz/pic text options={transform shape=false}}} to add this prescription to all angles. –  Jun 03 '20 at 14:20