
我想畫兩個向量之間的角度:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles,quotes,babel,plotmarks}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[decoration=brace]
% orthogonal ground line
\draw[thick] (-3,0) -- (3,0);
% Origin
\draw[fill=black] (0,0) node(O)[anchor=north] {$O$};
% vector a
\draw[thick,->] (0,0) -- (-2,2) node(a)[anchor=north east] {$a$};
% vector b
\draw[thick,->] (0,0) -- (2.5,1.5) node(b)[anchor=west] {$b$};
\pic [draw, -, angle eccentricity=1.2, angle radius=1cm,, "$\gamma$"] {angle=b--O--a};
\end{tikzpicture}
\end{document}
由於某些原因,角度畫得比預期大?
有什麼建議如何正確執行此操作嗎?
答案1
原因是您錯誤地定義了角度的座標。如果您編寫\draw (0,0) -- (-2,2) node (a) [anchor=north east] {$a$};
,則定義(a)
為對標籤 的節點的引用$a$
,按照您的定義,其中心是north east
座標(-2,2)
。但這是(-2,2)
您實際需要的角度座標。
所以,你應該這樣做:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\begin{document}
\begin{tikzpicture}
% orthogonal ground line
\draw[thick] (-3,0) -- (3,0);
% Origin
\draw[fill=black] (0,0) coordinate (O) node [anchor=north] {$O$};
% vector a
\draw[thick,->] (0,0) -- (-2,2) coordinate (a) node[anchor=north east] {$a$};
% vector b
\draw[thick,->] (0,0) -- (2.5,1.5) coordinate (b) node[anchor=west] {$b$};
\pic[draw, angle eccentricity=1.2, angle radius=1cm,, "$\gamma$"] {angle=b--O--a};
\end{tikzpicture}
\end{document}
作為替代方案,您可以使用labels
:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\begin{document}
\begin{tikzpicture}
% orthogonal ground line
\draw[thick] (-3,0) -- (3,0);
% Origin
\draw[fill=black] (0,0) coordinate[label={below:$0$}] (O);
% vector a
\draw[thick,->] (0,0) -- (-2,2) coordinate[label={below left:$a$}] (a);
% vector b
\draw[thick,->] (0,0) -- (2.5,1.5) coordinate[label={right:$b$}] (b);
\pic [draw, angle eccentricity=1.2, angle radius=1cm,, "$\gamma$"] {angle=b--O--a};
\end{tikzpicture}
\end{document}
答案2
這很容易做到pstricks
——更具體地說pst-eucl
:
\documentclass[pstricks, border=6pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(-3,-1)(3,3)
\psset{arrowinset=0.12,labelsep=3pt}
\pstGeonode[PointSymbol=none, PosAngle={-90,135, 45}](0,0){O}(-2,2){a}(2.5,1.5){b}
% orthogonal ground line
\psline (-3,0)(3,0)
\ncline{->}{O}{a}\ncline{->}{O}{b}
\pstMarkAngle[linewidth=0.3pt, LabelSep=0.6]{b}{O}{a}{$\gamma$}%
\end{pspicture}
\end{document}
答案3
節點不在端點處,而是在旁邊,您需要像這樣指定座標
\begin{tikzpicture}[decoration=brace]
% orthogonal ground line
\draw[thick] (-3,0) -- (3,0);
% Origin
\coordinate (O) at (0,0);
\draw[fill=black] (O) node[anchor=north] {$O$};
% vector a
\coordinate (a) at (-2,2);
\draw[thick,->] (O) -- (a) node[anchor=south east] {$a$};
% vector b
\coordinate (b) at (2.5,1.5);
\draw[thick,->] (O) -- (b) node[anchor=south west] {$b$};
\pic [draw, -, angle eccentricity=1.2, angle radius=1cm,, "$\gamma$"] {angle=b--O--a};
\end{tikzpicture}