我想在 TikZ 中重现下图:
这两个向量是(-1/5, 2/5),(2/5, 1/5) 。有没有办法让 TikZ 绘制虚线直到与粗外框的交点,而不必实际计算交点并明确输入节点?到目前为止,我有:
\begin{tikzpicture}
\node (a) at (-1, 2) {};
\node (b) at (2, 1) {};
\draw [very thick] (-5, 0) -- (5, 0);
\draw [very thick] (-5, -5) -- (5, -5);
\draw [very thick] (-5, 5) -- (5, 5);
\draw [very thick] (-5, -5) -- (-5, 5);
\draw [very thick] (0, -5) -- (0, 5);
\draw [very thick] (5, -5) -- (5, 5);
\draw [very thick, ->] (0, 0) -- (a);
\draw [very thick, ->] (0, 0) -- (b);
\node[label=right:{$1$}] at (5,0) {};
\node[label=above:{$1$}] at (0,5) {};
\end{tikzpicture}
产生
答案1
可能使用极坐标会得到更好的结果(尤其是不用来node
定义点 a 和 b,而是coordinate
)。
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-5,-5) rectangle (5,5);
\draw[rotate=30,dotted,orange,cap=round] (-10,-10) grid[step=2cm] (10,10);
\end{scope}
\coordinate (a) at (30:2) {};
\coordinate (b) at (120:2) {};
\draw [very thick] (-5, -5) rectangle (5, 5)
(-5,0) -- (5,0) node[right] {$1$}
(0,-5) -- (0,5) node [above] {$1$};
\draw [very thick, ->] (0, 0) -- (a);
\draw [very thick, ->] (0, 0) -- (b);
\end{tikzpicture}
\end{document}
答案2
这是一个使用的解决方案grid
:
\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (-1, 2);
\coordinate (b) at (2, 1);
\draw [very thick, ->] (0, 0) -- (a);
\draw [very thick, ->] (0, 0) -- (b);
\node[label=right:{$(1,0)$}] at (5,0) {};
\node[label=above:{$(0,1)$}] at (0,5) {};
\draw[very thick, step=5] (-5,-5) grid (5,5);
\clip (-5,-5) rectangle (5,5);
\draw[dashed, very thick, step=sqrt(5), rotate=atan(1/2)] (-10,-10) grid (10,10);
\end{tikzpicture}
\end{document}