Graphics, Figures & TablesSpecifying end coordinates for node/path in TikZ

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
drgz
Posts: 44
Joined: Sat Apr 18, 2009 8:40 pm

Specifying end coordinates for node/path in TikZ

Post by drgz »

Hello,

trying to draw a block schematic for a digital predistortion system in TikZ, but I got some difficulties specifying the end coordinates for a path between two blocks.

The following code is what I got so far

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows,shapes}
\usepackage{amsmath}
\begin{document}

\tikzstyle{block} = [draw,minimum width=2em,minimum height=2em,line width=0.5pt]
\tikzstyle{LOblock} = [draw,minimum size=1em, line width=0.5pt]
\tikzstyle{LargeBlock} = [draw,minimum size=6em,line width=1pt]
\tikzstyle{SmallBlock} = [draw,minimum size=5em,line width=0.5pt]
\tikzstyle{recBlock} = [draw,minimum height=1em,minimum width=6em,line width=0.5pt,rotate=90]
\tikzstyle{PAblock}=[draw,isosceles triangle,minimum width=3em,minimum height=2em,line width=0.5pt]
\tikzstyle{AttBlock}=[draw,minimum width=4em,minimum height=1em,line width=0.5pt]

% diameter of semicircle used to indicate that two lines are not connected
\def\radius{.7mm} 
\tikzstyle{branch}=[fill,shape=circle,minimum size=3pt,inner sep=0pt]

\begin{tikzpicture}[>=latex']
			\node at (-0.5,-1) (input1) {$I[n]$};
			\node at (-0.5,-2) (input2) {$Q[n]$};
			\node at (11.5,-1.5) (output) {$y(t)$};
			\node[LargeBlock] at (2,-1.5) (dpdR) {};
			\node[SmallBlock] at (2,-1.5) (dpd) {DPD};
			\node[block] at (5,-1) (dac1) {DAC};
			\node[block] at (5,-2) (dac2) {DAC};
			\node[block] at (5,-4) (adc1) {ADC};
			\node[block] at (5,-5) (adc2) {ADC};
			\node[recBlock] at (7,-1.5) (iqmod) {I-Q mod.};
			\node[recBlock] at (7,-4.5) (iqdemod) {I-Q demod.};
			\node[LOblock] at (8.5,-3) (lo) {LO at $f_c$};
			\node[PAblock] at (9,-1.5) (pa) {};
			\node[AttBlock] at (9,-4.5) (att) {Attenuator};
			\draw[->] (input1) -- (dpdR.west |- input1);
			\draw[->] (input2) -- (dpdR.west |- input2);
			\draw[->] (dpdR.25) -- node[above]{$I_\text{PD}[n]$} (dac1);
			\draw[->] (dpdR.-25) -- node[above]{$Q_\text{PD}[n]$} (dac2);
			\draw[->] (dac1) -- (iqmod.north |- dac1);
			\draw[->] (dac2) -- (iqmod.north |- dac2);
			\draw[->] (iqmod) -- node[above]{$x(t)$} (pa);
			\draw[->] (iqdemod.north |- adc1) -- (adc1);
			\draw[->] (iqdemod.north |- adc2) -- (adc2);
			\draw[->] (adc1.west) -| node[above]{$I_o[n]$} (dpdR.south east);
			\draw[->] (adc2.west) -| node[above]{$Q_o[n]$} (dpdR.south west);
			\draw[->] (att) -- (iqdemod.south);
			\draw[->] (lo) -| (iqmod.west);
			\draw[->] (lo) -| (iqdemod.east);
			\draw[->] (pa) -- (output);
			\draw[->] (10.5,-1.5) |- (att.east);
			\path (pa.north)+(0.1,0.5) node (palabel) {Power Amplifier};
\end{tikzpicture}
\end{document}
Basically, I'd like to connect the (ADC1) and (ADC2) blocks to the (DPDR) block, at an equal distance to the right and left of the south center of the (DPDR) block, respectively. However, for some reason I can't figure out how I do this, so hopefully someone can point out what I need to add to fix this, at least I'd appreciate any help.

Best regards.

drgz

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

drgz
Posts: 44
Joined: Sat Apr 18, 2009 8:40 pm

Specifying end coordinates for node/path in TikZ

Post by drgz »

Solved. I needed to add the coordinates as a linear combination, using the calc library for TikZ to be able to specify ($(x,y)+(x0,y0)$).
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Specifying end coordinates for node/path in TikZ

Post by localghost »

At first, many thanks for this very good MWE which made working out a solution very easy.

As you already did for the same node, you can use again degree values to assign a connection point. If I understood you right, the code below should yield the desired result.

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows,shapes}
\usepackage{amsmath}

