
The answer is updated in accordance with Hany's remark, "I want the
tangent at point 1 to end at y axis with a node containing some text".
There are two decorations tanget at and tangent vector at. The main one is the former and is used for the points 1 and 2. The later, used for 3, is simpler and indicates the sens in which TikZ goes along the curve.
Some comments concerning tanget at
- It has three arguments:
#1 is a sub-unitary float which determines
the point on the curve; #2 and #3 are multiplicative constants.
- It draws a tangent (segment) line at
#1. Think about #1 as being a value of the time coordinate describing the curve with constant speed.
- The length of the tangent line is
determined by the two multiplicative constants:
#2 represents the length (in length units, cm by default) of the tangent semi-line in the
negative direction. The same for #3, but in the positive one.
- As a side effect,
tangent at sets the following names to points
involved in the construction:
(point-k) the point on the curve defined by #1
(tpoint-k) the point on the tangent line such that (tpoint-k) - (point-k) is the unit tangent vector in the positive direction (see also tangent vector at)
(A-k) and (B-k) the extremities of the tangent line.
The integer k stands for the index of the point in the sequence of invocations of tangent at. In the above drawing k is 1 or 2.
Remark
You can play with the arguemnts #2 and #3 to have the tangent line you want at the point #1. Then use (A-k) and/or (B-k) to insert the text you need. It might be easier to draw the point (A-k) before looking for the perfect value of #2.
The code
\documentclass[11pt, border=.4cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, math}
\usetikzlibrary{decorations.markings}
\begin{document}
\tikzset{
tangent vector at/.style={
decoration={
markings, % switch on markings
mark = at position #1 with {
\filldraw[red] (0, 0) circle (1.5pt) ++(0, 1.5ex)
node[scale=.8]
{\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}};
\draw[red, ->] (0, 0) -- (1, 0);
}
}, postaction=decorate
},
tangent at/.style args={#1;#2|#3}{%
decoration={
markings, % switch on markings
mark = at position #1 with {
\path (0, 0) coordinate
(point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number});
\path (1, 0) coordinate (tpoint-%
\pgfkeysvalueof{/pgf/decoration/mark info/sequence number});
\filldraw[blue] (0, 0) circle (1.5pt) ++(0, 1.5ex)
node[scale=.8]
{\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}};
\draw[blue] (-#2, 0)
coordinate (A-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number})
-- (#3, 0)
coordinate (B-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number});
}
}, postaction=decorate
}
}
\begin{tikzpicture}[every node/.style={scale=.8}]
\begin{scope}[gray, very thin, ->]
\draw (-1, 0) -- (5.5, 0) node[right] {$x$};
\draw (0, -1) -- (0, 3.5) node[above] {$y$};
\end{scope}
\draw[tangent at={.4; 1.92|2}, tangent at={.77; 1|1.1},
tangent vector at=.02]
(-1, 1) .. controls +(2, 2.3) and +(3, 3) .. ++(4.5, -1.5);
\filldraw (A-1) circle (1.5pt) node[above left] {Some text};
% a curve through the first point
\draw[red] (point-1) to[out=210, in=90] ++(0, -2);
\end{tikzpicture}
\end{document}
markingswhich comes with an adapted relative frame (i.e. tangent and normal vectors) to the curve at the point. If the point is not on the curve, the problem is difficult, in general, even from a computational point of view. – Daniel N May 14 '22 at 16:32