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}
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}
x
coordinate of where you want to extract the point) withdraw=none
but name it, and then use theintersections
library to find the intersection of this vertical line with the given curve. An example is given in Intersections in PGFplots, and TikZ: Intersection of two lines\fill
command you are using in the marking. More generally, exactly how you extract the coordinates will depend somewhat on how you specify the point. How do you want to do that?coordinate (name)
then you have a handle,name
, by which you can refer to the point so you can write\draw[red] (B) -- ++(5,1);
without needing\gettikzxy
at all. Do you want to do anything more complicated with the coordinates than just refer to them? If not, you don't need anything more complicated than the above.