5

I would like to avoid setting too many of the values for the following picture too rigidly. For example, I would like to be able to set the position of point A and forever after that be able to retrieve the distance from other points to A through the \path ... let ... in ... structure.

Here's my MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\begin{document}

\begin{tikzpicture}[x=0.5cm,y=0.5cm]
    \draw[help lines,blue!20,step=1] (0,0) grid (12,12);

    \draw[fill]  (0,0) coordinate [label=180:Z] (Z) circle (2pt);           %% center of the picture
    \draw[fill]  (5,5) coordinate [label=135:Q] (Q) circle (2pt);           %% center of the circle
    \draw[fill]  (Q) -- +(  0:7)   coordinate [label=0:A] (A) circle (2pt); %% first point on the circle
    %% drawing the circle
    \draw[blue]  (A) 
                 let \p1 = ($ (A) - (Q) $) in
                 arc(0:360:{veclen(\x1,\y1)});

    %% these lines do work, but I don't want to explicitly state the radius as "7"
    %% BEGIN <remove these lines>
    \draw  [line width=0.4pt,red]           
           (Q) -- +(320:7) 
           coordinate (B) circle (2pt);
    %% END <remove these lines>

    %% after removing the above lines, uncomment the following lines to get error.
    %% no matter how I try to tweak these line, I can't get it to work
    %% \draw [line width=0.4pt,red]
    %%       let \p1 = ($(A) - (Q)$) in
    %%       (Q) -- +(320:{veclen(\x1,\y1)}) 
    %%       coordinate (B) circle (2pt);

    \draw[purple,line width=0.4pt] 
          (B) -- +($  (0,0) ! 2em ! 0 : ($(B)-(Q)$)  $)  
          coordinate [label=center:B] (Bl) circle (6pt);

    \draw[blue]   
          ($ (B) ! 0.45 ! (Q) $) 
          coordinate (tC) circle (2pt);

    \draw[line width=1.5em,->]
          (tC) 
          let \p1 = ($(tC) - (Q)$) in
              arc ({atan2(\x1,\y1)}:{atan2(\x1,\y1)+90}:{veclen(\x1,\y1)});

\end{tikzpicture}

\end{document}

enter image description here

After removing the lines I've flagged to be removed and uncommenting the following block of code, I get the following error:

! Package tikz Error: Giving up on this path. Did you forget a semicolon?.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.30               (Q) -- +(320:{veclen(\x1,\y1)})

? 

In case I'm being unclear about what to remove and what to uncomment, here's the MWE which produces this error.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\begin{document}

\begin{tikzpicture}[x=0.5cm,y=0.5cm]
    \draw[help lines,blue!20,step=1] (0,0) grid (12,12);

    \draw[fill]  (0,0) coordinate [label=180:Z] (Z) circle (2pt);           %% center of the picture
    \draw[fill]  (5,5) coordinate [label=135:Q] (Q) circle (2pt);           %% center of the circle
    \draw[fill]  (Q) -- +(  0:7)   coordinate [label=0:A] (A) circle (2pt); %% first point on the circle
    %% drawing the circle
    \draw[blue]  (A) 
                 let \p1 = ($ (A) - (Q) $) in
                 arc(0:360:{veclen(\x1,\y1)});

    %% PROBLEMATIC LINES
    \draw [line width=0.4pt,red]
          let \p1 = ($(A) - (Q)$) in
          (Q) -- +(320:{veclen(\x1,\y1)}) 
          coordinate (B) circle (2pt);

    \draw[purple,line width=0.4pt] 
          (B) -- +($  (0,0) ! 2em ! 0 : ($(B)-(Q)$)  $)  
          coordinate [label=center:B] (Bl) circle (6pt);

    \draw[blue]   
          ($ (B) ! 0.45 ! (Q) $) 
          coordinate (tC) circle (2pt);

    \draw[line width=1.5em,->]
          (tC) 
          let \p1 = ($(tC) - (Q)$) in
              arc ({atan2(\x1,\y1)}:{atan2(\x1,\y1)+90}:{veclen(\x1,\y1)});

\end{tikzpicture}

\end{document}

Why is it just this particular \path ... let ... in that's failing?

Incidentally

I don't like how the arrow is oriented. Recently, there was a post on this site which explalined how to correct such arrows. But no matter how much I've searched, I can't seem to find it. Anyone know the link?

1 Answer 1

4

You can use either

\draw [line width=0.4pt,red]
      let \p1 = ($(A) - (Q)$) in
      (Q) -- ([shift=(320:{veclen(\x1,\y1)})] Q) 
      coordinate (B) circle (2pt);

or

\draw [line width=0.4pt,red]
      let \p1 = ($(A) - (Q)$), \n1={veclen(\x1,\y1)} in
      (Q) -- ++(320:\n1)
      coordinate (B) circle (2pt);

I got your example to work with

\draw [line width=0.4pt,red]
      let \p1 = ($(A) - (Q)$) in
      (Q) -- ++(320:({veclen(\x1,\y1)})
      coordinate (B) circle (2pt);

Note that there are two opening parenthesis ( but only one closing ) one (not counting the ones from veclen. This does look like a bug to me.

6
  • Why do I not need to take the same approach with my other \path ... let ... in structures?
    – A.Ellett
    Commented Feb 16, 2013 at 23:56
  • @A.Ellett Take a look at my updated answer. The arc path operator forwards its arguments to the PGF math engine (as does the one you used). Apparently there is some mix-up in the parentheses-parsing process. Commented Feb 17, 2013 at 0:08
  • 1
    @A.Ellett Looks like you've hit this one (though fixed in the CVS ersion) tex.stackexchange.com/questions/41828/using-math-in-tikz
    – percusse
    Commented Feb 17, 2013 at 0:09
  • Thanks Qrrbrbirlbel and thanks @percuße for your link, very informative. Either of you know how to find the post about modifying the positioning of arrows?
    – A.Ellett
    Commented Feb 17, 2013 at 0:14
  • @percuße. What is CVS?
    – A.Ellett
    Commented Feb 17, 2013 at 0:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .