如何设置多个三维坐标系?

如何设置多个三维坐标系?

我是 tikz 的新手。我正在尝试使用 tikz-3dplot 重现以下图像:在此处输入图片描述

这是我目前想到的,它并不漂亮,因为我无法弄清楚如何正确参数化每个物体的相对位置。

\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} 

我想要实现的是建立多个坐标系统,以便能够轻松绘制具有适当透视的弧线,并且能够添加更多框架,而不必微调所有内容以使交叉点匹配。

如何设置多个 3D 坐标系统?

答案1

我将这个问题解释为定义新的坐标系,这些坐标系通过旋转某些轴从旧坐标系中产生。这已经讨论过了这里,我使用那里的一个答案。然后可以使用rollpitchyaws键分别实现绕 x、y 和 z 轴的旋转。我使用它来重现屏幕截图的大部分内容。您可以使用3d会自动加载的库tikz-3dplot切换到其中一个坐标平面。

\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}

在此处输入图片描述

相关内容