\begin{document}
	\tikzstyle{block} = [draw,minimum width=2em,minimum height=2em,line width=0.5pt]
	\tikzstyle{LOblock} = [draw,minimum size=1em, line width=0.5pt]
	\tikzstyle{LargeBlock} = [draw,minimum size=6em,line width=1pt]
	\tikzstyle{SmallBlock} = [draw,minimum size=5em,line width=0.5pt]
	\tikzstyle{recBlock} = [draw,minimum height=1em,minimum width=6em,line width=0.5pt,rotate=90]
	\tikzstyle{PAblock}=[draw,isosceles triangle,minimum width=3em,minimum height=2em,line width=0.5pt]
	\tikzstyle{AttBlock}=[draw,minimum width=4em,minimum height=1em,line width=0.5pt]

% diameter of semicircle used to indicate that two lines are not connected
	\def\radius{.7mm}
	\tikzstyle{branch}=[fill,shape=circle,minimum size=3pt,inner sep=0pt]

	\begin{tikzpicture}[>=latex']
		\node at (-0.5,-1) (input1) {$I[n]$};
		\node at (-0.5,-2) (input2) {$Q[n]$};
		\node at (11.5,-1.5) (output) {$y(t)$};
		\node[LargeBlock] at (2,-1.5) (dpdR) {};
		\node[SmallBlock] at (2,-1.5) (dpd) {DPD};
		\node[block] at (5,-1) (dac1) {DAC};
		\node[block] at (5,-2) (dac2) {DAC};
		\node[block] at (5,-4) (adc1) {ADC};
		\node[block] at (5,-5) (adc2) {ADC};
		\node[recBlock] at (7,-1.5) (iqmod) {I-Q mod.};
		\node[recBlock] at (7,-4.5) (iqdemod) {I-Q demod.};
		\node[LOblock] at (8.5,-3) (lo) {LO at $f_c$};
		\node[PAblock] at (9,-1.5) (pa) {};
		\node[AttBlock] at (9,-4.5) (att) {Attenuator};
		\draw[->] (input1) -- (dpdR.west |- input1);
		\draw[->] (input2) -- (dpdR.west |- input2);
		\draw[->] (dpdR.25) -- node[above]{$I_\text{PD}[n]$} (dac1);
		\draw[->] (dpdR.-25) -- node[above]{$Q_\text{PD}[n]$} (dac2);
		\draw[->] (dac1) -- (iqmod.north |- dac1);
		\draw[->] (dac2) -- (iqmod.north |- dac2);
		\draw[->] (iqmod) -- node[above]{$x(t)$} (pa);
		\draw[->] (iqdemod.north |- adc1) -- (adc1);
		\draw[->] (iqdemod.north |- adc2) -- (adc2);
		\draw[->] (adc1.west) -| node[above right]{$I_o[n]$} (dpdR.300);
		\draw[->] (adc2.west) -| node[above right]{$Q_o[n]$} (dpdR.240);
		\draw[->] (att) -- (iqdemod.south);
		\draw[->] (lo) -| (iqmod.west);
		\draw[->] (lo) -| (iqdemod.east);
		\draw[->] (pa) -- (output);
		\draw[->] (10.5,-1.5) |- (att.east);
		\path (pa.north)+(0.1,0.5) node (palabel) {Power Amplifier};
	\end{tikzpicture}
\end{document}

Best regards
Thorsten
drgz
Posts: 44
Joined: Sat Apr 18, 2009 8:40 pm

Re: Specifying end coordinates for node/path in TikZ

Post by drgz »

Thanks for the quick answer. I completely forgot about the degree approach although I had already used it. Just after I found out about "|- nodename" trick, I simply forgot about what I already had done for some stupid reason.

However, after some tweaking back and forth: as far I as understand, using a linear combination of coordinates may result in a more "consistent" result (if the coordinates are given relative to nodes, i.e. nodename.south/east/etc). With this I mean that if it is desirable to resize some of the blocks/objects in the figure at a later stage, the coordinates will still be valid if this approach is chosen. At least that is what I experienced when I tried to resize one of the blocks, giving me (ugly) sloped/skewed (or what to call it) paths instead.

Best regards,

drgz
Post Reply