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.

  • Use tikz-3dplot for angles in three dimensions. – Henri Menke Jun 2 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. – user194703 Jun 2 at 10:58
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

| improve this answer | |
  • 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 2 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.) – user194703 Jun 2 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 3 at 9: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? – user194703 Jun 3 at 13:41
  • 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. – user194703 Jun 3 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.