Linie in TikZ kürzen

Tabellen und Grafiken erstellen und anordnen


ThoRie
Forum-Century
Forum-Century
Beiträge: 159
Registriert: Fr 12. Mai 2017, 11:57

Linie in TikZ kürzen

Beitrag von ThoRie »

Hallo :)

Ich möchte gern die zweite Grafik aus folgendem Code produzieren:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (1,0);
\draw (1,0) circle (2pt);
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) -- (0.925,0);
\draw (1,0) circle (2pt);
\end{tikzpicture}
\end{document}
Allerdings sollte das auch sinnvoll umgesetzt sein, denn die Variante, die das jetzt bei mir macht, ist das Ergebnis von 10 Minuten herum probieren.

Kann man also die Linie so anpassen, dass sie immer, abhängig von seiner Größe, bis an den Rand des Kreises geht?

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

Da gibt es viele verschiedene Möglichkeiten, u.a.
\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}
\draw (0,0) -- (1,0);
\draw[fill=white] (1,0) circle [radius=2pt];
\end{tikzpicture}

\begin{tikzpicture}
\draw[shorten > = 2pt] (0,0) -- (1,0);
\draw (1,0) circle [radius=2pt];
\end{tikzpicture}

\begin{tikzpicture}
\draw
  (0,0) -- ({1cm-2pt},0)
  (1,0) circle [radius=2pt]
;
\end{tikzpicture}

\begin{tikzpicture}
\path 
  (1,0)
    node [draw,circle,inner sep=0pt,minimum size=4pt](c){}
    edge (0,0)
;
\end{tikzpicture}

\begin{tikzpicture}
\path 
  (0,0) coordinate (O)
  (1,0)
    node [draw,circle,inner sep=0pt,minimum size=4pt](c){}
    edge (O)
;
\end{tikzpicture}
\end{document}
Was man nimmt, hängt vom Kontext ab.

Bartman
Forum-Meister
Forum-Meister
Beiträge: 2456
Registriert: Do 16. Jul 2009, 21:41
Wohnort: Hessische Provinz

Beitrag von Bartman »

@ThoRie

Die Variante im letzten Beispiel dürfte Dir schon aus einem älteren Thema bekannt sein.
\documentclass[tikz]{standalone}
\usetikzlibrary{intersections, through}

\begin{document}
\begin{tikzpicture}
\draw
    node [draw, circle, inner sep=0pt, minimum size=4pt] (c) {}
    (c) -- +(-1,0)
;
\end{tikzpicture}

\begin{tikzpicture}
\draw
    node [draw, circle, inner sep=0pt, minimum size=4pt] (c) {}
    (c) -- +(180:1)
;
\end{tikzpicture}

\begin{tikzpicture}
\pgfmathsetlengthmacro{\radius}{2pt}
\draw 
    (0,0) -- (1cm-\radius,0) 
        arc [start angle=180, end angle=-180, radius=\radius]
;
\end{tikzpicture}

\begin{tikzpicture}
\draw (0,0) -- (1cm-2pt,0) coordinate (line end);
\node [draw, circle through=(line end)] at (1,0) {};
\end{tikzpicture}

\begin{tikzpicture}
\path [name path=line] (0,0) coordinate (O) -- (1,0) coordinate (c);
\draw [name path=circle] (c) circle [radius=2pt];
\draw [name intersections={of=line and circle}] (O) -- (intersection-1);
\end{tikzpicture}
\end{document}

Antworten