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), .. )$)


  • What do you mean exactly with "calculate coordinates based on existing coordinates but each coordinate individually"? I have the feeling you use "coordinate" for both \coordinate and the X and Y part of it, which makes the question quite difficult to read. May 2, 2011 at 9:52
  • Agree this was somewhat confusing, I just want to access the x and y part of it separately instead of, let's say just multiply the coordinate vector with a scalar.
    – Nils
    May 2, 2011 at 11:30
  • You could define scalars with \newcommand.
    – Caramdir
    May 2, 2011 at 14:57

1 Answer 1


It is possible to do by means of let operation:


    \fill[blue] (0,0) coordinate (centre) circle[radius=1pt];
    \fill[red] let \p1=(centre) in
        ({\x1 + 2 * cos(30)}, \y1) circle[radius=1pt];
  • ! Package tikz Error: Cannot parse this radius. (line 7)
    – Nils
    May 2, 2011 at 11:13
  • It's a bad idea to use \pgfmathresult inside a coordinate. This macro is overwritten by any pgfmath operation. It is much saver to use \pgfmathsetmacro\myresult{...} instead of \pgfmathparse{...} and then \myresult pt as X-coordinate. Note that \pgfmathresult is in pt but without the unit, so just using it alone will give you wrong results except when x=1pt is in affect. May 2, 2011 at 11:37
  • @Nils: it turns out that we use different versions of PGF (I use v2.10). May 2, 2011 at 13:44
  • @Martin: Thank you for your comment, I've changed my answer accordingly. May 2, 2011 at 13:51
  • 1
    @Dmitry: One can simply write ({\x1 + 2 * cos(30)}, \y1). (Note the additional braces and that \x1 already contains the unit pt.)
    – Caramdir
    May 2, 2011 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.