我已经在 TikZ 中完成了这个图形,但我不知道如何在 TikZ-3D 中添加和标记角度,我该怎么做?
原始数据如下:
这是我的以及代码:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{60}{-30}
\begin{tikzpicture}[tdplot_main_coords, >=stealth, scale=2.5]
\draw[->, thick] (0,0,0)--(0,0,3) node[left] {$\vec{z}_{n-1}$};
\draw[->, thick] (0,0,0)--(3,0,0) node[below] {$\vec{x}_{n-1}$};
\draw[dashed] (0,0,0)--(0,0.53,0.47);
\draw[dashed] (1.75,0,0)--(1.75,0,1);
\draw[->, thick] (1.75,0,0)--(1.75,2,1.75) node[left] {$\vec{z}_{n}$};
\draw[dashed] (1.75,0.97,0.85)--(3,0.97,0.85);
\draw[->, thick] (1.75,0.97,0.85)--(3,0.97,1.5) node[below] {$\vec{x}_n$};
\draw[<->, thick] (0,0.32,0.25)--(1.75,0.32,0.25) node[above, midway] {$d_n$};
\draw[<->, thick] (2.75,0,0)--(2.75,0.97,0.85) node[right, midway] {$r_n$};
\end{tikzpicture}
\end{document}
答案1
另一个选项是更换tikz-3dplot
和3d
库perspective
。依我之见,这样我们可以更好地控制放置矢量的斜平面,而且绘图非常简单。此外,我只使用库来angles
绘制直角。
像这样:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{3d,angles,perspective}
\tikzset{ra/.style={red,draw,angle radius=0.5cm}} % right angle style
\begin{document}
\begin{tikzpicture}[3d view={-30}{30},>=stealth,scale=2.5,
line cap=round,line join=round]
% angles
\def\aa{48} % alpha angle
\def\ta{80} % theta angle
% some coordinates
\coordinate (O) at (0,0);
\coordinate (X) at (3,0,0);
\coordinate (Z) at (0,0,3);
\coordinate (O') at (1.75,0,0);
% vertical stuff
\begin{scope}[canvas is xz plane at y=0]
\draw[<->,thick] (X) node[below] {$\vec{x}_{n-1}$} -|
(Z) node[left] {$\vec{z}_{n-1}$};
\draw[dashed] (O') --++ (0,1);
\pic [ra] {right angle=Z--O--X};
\end{scope}
%z_n x_{n-1} plane
\begin{scope}[rotate around x=90-\aa,canvas is xy plane at z=0]
\draw[dashed] (O) --++ (0,0.7);
\draw[thick,->] (O') --++ (0,2.6) coordinate (Z') node[left] {$\vec{z}_n$};
\draw[thick,<->] (0,0.4) -- (1.75,0.4) node[midway,above] {$d_n$};
\draw[thick,<->] (2.75,0) -- (2.75,1.3) node[midway,right] {$r_n$};
\draw[dashed] (1.75,1.3) coordinate (P) --++ (1.25,0);
\pic [ra] {right angle=Z'--O'--O};
\end{scope}
% x_n and theta angle
\begin{scope}[rotate around x=180-\aa,canvas is xy plane at z=0]
\draw[thick,->] (P) --++ (\ta:2.3) coordinate (Q) node[below] {$\vec{x}_n$};
\draw[red,->] (P) ++ (0.5,0) arc (0:\ta:0.5) node[xshift=0.7cm,yshift=0.25cm] {$\theta_j$};
\pic [ra] {right angle=Q--P--O'};
\end{scope}
% alpha angle
\draw[canvas is yz plane at x=0,red,->] (O') ++ (0,0.5) arc (90:90-\aa:0.5) node[midway,above] {$\alpha_j$};
\end{tikzpicture}
\end{document}
答案2
我认为原图描绘了两个三维欧几里得变换。可以tikz-3dplot
通过定义旋转轴和新原点来实现这些变换,例如
\path (1,0,0) coordinate (xj)
(0,{cos(alphaj)},{-sin(alphaj)}) coordinate (yj)
(0,{sin(alphaj)},{cos(alphaj)}) coordinate (zj)
(dj,0,0) coordinate (Oj);
然后切换到新框架,例如通过
\begin{scope}[x={(xj)},y={(yj)},z={(zj)},shift={(Oj)}]
<code>
\end{scope}
可以在给定的平面中方便地绘制各种角度,例如
\scoped[canvas is xz plane at y=0] {\draw (0.5,0) |- (0,0.5);}
使用这些方法,可以用以下代码定性地再现原始图片,该代码将旋转角度和偏移定义为“函数”。
\documentclass[tikz,boder=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\tdplotsetmaincoords{60}{-30}
\begin{tikzpicture}[tdplot_main_coords, >={Stealth[bend]},
declare function={alphaj=50;thetaj=70;dj=5;rj=3;
zj1=4;xj1=8;},
pics/slash/.style={code={\draw[pic actions]
foreach \i in {1,...,#1} {({-0.3+0.3*(\i-#1/2-0.5)},-0.5) -- ({0.3+0.3*(\i-#1/2-0.5)},0.5)};}},
pics/slash/.default=1]
\draw[<->,thick] (xj1,0,0) node[below right] {$x_{j-1}$}
-- (0,0,0) coordinate[label=below:{$O_{j-1}$}] (Oj1)
-- (0,0,zj1) node[above]{$z_{j-1}$};
\scoped[canvas is xz plane at y=0] {\draw (0.5,0) |- (0,0.5);}
% define rotated y and z coordinates
\path (1,0,0) coordinate (xj)
(0,{cos(alphaj)},{-sin(alphaj)}) coordinate (yj)
(0,{sin(alphaj)},{cos(alphaj)}) coordinate (zj)
(dj,0,0) coordinate (Oj);
\begin{scope}[canvas is yz plane at x=dj]
\draw (0,0) -- pic[transform shape,sloped]{slash} ++ (0,3);
\path (Oj1) -- pic[sloped,transform shape,thin,-]{slash} ++ (0,3);
\path (90-alphaj/2:2) node[above]{$\alpha_j$};
\pgflowlevelsynccm
\draw[->] (0,2) arc[start angle=90,end angle=90-alphaj,radius=2];
\end{scope}
% switch to first rotated plane
\begin{scope}[x={(xj)},y={(yj)},z={(zj)},shift={(Oj)}]
\draw[thick,->] (0,0,0) -- ++ (0,0,5) node[above]{$z_j$};
\draw[dashed] (-dj,0,0) -- ++ (0,0,4);
\draw[dashed,<->] (-dj,0,2.5) -- node[above]{$d_j$} (0,0,2.5);
\draw[dashed,<->] (1.5,0,0) -- node[above right]{$r_j$} (1.5,0,rj);
\scoped[canvas is xz plane at y=0] {\draw (-0.5,0) |- (0,0.5);}
% define rotated x and y coordinates
\path ({cos(thetaj)},{-sin(thetaj)},0) coordinate (xj')
({sin(thetaj)},{cos(thetaj)},0) coordinate (yj')
(0,0,1) coordinate (zj')
(0,0,rj) coordinate (Oj');
\draw (Oj') -- pic[pos=0.7]{slash=2} ++ (5,0,0);
\path (Oj1) -- pic{slash=2} (Oj);
% switch to second rotated plane
\begin{scope}[x={(xj')},y={(yj')},z={(zj')},shift={(Oj')}]
\scoped[canvas is xz plane at y=0] {\draw (0.5,0) |- (0,0.5);}
\draw[thick,->] (0,0,0) -- (3,0,0) node[right]{$x_j$};
\begin{scope}[canvas is xy plane at z=0]
\path (thetaj/2:2) node[right]{$\theta_j$};
\pgflowlevelsynccm
\draw[->] (thetaj:2) arc[start angle=thetaj,end angle=0,radius=2];
\end{scope}
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}
答案3
默认情况下,所有圆和圆弧都绘制在 xy 平面上,但您可以使用 进行更改\tdplotsetthetaplanecoords{}
。 tikzlibrary 应该可以做到这一点。
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{60}{-30}
\begin{tikzpicture}[tdplot_main_coords, >=stealth, scale=2.5]
\draw[->, thick] (0,0,0) coordinate (O)--(0,0,3) coordinate(A) node[left] {$\vec{z}_{n-1}$};
\draw[->, thick] (O)--(3,0,0) coordinate(B) node[below] {$\vec{x}_{n-1}$};
\draw[dashed] (O)--(0,0.53,0.47);
\draw[dashed] (1.75,0,0)--(1.75,0,1);
\draw[->, thick] (1.75,0,0) coordinate(C) --(1.75,2,1.75) coordinate(D) node[left] {$\vec{z}_{n}$};
\draw[dashed] (1.75,0.97,0.85)--(3,0.97,0.85);
\draw[->, thick] (1.75,0.97,0.85)--(3,0.97,1.5) node[below] {$\vec{x}_n$};
\draw[<->, thick] (0,0.32,0.25)--(1.75,0.32,0.25) node[above, midway] {$d_n$};
\draw[<->, thick] (2.75,0,0)--(2.75,0.97,0.85) node[right, midway] {$r_n$};
\tdplotsetthetaplanecoords{90}
\draw[red] pic[draw] {right angle=B--O--A};
\tdplotsetthetaplanecoords{0}
\draw[red] pic[draw] {right angle=O--C--D};
\end{tikzpicture}
\end{document}