Schnittpunkte in TikZ Grafik
Hallo,
ich möchte mit TikZ eine Beziehung über ein System von linearen Gleichungen visualisieren. Das ist mir als TikZ Anfänger soweit auch gelungen. Dabei habe ich die Koordinaten von einer Grafikvorlage übernommen.
Während in der Vorlage alle Koordinaten manuell eingegeben wurde, möchte ich sie in TikZ aber möglichst ausrechnen lassen. Dazu habe ich das Konstrukt mit dem -| bzw. |- benutzt, sowie xshift.
Leider find ich keinen Weg, die Schnittpunkte in den Geraden elegant anzugeben. Da für die Linien A1-A2 und B1-B2 identische x1 bzw. x2 gelten, konnte ich die beiden Punkte mit ($ (A1) ! 0.4 ! (A2) $) berechnen, musste aber beide male den Faktor 0.4 angeben. Besser wäre, von y ausgehend die Punkte zu bestimmen.
Gibt es da einen Weg?
Wie erwähnt, bin ich TikZ Anfänger. Kann man das übersichtlicher aufschreiben?
\documentclass{article} \usepackage{tikz} \usetikzlibrary{calc, arrows.meta} \begin{document} \noindent \begin{tikzpicture}[scale=1.0, >=Stealth] % The position of the cartesian coordination system \coordinate (O) at (2.740,1.172); \coordinate (X) at (18.634,1.172); \coordinate (Y) at (2.740,12.776); \draw [->] (O) -- (X); \draw [->] (O) -- (Y); \node [label=left:$y$] at (Y) {}; \node [label=below:$x$] at (X) {}; % The line endpoints \coordinate (A1) at (4.555,10.716); \coordinate (A2) at (15.214,9.487); \coordinate (B1) at (4.555,6.709); \coordinate (B2) at (15.214,4.328); % draw lines with dots \draw [blue,thick] (A1)--(A2); \draw [blue, fill] (A1) circle [radius=3pt]; \draw [blue, fill] (A2) circle [radius=3pt]; \draw [red,thick] (B1)--(B2); \draw [red, fill] (B1) circle [radius=3pt]; \draw [red, fill] (B2) circle [radius=3pt]; % example point at the functions. Better input would be a value of Y \coordinate (A curr) at ($ (A1) ! 0.4 ! (A2) $); \coordinate (B curr) at ($ (B1) ! 0.4 ! (B2) $); \draw [blue, fill] (A curr) circle [radius=3pt]; \draw [red, fill] (B curr) circle [radius=3pt]; \node (y in) at ([xshift=-2cm]A curr -| Y) {$y$}; \node (y out) at ([xshift=-2cm]B curr -| Y) {$\tilde{y}$}; % draw dependcy from Y to first function getting ~X, to second function, getting ~y \draw [-{Stealth[length=3mm]}] (y in) -- (A curr); \draw [-{Stealth[length=3mm]}] (A curr) -- (B curr); \draw [-{Stealth[length=3mm]}] (B curr) -- (y out); % draw supplemental lines from points to axis \draw [dashed] (A1) -- (A1 -| Y) coordinate (a1); \draw [dashed] (A2) -- (A2 -| Y) coordinate (a2); \draw [dashed] (B1) -- (B1 -| Y) coordinate (b1); \draw [dashed] (B2) -- (B2 -| Y) coordinate (b2); \draw [dashed] (A1) -- (B1 |- X) coordinate (x1); \draw [dashed] (A2) -- (B2 |- X) coordinate (x2); \draw [dashed] (B curr) -- (B curr |- X) coordinate (x); % draw coordinate's names at the axis \draw [very thick] (x2) ++(0,0.25) -- ++(0,-0.5) node[label=below:$x_2$] {}; \draw [very thick] (x1) ++(0,0.25) -- ++(0,-0.5) node[label=below:$x_1$] {}; \draw [very thick] (x) ++(0,0.25) -- ++(0,-0.5) node[label=below:$\bar{x}$] {}; \draw [very thick] (a1) ++(0.25,0) -- ++(-0.5,0) node[label=left:$a_1$] {}; \draw [very thick] (a2) ++(0.25,0) -- ++(-0.5,0) node[label=left:$a_2$] {}; \draw [very thick] (b1) ++(0.25,0) -- ++(-0.5,0) node[label=left:$b_1$] {}; \draw [very thick] (b2) ++(0.25,0) -- ++(-0.5,0) node[label=left:$b_2$] {}; \end{tikzpicture} \end{document}