如何在 latex-tikz 中从节点到框创建多边/树边?

如何在 latex-tikz 中从节点到框创建多边/树边?

我必须在 LaTeX 中绘制一个图形,并且必须从节点到矩形绘制一条边,如图所示 这里。(图片说明:左边有一个节点,右边有一个盒子,从节点到盒子有多条直线,每条直线的角度不同,端点形成一条直线)

我还没有找到答案,宁愿避免制作大量的小边,特别是因为我需要多次在不同方向上制作这样的边。我正在使用带有 calc 库的 tikz。

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage[ngerman]{babel}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}


\begin{document}
\begin{tikzpicture}
%big box
\coordinate (lowleftbox) at (1,0);
\coordinate (uprightbox) at (9.5,10.5);
\draw[] (lowleftbox) rectangle (uprightbox);

%vertices
\coordinate (v1) at (0,5.5);
\coordinate (v2) at (0.5,5.5);
\fill (v1) circle[radius=3pt];
\fill (v2) circle[radius=3pt];

%edge between them
\draw[] (v1) to (v2);

%edge to box, manually, the code I want to improve
\draw[] (v2) to (1,5.5);
\draw[] (v2) to (1,5.6);
\draw[] (v2) to (1,5.7);
\draw[] (v2) to (1,5.8);
\draw[] (v2) to (1,5.9);
\draw[] (v2) to (1,6);
\draw[] (v2) to (1,5.4);
\draw[] (v2) to (1,5.3);
\draw[] (v2) to (1,5.2);
\draw[] (v2) to (1,5.1);
\draw[] (v2) to (1,5.0);

\end{tikzpicture}
\end{document}

我将非常感激任何与此相关的建议。谢谢!

答案1

你可以稍微简化一下:

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage[ngerman]{babel}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\tikzset{% from https://tex.stackexchange.com/a/290508/36296
    clip even odd rule/.code={\pgfseteorule}, % Credit to Andrew Stacey 
    invclip/.style={
        clip,insert path=
            [clip even odd rule]{
                [reset cm](-\maxdimen,-\maxdimen)rectangle(\maxdimen,\maxdimen)
            }
    }
}

\begin{document}
\begin{tikzpicture}
%big box
\coordinate (lowleftbox) at (1,0);
\coordinate (uprightbox) at (9.5,10.5);
\draw[] (lowleftbox) rectangle (uprightbox);

%vertices
\coordinate (v1) at (0,5.5);
\coordinate (v2) at (0.5,5.5);
\fill (v1) circle[radius=3pt];
\fill (v2) circle[radius=3pt];

%edge between them
\draw[] (v1) to (v2);

\begin{scope}
\begin{pgfinterruptboundingbox}
   \clip[invclip]  (lowleftbox) rectangle (uprightbox);
\end{pgfinterruptboundingbox}
\foreach \x in {-42,-35,...,42}{
  \draw[red] (v2) -- ++(\x:1);
}
\end{scope}

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容