![Tikz - 绘制在同一 x 坐标处截断的平行线](https://linux22.com/image/332485/Tikz%20-%20%E7%BB%98%E5%88%B6%E5%9C%A8%E5%90%8C%E4%B8%80%20x%20%E5%9D%90%E6%A0%87%E5%A4%84%E6%88%AA%E6%96%AD%E7%9A%84%E5%B9%B3%E8%A1%8C%E7%BA%BF.png)
但是,我希望平行线在水平线上“截断”。如果平行线在水平线上截断,则所有平行线的长度都相等,并且是无理数,端点的坐标也是如此。因此,为了绘制它们,我既不想利用线的长度,也不想利用水平线上线端点的坐标。(所有线的斜率都是 1)
我怎样才能做到这一点?
这是我用来绘制它们的代码:
\documentclass{article}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\tikzstyle{every node}=[circle, draw, fill=black!50,
inner sep=0pt, minimum width=4pt]
\begin{tikzpicture}[thick,scale=0.8]
\draw {(0,0) -- (5,-5)node{}};
\draw \foreach \x in {0,0.5,...,5}
{
(\x,-\x) node{} -- (-5+\x,-5-\x)
};
\draw {(-5,-5) -- (5,-5)};
\end{tikzpicture}
\end{document}
干杯!
答案1
一个基本的解决方案:重新计算线的长度并使用极坐标......
\documentclass{article}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\tikzstyle{every node}=[circle, draw, fill=black!50,
inner sep=0pt, minimum width=4pt]
\begin{tikzpicture}[thick,scale=0.8]
\draw {(0,0) -- (5,-5)node{}};
\draw \foreach \x in {0,0.5,...,5}
{
(\x,-\x) node{} -- + (225:{1.414*(5-\x)}) % <---
};
\draw {(-5,-5) -- (5,-5)};
\end{tikzpicture}
\end{document}
这就是您所寻找的吗?
答案2
剪切线上方(或下方)的区域。
\documentclass{article}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\tikzstyle{every node}=[circle, draw, fill=black!50,
inner sep=0pt, minimum width=4pt]
\begin{tikzpicture}[thick,scale=0.8]
\begin{scope}
\clip (-5,-5) rectangle (5,0.2);
\draw {(0,0) -- (5,-5)node{}};
\draw \foreach \x in {0,0.5,...,5}
{
(\x,-\x) node{} -- (-5+\x,-5-\x)
};
\draw {(-5,-5) -- (5,-5)};
\end{scope}
\end{tikzpicture}
\end{document}