Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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


share|improve this question
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. –  Martin Scharrer May 2 '11 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 '11 at 11:30
You could define scalars with \newcommand. –  Caramdir May 2 '11 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];
share|improve this answer
! Package tikz Error: Cannot parse this radius. (line 7) –  Nils May 2 '11 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. –  Martin Scharrer May 2 '11 at 11:37
@Nils: it turns out that we use different versions of PGF (I use v2.10). –  Dmitry Volosnykh May 2 '11 at 13:44
@Martin: Thank you for your comment, I've changed my answer accordingly. –  Dmitry Volosnykh May 2 '11 at 13:51
@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 '11 at 14:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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