# nodes vs coordinates. lines are drawn inside nodes

The plot tries to draw the joints and links of a robotic manipulator. Initially I defined the points for the joints as nodes and this resulted in some shift when lines were later drawn between them. Based on answers from SE, I changed this into a three step process where I first defined coordinates, then drew joints at the coordinates and later connected them with lines.

However, now the lines go inside the joint. I want to have the property of nodes where lines are drawn only upto node's borders and the property of coordinates where the lines are drawn exactly to the coordinate? (I realise that I can simply draw the joints after drawing the links thereby overwriting them, but i prefer to have the nodes as unfilled circles as in this figure for other reasons)

How do I achieve this.

MWE and results with nodes and coordinates below.

\documentclass[tikz]{standalone}
\usetikzlibrary{math}
\begin{document}
\foreach \mynodes/\numnodes in {{1/0,2/90,3/0}/3}{%
\begin{tikzpicture}[scale=1]
\draw (-1,-1) [help lines] grid (3,2);

% define coordinates for joints
\node (0,0)(n0){};
\path (0,0)
foreach \nodeid/\nodeangle in \mynodes{
++(\nodeangle:1) node(n\nodeid){}
};

\draw [red, ultra thick](0,0)
foreach \nodeid in {1,...,\numnodes}{
-- (n\nodeid)
};

%draw joints
\foreach \nodeid in {0,1,...,\numnodes}{%
};

\end{tikzpicture}
}
\end{document}


with coordinates

with nodes

Another possibility is "one-step" approach, which is (to my opinion) more clear and simple. For it I use TikZ library calc:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[
every node/.style = {circle, draw=red, thick,
minimum size=2mm, inner sep=0pt}
]
\draw (-1,-1) [help lines] grid (3,2);
% graph
\node (n1) at (0,0) {};
\foreach \nodeangle [count=\lastid from 1, count=\nodeid from 2] in {0,90,0}
{
\node (n\nodeid) at ($(n\lastid) + (\nodeangle:10mm)$) {};
\draw (n\lastid) -- (n\nodeid);
}
\end{tikzpicture}
\end{document}


Result:

Edit: Above proposed solution has only one Tikz picture to contrary three in your approach. With it you have three independent pictures which overly each over other. In this some information for properly drawing of nodes seems to be lost.

• I am accepting this as the answer since this automatically accounts for larger and smaller node circles and since it is shorter code. – AJN Feb 14 '16 at 3:25

You could draw the path piecewise:

\documentclass[tikz]{standalone}
\usetikzlibrary{math}
\begin{document}
\foreach \mynodes/\numnodes in {{1/0,2/90,3/0}/3}{%
\begin{tikzpicture}[scale=1]
\draw (-1,-1) [help lines] grid (3,2);

% define coordinates for joints
\node (0,0)(n0){};
\path (0,0)
foreach \nodeid/\nodeangle in \mynodes{
++(\nodeangle:1) node(n\nodeid){}
};

\foreach \nodeid in {1,...,\numnodes}{
\draw [red, ultra thick](n\the\numexpr\nodeid-1) --(n\nodeid);
};

%draw joints
\foreach \nodeid in {0,1,...,\numnodes}{%
};

\end{tikzpicture}
}
\end{document}


May be you can consider using chains library for this kind of graphs. At the same time you add elements to the chain, joins between them are drawn.

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{chains}

\begin{document}

\begin{tikzpicture}[%
on grid,
scale=1,
start chain=going right,
every join/.style={thick, red, shorten >=1pt, shorten <=1pt},
item/.style={
draw,
thick,
on chain,
circle,
minimum size=3mm,
inner sep=0pt,
join
}
]
\draw (-1,-1) [help lines] grid (3,2);

\node [item] {};

\node [item] {};

\node [item, on chain= going above] {};

\node [item] {};

\end{tikzpicture}

\end{document}


Update

Using chains doesn't constrain any placement relation between nodes. It's possible to place all nodes and later on chain them, or just place them where you want while they are forming the chain and joining between them.

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{chains}

\begin{document}

\begin{tikzpicture}[%
scale=1,
start chain,
every join/.style={thick, red, shorten >=1pt, shorten <=1pt},
item/.style={
draw,
thick,
on chain,
circle,
minimum size=3mm,
inner sep=0pt,
join
}
]

\foreach \i in {1,...,5}
\node [item] (\i) at (3*rand,3*rand) {};

\end{tikzpicture}

\end{document}


• The real code has the robotic arm in various poses (and possibly even animation). I should have added non right angles in my MWE. – AJN Feb 14 '16 at 3:20
• @AJN There's no limitation in nodes placement using chains. Please, see a little example in updated answer. More details in section 46 from pgfmanual. – Ignasi Feb 14 '16 at 9:15