我需要在我的图表中添加一个矩形:它的边应该与轴 $x_{or}$ 和 $y_{or}$ 平行。我知道如何添加矩形,但我不知道如何将其边设置为与轴平行。以下是我目前所做的:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%principal axes
\draw[->,very thick](0,0,0)--(6,0,0);
\draw[-] (6.2,0,0) node {\LARGE y};
\draw[->,very thick](0,0,0)--(0,8,0);
\draw[-] (0,8.2,0) node {\LARGE z};
\draw[->,very thick](0,0,0)--(0,0,10);
\draw[-] (0,0,10.5) node {\LARGE x};
%orbital plane axes
\draw[->,very thick,red](0,0,0)--(4,-5,-1);
\draw[-] (4,-5.5,-1.5) node {\LARGE $x_{or}$};
\draw[->,very thick,red](0,0,0)--(0.001,7,-2);
\draw[-] (0.001,7.2,-2.3) node {\LARGE $\vec{\ell}$};
\draw[->,very thick,red](0,0,0)--(-5,-3,-3);
\draw[-] (-5,-3,-2.3) node{\LARGE $y_{or}$};
%axis n
\draw[->,very thick,blue](0,0,0)--(5,-4,-2);
\draw[-] (5,-4.4,-2.7) node {\LARGE $\vec{n}$};
%phi angle
\filldraw[-](0,0,0)--(10mm,-10mm) arc (0:30:10mm) --cycle;
\draw[-] (1,-2,-1.7)node {\LARGE $\phi$};
\end{tikzpicture}
\end{document}
答案1
希望以下内容有所帮助。标记各种角度的一种简单方法是使用angles
Ti钾Z 库。直角不太难手动完成,如下所示。其他的也可以使用基于 的计算手动完成atan2
,但angles
Ti钾Z 库使这个任务变得容易得多。
你可能应该使用\coordinate
更多,以使你的代码更具可读性和可维护性,并阅读有关positioning
库的内容TikZ & PGF 手册(下面有一个例子,放置包含的节点$\vec{\ell}$
)。
评论:
\node[xshift=1.5pt, above=2pt of l] {$\vec{\ell}$};
也可以写成
\node[above right=2pt and 1.5pt of l, anchor=south] {$\vec{\ell}$};
解释:above right
设置anchor=south west
,但我们用覆盖它,anchor=south
因为这样更方便。
另外,不要忘记使用$x$
而不是简单地x
在节点中使用,X表示数学对象。两种情况使用的字体相当不同。
\documentclass[tikz, border=2mm]{standalone}
% 'calc': for the right angle marked using a “manual way”
\usetikzlibrary{angles, calc, positioning, quotes}
\begin{document}
\begin{tikzpicture}[font=\LARGE, arrow/.style={->, very thick}]
\coordinate (O) at (0,0,0);
\draw[arrow](0,0,0)--(6,0,0);
\node at (6.2,0,0) {$y$};
\draw[arrow](0,0,0)--(0,8,0);
\node at (0,8.2,0) {$z$};
\draw[arrow](0,0,0)--(0,0,10);
\node at (0,0,10.5) {$x$};
\coordinate (x) at (4,-5,-1);
\node at (4,-5.5,-1.5) {$x_{or}$};
\coordinate (y) at (-5,-3,-3);
\node at (-5,-3,-2.3) {$y_{or}$};
\coordinate (n) at (5,-4,-2);
\node at (5,-4.4,-2.7) {$\vec{n}$};
\coordinate (l) at (0.001,7,-2);
\node[xshift=1.5pt, above=2pt of l] {$\vec{\ell}$};
% Non-right angle using the 'angles' TikZ library
\pic["$\phi$", fill=black!30, angle radius=1.4cm, angle eccentricity=1.2]
{angle=x--O--n};
\draw[arrow, blue] (0,0,0) -- (n);
\draw[arrow, red] (0,0,0) -- (x);
\draw[arrow, red] (0,0,0) -- (l);
\draw[arrow, red] (0,0,0) -- (y);
% Right angle using the 'calc' TikZ library
\coordinate (a) at ($(O)!10pt!(x)$);
\coordinate (b) at ($(O)!10pt!(y)$);
\draw[blue!40] (a) -- ([shift=(a)]b) -- (b);
% Right angle using the 'angles' TikZ library (easier)
\pic[draw=green!50!blue, angle radius=10pt] {right angle=y--O--l};
\end{tikzpicture}
\end{document}