1

I have to draw a graph in LaTeX and I have to draw an edge from a node to a rectangle as seen here. (image description: there is a node on the left and a box on the right, with multiple straight lines going from the node to the box, all having different angles, the endpoints form a straight line)

I haven't found an answer yet and would rather avoid making a ton of small edges, especially since I need to make such an edge multiple times and in different directions. I am using tikz with calc library.

\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}

I would be grateful for any tips regarding this. Thank you!

2
  • Please make a compilable [mre] Commented Nov 30, 2020 at 20:46
  • @samcarter_is_at_topanswers.xyz I added a minimal code example with manually drawn edges (what I want to avoid).
    – notSpock
    Commented Dec 1, 2020 at 11:45

1 Answer 1

0

You can simplify this a bit:

\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}

enter image description here

2
  • Thank you, something like this was what I was looking for!
    – notSpock
    Commented Dec 1, 2020 at 12:03
  • @notSpock You're welcome! Commented Dec 1, 2020 at 12:04

You must log in to answer this question.