![Tikz:绘制从一个点指向另一个点的矢量](https://linux22.com/image/256503/Tikz%EF%BC%9A%E7%BB%98%E5%88%B6%E4%BB%8E%E4%B8%80%E4%B8%AA%E7%82%B9%E6%8C%87%E5%90%91%E5%8F%A6%E4%B8%80%E4%B8%AA%E7%82%B9%E7%9A%84%E7%9F%A2%E9%87%8F.png)
我有两点看法:
\coordinate (A) at (1,2);
\coordinate (B) at (13.2,-23.4);
我想绘制一个从点 A 指向点 B 的矢量。该矢量从点 A 开始,其长度由其他指定,其终点不在点 B。见下图。有没有一种自动绘制箭头的方法,这样我就不需要每次都计算箭头终点的坐标了?
答案1
除此之外shorten
,您可能对calc
图书馆感兴趣。
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (-1,5);
\coordinate (B) at (1,2);
\tikzset{-|}
\draw [|-|,help lines] (A) -- (B);
\draw[black,very thick] (A) -- ($(B)!1cm!(A)$); % 1 cm before B
\draw[blue, thick] (A) -- ($(A)!.65!(B)$); % 65 % on the path from A to B
\draw[green] (A) -- ($(B)!.45!(A)$); % 45 % on the path from B to A (55% from A to B)
\end{tikzpicture}
\end{document}
输出
答案2
您可以使用shorten >= <length>
:
代码
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (1,2);
\coordinate (B) at (2,4);
\draw [fill=blue] (A) circle (2pt) node [left] {A};
\draw [fill=blue] (B) circle (2pt) node [left] {B};
\draw [-latex, red, thick, shorten >= 1.00cm] (A) -- (B);
\end{tikzpicture}
\end{document}
答案3
这里有一种方法:
\documentclass[11pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,arrows}
\begin{document}
\begin{tikzpicture}
\node[circle,draw,black,scale=0.2] (A) at (1,2) {};
\node[circle,draw,black,scale=0.2] (B) at (3,4) {};
\draw[postaction={decorate,decoration={markings,mark=at position 0.25 with {\arrow[black,line width=1.5pt]{>}}}}](A)node[below]{A}--(B)node[above]{B};
\end{tikzpicture}
\end{document}
结果: