TikZ: Startpunkt von Verbindungslinie ändern

Antwort erstellen


Diese Frage dient dazu, das automatisierte Versenden von Formularen durch Spam-Bots zu verhindern.
Smilies
:D :) :( :o :shock: :? 8) :lol: :-x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:

BBCode ist eingeschaltet
[img] ist eingeschaltet
[flash] ist ausgeschaltet
[url] ist eingeschaltet
Smilies sind eingeschaltet

Die letzten Beiträge des Themas

Ich habe die Datenschutzerklärung gelesen und bin damit einverstanden.

   

Wenn du eine Datei oder mehrere Dateien anhängen möchtest, gib die Details unten ein.

Ansicht erweitern Die letzten Beiträge des Themas: TikZ: Startpunkt von Verbindungslinie ändern

Re: TikZ: Startpunkt von Verbindungslinie ändern

von Noah1989 » So 24. Jul 2022, 00:13

ups.. in dem Beispiel muss bei den neuen Ankerpunkten noch "box" durch "parallelepiped" ersetzt werden, da ich die shape bei mir anders genannt hatte :roll:

Re: TikZ: Startpunkt von Verbindungslinie ändern

von Noah1989 » So 24. Jul 2022, 00:09

Zusätzliche Ankerpunkte definiert man so:
\documentclass{article}

\usepackage{tikz}
\usepackage{xcolor}

\definecolor{grey}{RGB}{200,200,200}

\makeatletter
\pgfkeys{/pgf/.cd,
  parallelepiped offset x/.initial=2mm,
  parallelepiped offset y/.initial=2mm
}
\pgfdeclareshape{parallelepiped}
{
  \inheritsavedanchors[from=rectangle] % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{mid}
  \inheritanchor[from=rectangle]{mid west}
  \inheritanchor[from=rectangle]{mid east}
  \inheritanchor[from=rectangle]{base}
  \inheritanchor[from=rectangle]{base west}
  \inheritanchor[from=rectangle]{base east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}
  
  %add additional anchor points at the outer side of the box
  	\anchor{north outer}{    
		% store lower right in xa/ya and upper right in xb/yb
		\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
		\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
		\pgf@x=0.5\pgf@xa \advance \pgf@x by 0.5\pgf@xb
		\pgf@y=\pgf@yb \advance \pgf@y by \pgfkeysvalueof{/pgf/box offset y}
	}
	\anchor{east outer}{    
		% store lower right in xa/ya and upper right in xb/yb
		\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
		\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
		\pgf@x=\pgf@xb \advance \pgf@x by \pgfkeysvalueof{/pgf/box offset x}
		\pgf@y=0.5\pgf@ya \advance \pgf@y by 0.5\pgf@yb
	}
	\anchor{north east outer}{    
		\northeast
		\advance \pgf@x by \pgfkeysvalueof{/pgf/box offset x}
		\advance \pgf@y by \pgfkeysvalueof{/pgf/box offset y}
	}
  
  \backgroundpath{
    % store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/parallelepiped offset x}}
    \pgfmathsetlength\pgfutil@tempdimb{\pgfkeysvalueof{/pgf/parallelepiped offset y}}
    \def\ppd@offset{\pgfpoint{\pgfutil@tempdima}{\pgfutil@tempdimb}}
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathclose
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@ya}}{\ppd@offset}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\ppd@offset}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xa}{\pgf@yb}}{\ppd@offset}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\ppd@offset}}
  }
}
\makeatother

\begin{document}
\begin{tikzpicture}

\node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,minimum height=1.5cm, align=center] 
(1) at (0,0) {Block 1};
\node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm, minimum height=1.5cm, align=center] 
(2) at (4,0) {Block 2};

\draw[thin, -] (1.east outer) -- (2);

\end{tikzpicture}
\end{document}

Re: TikZ: Startpunkt von Verbindungslinie ändern

von Yoschi95 » Mi 15. Jun 2022, 22:03

Hallo Stefan,

das ist eine echt simple und zugleich effektive Lösung!

Besten Dank!!!

Re: TikZ: Startpunkt von Verbindungslinie ändern

von Stefan Kottwitz » Mi 15. Jun 2022, 18:54

Hallo Yoschi,

