[Tex/LaTex] How to nest coordinate calculations in TikZ

calculationstikz-pgf

Why does this not work? I'm not using LaTeX and TikZ very much; I don't see it.

\begin{tikzpicture}
\coordinate (Zero)  at (0,0);
\coordinate[label=below:cell a] (vertexA) at (0, 10);
\coordinate[label={above right:cell b}, label={below right:cell c}] 
           (vertexB) at (5, 8);
\coordinate(vertexC) at (2.5, 0);
\coordinate(vertexD) at (12, 4);

\coordinate (centroidCellA) at  ($ 1/3*((vertexA)+(vertexB)+(vertexC)) $);       
\end{tikzpicture}

I get

! Package pgf Error: No shape named (vertexA is known.

Best Answer

The syntax for coordinate calculations is

<factor>*<coordinate><modifiers>

The problem is that (vertexA)+(vertexB)+(vertexC) is not a coordinate. You have to tell tikz that you want it to calculate the coordinate at (vertexA)+(vertexB)+(vertexC). This will work:

\coordinate (centroidCellA) at  ($ 1/3*($(vertexA)+(vertexB)+(vertexC)$) $);

(You can nest coordinate calculations).

Related Question