Tikz: Extract polar coordinate

coordinatestikz-pgf

Is there a (simple) way to extract polar coordinates in Tikz?

Motivation: I define two points (a) and (b) as intersection of a line and a circle (center at the origin) and then I want to an arc between these two points along my circle. I need the polar coordinates of (a) and (b) for that.

I have seen in the TikZ documentation that there is \pgfextractx{<dimension>}{<point>} to extract the x-coordinate, and a similar function for the y-coordinate as well, but could not find something for polar coordinates.

Best Answer

You can define your own macro analogous to \pgfgetlastxy to extract the last cartesian coordinates, convert them into polar coordinates and store the resulting values in macros:

(Thanks to @John Kormylo the macro below has gradually become the short and crisp piece of code it is now. It only needs the tikz package without any additional libraries.)

\documentclass[border=1mm, tikz]{standalone}

\newcommand{\pgfgetlastpolar}[2]{
    \pgfgetlastxy{\tempx}{\tempy}
    \pgfmathsetmacro{#1}{atan2(\tempy,\tempx)}
    \pgfmathsetlengthmacro{#2}{veclen(\tempx,\tempy)}
}

\begin{document}
\begin{tikzpicture}

\node[draw, circle] at (1,1) {};

% use analogous to `\pgfgetlastxy{\myx}{\myy}ยด 
\pgfgetlastpolar{\mytheta}{\myrho}

\node[draw, rectangle] at (\mytheta:\myrho) {};

\end{tikzpicture}
\end{document}
Related Question