2

I am a beginner with tikz. I am trying to reproduce the following image using tikz-3dplot : enter image description here

Here is what I have come up with so far, its not pretty because I cannot figure how to properly parametrize the relative position of each objects.

\documentclass{article}     
\usepackage{tikz,tikz-3dplot}      
\begin{document}      
\tdplotsetmaincoords{60}{50}     
\begin{tikzpicture}[tdplot_main_coords]
% F0
\draw[->] (0,0,0) -- (3.5,0,0) node[anchor=north east]{$x_0$};
\draw[->,>=latex'] (0,0,0) -- (0,0,1) node[anchor=south]{$z_0$};

% F1
\pgfmathsetmacro{\a}{3.5}
\pgfmathsetmacro{\y}{0}
\pgfmathsetmacro{\d}{3}
\pgfmathsetmacro{\theta}{0}
\pgfmathsetmacro{\alpha}{0}
\coordinate (F1) at (\a,\y,\d);
\tdplotsetrotatedcoords{90}{30}{-30};
\tdplotsetrotatedcoordsorigin{(F1)};    

% F0 to F1 - length
\draw[dashed] (2.15,0,-1) -- (2.15,0,1);
\draw[->] (0.7,0,0.2) -- (1.5,0,0.2) node[anchor = south]{$a_1$};
\draw[tdplot_rotated_coords,->] (0.15,0,-1.2) -- (0.15,0,-0.7) node[anchor = north west]{$d_1$};


% F1 - Frame
\draw[tdplot_rotated_coords,->] (0,0,0) -- (3,0,0) node[anchor=north west]{$x_1$};
\draw[dashed] (F1) -- (2+\a,\y,\d);
\draw[tdplot_rotated_coords,->] (0,0,-3) -- (0,0,1) node[anchor=south west]{$z_1$};


% F2
\draw[dashed,tdplot_rotated_coords] (2,0,-0.5) -- (2,0,0.5);
\draw[tdplot_rotated_coords] (2,-0.365,-0.5) -- (2,1.5,2);

\end{tikzpicture}        
\end{document} 

What I would love to achieve is to set up multiple coordinates system to make it easy to draw the arcs with the proper perspective, and to be able to add more frame without having to fine tune everything so the intersection matches.

How do I set up multiples 3d coordinates system ?

Dawi
  • 55

1 Answers1

3

I interpret the question to be about defining new coordinate systems that emerge from older coordinate systems by rotation about some of the axes. This has been discussed here, and I using one of the answers there. The rotations about x, y and z axis, respectively, can then be achieved with the roll, pitch and yaws keys. I use this to reproduce large parts of your screen shot. You can use the 3d library, which gets automatically loaded by tikz-3dplot, to switch into one of the coordinate planes.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta,bending}
\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=0+#1) coordinate(xpp)
(z spherical cs:radius=1,theta=90,phi=90+#1) coordinate(ypp) 
(0,0,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)}}
}

\begin{document}


\tdplotsetmaincoords{70}{120}     
\begin{tikzpicture}[tdplot_main_coords,>={Latex[bend]},semithick,line cap=round]
 \draw[->] (0,0,0) coordinate (O) -- (1,0,0) node[above]{$x_b$};
 \draw[->] (O) -- (0,1,0) node[above]{$y_b$};
 \draw[->] (O) -- (0,0,8) node[above]{$z_0=z_b$};
 \draw[->] (-0.3,0,1) -- (-0.3,0,3) node[midway,right] {$d_0$};
 \path (0,0,6) coordinate (O'); %define new center
 \begin{scope}[yaw=80,shift={(O')}]
  \draw[->] (O') -- (6,0,0) node[pos=1.1] {$x_0$};
  \begin{scope}[canvas is xy plane at z=0]
   \draw[->] (1,0.3) -- (3,0.3) node[midway,above] {$a_1$};
   \draw[dashed] (O') -- (-80:3);
   \draw[->] (-80:1) arc[start angle=-80,end angle=0,radius=1]
   node[pos=0.2,below] {$\theta_0$};
  \end{scope}
  %
  \path (4,0,0) coordinate (O''); %define new center
  \begin{scope}[roll=320,shift={(O'')}]
   \draw[->] (0,0,-1) -- (0,0,6) node[right]{$z_1$};
   \draw[->] (0.3,0,2) -- (0.3,0,4) node[midway,right] {$d_1$};
   \begin{scope}[canvas is yz plane at x=0]
    \draw[dashed] (130:3) -- (310:3);
    \draw[->] (130:1) arc[start angle=130,end angle=450,radius=1]
    node[pos=0.8,right] {$\alpha_1$};
   \end{scope}
   %
   \path (0,0,5) coordinate (O'''); %define new center
   \begin{scope}[yaw=20,shift={(O''')}]
    \draw[->] (O''') -- (4.5,0,0) node[pos=1.1] {$x_1$}; 
    \begin{scope}[canvas is xy plane at z=0]
     \draw[->] (2.5,-0.5) -- (3.5,-0.5) node[midway,above] {$a_2$};
     \draw[dashed] (O''') -- (-20:3);
     \draw[->] (340:1) arc[start angle=340,end angle=0,radius=1]
     node[pos=0.5,left] {$\theta_1$};
    \end{scope}
   \end{scope}
  \end{scope}
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here