willkommen im Forum!

Ich finde es super, dass Du gleich ein komplettes Codebeispiel postest. Das probiere ich doch gern aus und hier ist mein Vorschlag.

Zeichne doch einfach die Linie zusammen mit den Nodes, denn die werden erst nach dem gezeichneten Pfad drauf platziert und damit ist die Linie überdeckt:
\draw (0,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
      minimum height=1.5cm, align=center] (1){Block 1}
    -- (4,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
      minimum height=1.5cm, align=center] (2) at (4,0) {Block 2};
quader.png
Testbares Komplettbeispiel, einfach auf "LaTeX-Ausgabe" klicken:
\documentclass[border=10pt]{standalone}

\usepackage{tikz}
\usepackage{xcolor}

\definecolor{grey}{RGB}{200,200,200}

\makeatletter
\pgfkeys{/pgf/.cd,
  parallelepiped offset x/.initial=2mm,
  parallelepiped offset y/.initial=2mm
}
\pgfdeclareshape{parallelepiped}
{
  \inheritsavedanchors[from=rectangle] % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{mid}
  \inheritanchor[from=rectangle]{mid west}
  \inheritanchor[from=rectangle]{mid east}
  \inheritanchor[from=rectangle]{base}
  \inheritanchor[from=rectangle]{base west}
  \inheritanchor[from=rectangle]{base east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}
  \backgroundpath{
    % store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/parallelepiped offset x}}
    \pgfmathsetlength\pgfutil@tempdimb{\pgfkeysvalueof{/pgf/parallelepiped offset y}}
    \def\ppd@offset{\pgfpoint{\pgfutil@tempdima}{\pgfutil@tempdimb}}
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathclose
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@ya}}{\ppd@offset}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\ppd@offset}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xa}{\pgf@yb}}{\ppd@offset}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\ppd@offset}}
  }
}
\makeatother

\begin{document}
\begin{tikzpicture}

\draw (0,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
      minimum height=1.5cm, align=center] (1){Block 1}
    -- (4,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
      minimum height=1.5cm, align=center] (2) at (4,0) {Block 2};

\end{tikzpicture}
\end{document}
Stefan

TikZ: Startpunkt von Verbindungslinie ändern

von Yoschi95 » Mi 15. Jun 2022, 14:51

Hallo Community!

Ich habe hier ein Minimalbeispiel, in dem sogenannte Parallelepiped (geometrischer Körper) definiert werden. Bei der Verwendung dieser startet die Verbindungslinie von Block 1 zu Block 2 bei der vorderen rechten Linie des Block 1. Allerdings möchte ich, dass die Linie bei der hinteren rechten Linie des Blocks startet.

Kann mir jemand helfen?
\documentclass{article}

\usepackage{tikz}
\usepackage{xcolor}

\definecolor{grey}{RGB}{200,200,200}

\makeatletter
\pgfkeys{/pgf/.cd,
  parallelepiped offset x/.initial=2mm,
  parallelepiped offset y/.initial=2mm
}
\pgfdeclareshape{parallelepiped}
{
  \inheritsavedanchors[from=rectangle] % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{mid}
  \inheritanchor[from=rectangle]{mid west}
  \inheritanchor[from=rectangle]{mid east}
  \inheritanchor[from=rectangle]{base}
  \inheritanchor[from=rectangle]{base west}
  \inheritanchor[from=rectangle]{base east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}
  \backgroundpath{
    % store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/parallelepiped offset x}}
    \pgfmathsetlength\pgfutil@tempdimb{\pgfkeysvalueof{/pgf/parallelepiped offset y}}
    \def\ppd@offset{\pgfpoint{\pgfutil@tempdima}{\pgfutil@tempdimb}}
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathclose
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@ya}}{\ppd@offset}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\ppd@offset}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xa}{\pgf@yb}}{\ppd@offset}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\ppd@offset}}
  }
}
\makeatother

\begin{document}
\begin{tikzpicture}

\node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,minimum height=1.5cm, align=center] 
(1) at (0,0) {Block 1};
\node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm, minimum height=1.5cm, align=center] 
(2) at (4,0) {Block 2};

\draw[thin, -] (1) -- (2);

\end{tikzpicture}
\end{document}

Nach oben