# How to extract the direction of a point on a path in Tikz?

I am following some tips online to extract a certain point on a path as follows

\documentclass{article}
\usepackage{tikz,color}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}
\begin{tikzpicture}
\draw (0,2) to[out=-90,in=0] coordinate[pos=0.28](A)(-3,-1);
\draw [red] (0,2) to[out=-90] (A);
\fill[blue] (A) circle (2pt);
\end{tikzpicture}
\end{document}


Where A is the point of interest. I would like to draw another path that exact on the top of the given curve but just cover from (0,2) to A in red. To do so, I need to know the "in" direction at point A. I use asymptote before and it has a dir command to extract the direction of a path at a certain point, but I didn't see it in tikz.

p.s. Someone recommend me to redraw the path from (0,2) to A and from A to (-3,1) so I can control the direction at A. For my case, I would like to know a more generic method to extract the direction so I could program it for other complicate cases. Thanks.

The pgfplots library fillbetween has the option of accessing intersection segments. However, here you could just clip the relevant stretch of the path. To make things more convenient, one can use save path and use path to recycle the path.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}
\begin{tikzpicture}
\draw[save path=\pathA] (0,2) coordinate (start) to[out=-90,in=0] coordinate[pos=0.28](A)(-3,-1);
\draw [red] (0,2) to[out=-90] (A);
\begin{scope}
\clip[overlay] let \p1=($(A)-(start)$),\n1={veclen(\x1,\y1)} in
\draw[orange,thick,use path=\pathA];
\end{scope}
\end{tikzpicture}
\end{document}


Alternatively you can place A with decorations.markings and read out the rotation angle from the transformation matrix. (Note that things become more complicated if you scale x and y differently. Note also that this will in general not restore the precise sub path since a curve is not completely fixed by the in and out angles, there is also a looseness parameter.)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}
\begin{tikzpicture}
\path (0,0) coordinate (O) (1,0) coordinate (X);
\draw[postaction=decorate,decoration={markings,
mark=at position 0.28 with {\coordinate(A);
\pgfgettransformentries\tmpA\tmpB\tmpC\tmp\tmp\tmp
\pgfmathsetmacro{\myrot}{atan2(\tmpB,\tmpA)+180}%
\xdef\myrot{\myrot}%
}}]
(0,2) coordinate (start) to[out=-90,in=0] (-3,-1);
\draw [red] (0,2) to[out=-90] (A);
\draw[orange,thick] (start)  to[out=-90,in=\myrot] (A)
node[right]{in angle is $\myrot^\circ$};
\end{tikzpicture}
\end{document}


A more core level option is to use \pgfpathcurvebetweentime from p. 1095 of the pgfmanual v3.1.5. Here is a very basic option that uses the show path construction decoration to get the curve start, end and control points in. This can be made more TikZy, of course, but here is the basic thing. The subcurve style takes three parameters: a set of pgf instructions that indicate what to do with the path, the start time and the end time.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\tikzset{subcurve/.style n args=3{decoration={show path construction,
moveto code={},
lineto code={},
curveto code={
\typeout{\tikzinputsegmentfirst}
\path (\tikzinputsegmentfirst) coordinate (tikzinputsegmentfirst)
(\tikzinputsegmentsupporta) coordinate (tikzinputsegmentsupporta)
(\tikzinputsegmentsupportb) coordinate (tikzinputsegmentsupportb)
(\tikzinputsegmentlast) coordinate (tikzinputsegmentlast);
\pgfpathcurvebetweentime{#2}{#3}{\pgfpointanchor{tikzinputsegmentfirst}{center}}%
{\pgfpointanchor{tikzinputsegmentsupporta}{center}}%
{\pgfpointanchor{tikzinputsegmentsupportb}{center}}%
{\pgfpointanchor{tikzinputsegmentlast}{center}}%
#1
\pgfusepath{stroke}
},
closepath code={}
},decorate}}

\begin{document}
\begin{tikzpicture}
\path (0,0) coordinate (O) (1,0) coordinate (X);
\draw[postaction={subcurve={\pgfsetstrokecolor{red}\pgfsetlinewidth{1pt}}{0}{0.28}}]
(0,2) coordinate (start) to[out=-90,in=0]
coordinate[pos=0.28](A)(-3,-1);
%\draw [red] (0,2) to[out=-90] (A);

• @user1285419 Yes, as I wrote the curve is not completely specified by the in and out angles. If you use \draw [red] (0,2) to[out=-90,in=\myrot,looseness=0.9] (A); it will match. The angles is correct, I believe, but if you take a subpath you need also to adjust the looseness.