[Tex/LaTex] TikZ Coordinate calculation – calculate coordinates separately

calculationstikz-pgf

I'm trying to calculate coordinates based on existing coordinates but each coordinate individually.

The first thing which is unclear to me is how to define scalar variables. I can define coordinates using the \coordinate command, but what about scalars?

Looking through the manual I found the \pgfextractx command, but I don't know how to use it, is it possible to use it within a coordinate calculation like for example

\coordinate(blah) at ($ (\pgfextractx{(centre)} + 2*cos(30), .. )$)

?

Best Answer

It is possible to do by means of let operation:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
    \fill[blue] (0,0) coordinate (centre) circle[radius=1pt];
    \fill[red] let \p1=(centre) in
        ({\x1 + 2 * cos(30)}, \y1) circle[radius=1pt];
\end{tikzpicture}
\end{document}
Related Question