[Tex/LaTex] Extract x, y coordinate of an arbitrary point on curve in TikZ

tikz-pgftikz-styles

We have very nice
Extract x, y coordinate of an arbitrary point in TikZ

\documentclass{article}
%\url{https://tex.stackexchange.com/q/33703/86}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\makeatletter
\newcommand{\gettikzxy}[3]{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \edef#2{\the\pgf@x}%
  \edef#3{\the\pgf@y}%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (2,1);
\gettikzxy{(A)}{\ax}{\ay}
\fill[red] (\ax,\ay) circle (5pt);

\tikzset{-dot-/.style={decoration={
  markings,
  mark=at position #1 with {\fill circle (2pt);}},postaction={decorate}}} %%% in this line added a ;

\begin{tikzpicture}
 \draw[-dot-=.5] (0,0) to [bend left] (2,4);
 \draw[-dot-=.8] (0,0) to [bend right] (2,4);
\end{tikzpicture}

\end{tikzpicture}
\end{document}

Is it possible to extract x, y coordinate of a point located on the curve? These points can be used for doing some other tasks.

New Answer: Thanks to all

\documentclass{article}
\usepackage{tikz}
\makeatletter
\newcommand{\gettikzxy}[3]{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \edef#2{\the\pgf@x}%
  \edef#3{\the\pgf@y}%
}
\makeatother

%
\begin{document}
%
\begin{tikzpicture}
\draw (0,0) to [bend left=20]  coordinate[pos=0.7] (A)(2,4);
\draw (0,0) to [bend right=20]  coordinate[pos=0.2] (B)(2,4);
\draw[thick,red] (A) -- (B);
\gettikzxy{(A)}{\ax}{\ay}
\gettikzxy{(B)}{\bx}{\by}
\fill[blue] (\ax, \ay) circle (2pt);
\fill[blue] (\bx, \by) circle (2pt);
\draw[thick,green] (A) -- (\bx,\ay) -- (B);
\draw[thick,yellow] (A) -- (\ax,\by) -- (B);
%
\end{tikzpicture}
%
\end{document}  

enter image description here


Thank you Andrew Stacey…

Now I got a better MWE and using:

\tikzset{pontoncurve/.style={decoration={
  markings,
  mark=at position #1 with {\coordinate (B);}},postaction={decorate}}}

I get the coordinate. But I do not know to change B in \coordinate (B). Should I use \newcommand like \gettikzxy?

\newcommand{\gettikzxy}[3]{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \edef#2{\the\pgf@x}%
  \edef#3{\the\pgf@y}%
}
\documentclass{article}
%\url{https://tex.stackexchange.com/q/33703/86}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\makeatletter
\newcommand{\gettikzxy}[3]{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \edef#2{\the\pgf@x}%
  \edef#3{\the\pgf@y}%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (2,1);
\gettikzxy{(A)}{\ax}{\ay}
%\fill[red] (\ax,\ay) circle (5pt);

\tikzset{-dot-/.style={decoration={
  markings,
  mark=at position #1 with {\fill circle (2pt);}},postaction={decorate}}} %%% in this line added a ;

\tikzset{pontoncurve/.style={decoration={
  markings,
  mark=at position #1 with {\coordinate (B);}},postaction={decorate}}}

\begin{tikzpicture}
 \draw[pontoncurve=.5] (0,0) to [bend left] (2,4);
\gettikzxy{(B)}{\bx}{\by}
\draw[red] (\bx,\by) -- ++(5,1);

 \draw[-dot-=.8] (0,0) to [bend right] (2,4);
\end{tikzpicture}

\end{tikzpicture}
\end{document}

Best Answer

You don't need the library decorations.markings and you don't need the macro gettikzxy in your examples; perhaps with other examples, it's useful to work like this.

First \pgfgetlastxy{\ax}{\ay} is enough after

 \coordinate (A) at (2,1); 
  \pgfgetlastxy{\ax}{\ay}  

Instead of

  \draw[-dot-=.5] (0,0) to [bend left]  (2,4);

you have

   \draw (0,0) to [bend left]  coordinate[pos=.5] (B)(2,4);  

Now if you want to get the coordinates, you have several ways like

 \path (B);\pgfgetlastxy{\bx}{\by}  

A complete code

\documentclass{article}
\usepackage{tikz}

\begin{document} 

\begin{tikzpicture}
\coordinate (A) at (2,1);
\pgfgetlastxy{\ax}{\ay}    
\fill[red] (\ax,\ay) circle (5pt);
\end{tikzpicture} 

\begin{tikzpicture}
 \draw (0,0) to [bend left]  coordinate[pos=.5] (B)(2,4);
 \draw (0,0) to [bend right] coordinate[pos=.8] (C)(2,4);
  \path (B);\pgfgetlastxy{\bx}{\by} 
  \path (C);\pgfgetlastxy{\cx}{\cy} 
  \draw[red,thick] (\bx,\by)--(\cx,\cy) ;
\end{tikzpicture}

\end{document}  

Perhaps you need to add another example to get a better answer.

Remark

You can get the coordinates like this with the curveto operation and now with the CVS version, it's possible with the arc operation.