9

I saw the image below and noticed that whoever made it slanted the angle label to match the slant of the perspective. I think this is a really nice effect that very effectively labels angles in 3 dimensional shapes.

I was wondering how this kind of effect is done. Also, I was wondering how the slanted right-angle sign is done.

enter image description here

15

The answer is you don't. Just load the 3d library and let TikZ compute the "slant" for you. The key elements are canvas is <plane> plane at x=<x0> and transform shape in

\begin{scope}[canvas is zy plane at x=0,transform shape]
\draw ({4*cos(30)-cos(15)},{sin(15)}) node[right,xscale=-1,font=\large]{$30^\circ$};
\end{scope}

This will do the projections for you. You may or may not set the 3D coordinate system. If not, TikZ will take the default value z=(-0.5,-0.5). Your picture looks a little bit as if these default values were used, but since these are projections one never knows.

(EDIT: Added the "tilted" arrow using \pgflowlevelsynccm. 2nd EDIT: Now I think I understand what you mean by slanted right angle sign. My bad! 3rd EDIT: added explanation and made minor corrections to the animation.)

\documentclass[margin=3.14mm,tikz]{standalone}
\usetikzlibrary{3d,arrows.meta}
\tikzset{bullet/.style={circle,fill,scale=0.4}}
\begin{document}
\begin{tikzpicture}[z={({-cos(45)*1cm},{-sin(45)*1cm})},x={(1cm,0cm)}, y={(0cm,1cm)}]
\draw (-2,0,0) -- (5,0,0);
\draw (0.4,0,0) -- (0.4,0,0.4) -- (0,0,0.4);
\draw (0,0,0) node[bullet,label={above left:$P$}] (P){} -- (0,1,0);
\draw (0,{4*sin(30)},0) node[bullet,label={right:$T$}] (T){};
\begin{scope}[canvas is zy plane at x=0,transform shape]
\draw (0,0) -- (6,0);
\draw plot[variable=\x,domain=0:30] ({4*cos(30)-cos(\x)},{sin(\x)});
\draw ({4*cos(30)-cos(15)},{sin(15)}) node[right,xscale=-1,font=\large]{$30^\circ$};
\end{scope}
\begin{scope}[canvas is xz plane at y=0]
\pgflowlevelsynccm
\draw[-{Stealth[length=12pt,width=8pt,inset=3pt]},line width=1mm] (0,-1) -- (0,-2);
\end{scope}
\node[font=\large\sffamily] at (0,0.2,-2) {N};
\draw (0,0,{4*cos(30)}) node[bullet,label={below:$B$}] (B){};
\draw (B) -- (T) -- (P);
\node[bullet,label=above right:$L$] (L) at (4,0,0){};
\draw (L) -- (3,0,6);
\draw[{Triangle[]}-{Triangle[].Bar[]},dashed] ([yshift=9pt]P.center) -- ([yshift=9pt]L.center)
node[midway,fill=white]{1 km};
\end{tikzpicture}
\end{document}

enter image description here

The advantage of this method is that this will do the correct slant for any view angle. (One only has to pay a bit attention to the orientation, which is why there is some \mysign trickery at work.)

\documentclass[margin=3.14mm,tikz]{standalone}
\usetikzlibrary{3d,arrows.meta}
\tikzset{bullet/.style={circle,fill,scale=0.4}}
\begin{document}
\foreach \X in {0,5,...,355}
{\begin{tikzpicture}[z={({-cos(\X)*1cm},{-0.45*sin(\X)*1cm})},x={(1cm,0cm)}, y={(0cm,1cm)}]
\path[use as bounding box] (-6,-5) rectangle (6,5);
\draw (-2,0,0) -- (5,0,0);
\draw (0.4,0,0) -- (0.4,0,0.4) -- (0,0,0.4);
\draw (0,0,0) node[bullet,label={above left:$P$}] (P){} -- (0,1,0);
\draw (0,{4*sin(30)},0) node[bullet,label={right:$T$}] (T){};
\node[bullet,label=above right:$L$] (L) at (4,0,0){};
\draw (L) -- (3,0,6);
\draw[{Triangle[]}-{Triangle[].Bar[]},dashed] ([yshift=9pt]P.center) -- ([yshift=9pt]L.center)
node[midway,fill=white]{1 km};
\begin{scope}[canvas is zy plane at x=0,transform shape]
\draw (0,0) -- (6,0);
\draw plot[variable=\x,domain=0:30] ({4*cos(30)-cos(\x)},{sin(\x)});
\pgfmathtruncatemacro{\mysign}{sign(-cos(\X))}
\ifnum\mysign=1
\draw ({4*cos(30)-cos(15)},{sin(15)}) node[left]{$30^\circ$};
\else
\draw ({4*cos(30)-cos(15)},{sin(15)}) node[xscale={-1},right]{$30^\circ$};
\fi
\end{scope}
\begin{scope}[canvas is xz plane at y=0]
\pgflowlevelsynccm
\draw[-{Stealth[length=12pt,width=8pt,inset=3pt]},line width=1mm] (0,-1) -- (0,-2);
\end{scope}
\node[font=\large\sffamily] at (0,0.2,-2) {N};
\draw (0,0,{4*cos(30)}) node[bullet,label={below:$B$}] (B){};
\draw (B) -- (T) -- (P);
\end{tikzpicture}}
\end{document}

enter image description here

  • 2
    Cool animation!!! – gen-z ready to perish Aug 5 '18 at 19:49
  • The knowledge and helpfulness of the members of this site never cease to amaze me. This is absolutely incredible. – Trogdor Aug 6 '18 at 12:43

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.