7

I am using tikz-3dplot a lot to draw coordinate systems (often multiple in one drawing) and I am not satisfied with how the 'origin' looks. For example,

\documentclass[tikz]{standalone}

\usepackage{tikz-3dplot}

\tikzset{
    axis/.style={-stealth,line width=2pt,every node/.append style={text=black}},
    xaxis/.style={axis,red},
    yaxis/.style={axis,green},
    zaxis/.style={axis,blue},
}

\begin{document}
    \tdplotsetmaincoords{70}{115}
    \begin{tikzpicture}[tdplot_main_coords]
        \draw[xaxis] (0,0,0) -- (1,0,0) node[pos=1.3]{\( x \)};
        \draw[yaxis] (0,0,0) -- (0,1,0) node[pos=1.3]{\( y \)};
        \draw[zaxis] (0,0,0) -- (0,0,1) node[pos=1.3]{\( z \)};
    \end{tikzpicture}
\end{document}

Results in

enter image description here

My problem (obviously) is with this part

enter image description here

Now I know that generally I would propose how I would like to see it, but the problem is twofold, because I am also not sure what exactly I would like to see. Does anyone have a solution that shows a more beautiful result? I should add that the orientation of the coordinate systems is not fixed, so the solution should be beautiful in every orientation.

Max
  • 9,733
  • 3
  • 28
  • 35
  • Did you test line cap=round? – AlexG Jul 18 '18 at 10:03
  • Yes but I'm not completely convinced. It does look slightly better. – Max Jul 18 '18 at 10:04
  • But how do you want it to look like? PGF is basically a 2D graphics language. – AlexG Jul 18 '18 at 10:06
  • I'm not sure what I want to see, I'm basically asking what other people are doing with this problem, e.g. drawing a small black dot on top of the three line endings would be a bit better. But maybe there is some alternative that I am overlooking. – Max Jul 18 '18 at 10:09
  • 1
    You could place a ball-shaded on top, \shade [ball color=red] (0,0,0) circle [radius=0.04cm];, in order to hide the origin. – AlexG Jul 18 '18 at 10:16
  • .. or without shade: \filldraw[red] (0,0,0) circle [radius=0.04cm]; – AlexG Jul 18 '18 at 10:21
  • Would you mind if I placed an answer listing some of the solutions (including yours)? – Max Jul 18 '18 at 10:29
  • No problem, go ahead. – AlexG Jul 18 '18 at 10:38

2 Answers2

7

I've collected some answers from the comments.

Basic style

enter image description here

\documentclass[tikz]{standalone}

\usepackage{tikz-3dplot}

\usetikzlibrary{arrows.meta}

\tikzset{
    axis/.style={-stealth,line width=2pt,every node/.append style={text=black}},
    xaxis/.style={axis,red},
    yaxis/.style={axis,green},
    zaxis/.style={axis,blue},
}

\begin{document}
    \foreach \rotationangle in {115,120,...,470}{
        \tdplotsetmaincoords{70}{\rotationangle}
        \begin{tikzpicture}
            \clip (-1.5,-0.75) rectangle (1.5,1.5);
            \begin{scope}[tdplot_main_coords]
                \draw[xaxis] (0,0,0) -- (1,0,0) node[pos=1.3]{\( x \)};
                \draw[yaxis] (0,0,0) -- (0,1,0) node[pos=1.3]{\( y \)};
                \draw[zaxis] (0,0,0) -- (0,0,1) node[pos=1.3]{\( z \)};
            \end{scope}
        \end{tikzpicture}
    }
\end{document}

Using line cap=round

Credits to @AlexG.

enter image description here

axis/.style={-stealth,line width=2pt,every node/.append style={text=black},line cap=round},

Overdrawing with a ball

Credits to @AlexG. enter image description here

\filldraw[red] (0,0,0) circle [radius=0.04cm];

Overdrawing with a shaded ball

Credits to @AlexG. enter image description here

\shade [ball color=black] (0,0,0) circle [radius=0.04cm];
Max
  • 9,733
  • 3
  • 28
  • 35
4

Very similar to Max Snippe's nice answer except that I recycle some alternative to tikz-3dplot which allows you to rotate about all three axes without pain (look also at Max Snippe's nice alternative), and, more importantly, \pgflowlevelsynccm to have more 3D-like arrows. (The shaded ball at the origin is adapted from the AlexG/Max Snippe consortioum. ;-)

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{3d}
\makeatletter
%from https://tex.stackexchange.com/a/375604/121799
%along x axis
\define@key{x sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{x sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{x sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x
    \setkeys{x sphericalkeys}{#1}%
    \pgfpointxyz{\myradius*cos(\mytheta)}{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*sin(\mytheta)*sin(\myphi)}}

%along y axis
\define@key{y sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{y sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{y sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x
    \setkeys{y sphericalkeys}{#1}%
    \pgfpointxyz{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*cos(\mytheta)}{\myradius*sin(\mytheta)*sin(\myphi)}}

%along z axis
\define@key{z sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{z sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{z sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x
    \setkeys{z sphericalkeys}{#1}%
    \pgfpointxyz{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*sin(\mytheta)*sin(\myphi)}{\myradius*cos(\mytheta)}}


\makeatother

% definitions to make your life easier
\tikzset{rotate axes about y axis/.code={
\path (y spherical cs:radius=1,theta=90,phi=0+#1) coordinate(xpp)
(y spherical cs:radius=1,theta=00,phi=90+#1) coordinate(ypp) 
(y spherical cs:radius=1,theta=90,phi=90+#1) coordinate(zpp);
},rotate axes about x axis/.code={
\path (x spherical cs:radius=1,theta=00,phi=90+#1) coordinate(xpp)
(x spherical cs:radius=1,theta=90,phi=00+#1) coordinate(ypp) 
(x spherical cs:radius=1,theta=90,phi=90+#1) coordinate(zpp);
},
rotate axes about z axis/.code={
\path (z spherical cs:radius=1,theta=90,phi=#1) coordinate(xpp)
(z spherical cs:radius=1,theta=90,phi=90+#1) coordinate(ypp) 
(z spherical cs:radius=1,theta=00,phi=#1) coordinate(zpp);
},
pitch/.style={rotate axes about y axis=#1,x={(xpp)},y={(ypp)},z={(zpp)}},
roll/.style={rotate axes about x axis=#1,x={(xpp)},y={(ypp)},z={(zpp)}},
yaw/.style={rotate axes about z axis=#1,x={(xpp)},y={(ypp)},z={(zpp)}}
}

\tikzset{
    axis/.style={-stealth,line width=2pt,every node/.append style={text=black}},
    xaxis/.style={axis,red},
    yaxis/.style={axis,green},
    zaxis/.style={axis,blue},
}

\begin{document}
\foreach\X in {0,5,...,355}
{\begin{tikzpicture}[yaw=00,scale=2]
\draw (-3,3,0) rectangle (3,-2,0);
\begin{scope}[pitch=\X]
\begin{scope}[canvas is xz plane at y=0,transform shape]
        \pgflowlevelsynccm
        \draw[yaxis] (0,0,0) -- (0,1);
        \draw[xaxis] (0,0,0) -- (1,0);
\end{scope}
\draw[zaxis] (0,0,0) -- (0,1,0) node[pos=1.3]{\( z \)};
\node at (1.3,0,0) {\( x \)};
\node at (0,0,1.3) {\( y \)};
\end{scope}
\shade[ball color=black](0,0,0) circle (1mm);
\end{tikzpicture}}
\end{document}

enter image description here