3

I want to place two points on a trajectory, drawn as a curved line. I have manage to draw my curved line using controls. So i have this image :

enter image description here

with the following code :

\begin{tikzpicture}
\draw (4,3) .. controls +(0,-2) and +(0.2,1) .. (5,0) ;

\draw (4,3) node[above]{$M$};
\draw (4,3) node{$\bullet$};
\draw (5,0) node[below]{$P$};
\draw (5,0) node{$\bullet$};
\end{tikzpicture}

However, I would like M and P to be only points of my trajectory, not its bound. Therefore, I would like to have them on the curve, but maybe M at y=2 and P and y=1. Is there a simple way to do that, that is, not adjusting mm by mm the position ?

1 Answers1

6

There are various solutions for my problem, all discovered with the help of Paul Gaborit's comment.

I list three solutions, two of them do not need any additional library, one require the intersections library

Without any additional library

The easiest solution consists on usgin in-built positioning options, that allow to mark a node with various combination of midway, at start, at end, near start, very near start and so on (I have not found a complete list...).

In this case, the code

\begin{tikzpicture}
\draw (4,3) .. controls +(0,-2) and +(0.2,1) .. (5,0) 
    node[near end] {$\bullet$}
    node[near end, right] {$P$}
    node[very near start] {$\bullet$}
    node[very near start, right] {$M$};
\end{tikzpicture}

yields me

enter image description here

These commands are in fact just particular values of a more general one, the pos option, that takes value in [0,1]. You can specify wherever you want your point on your line. I therefore get my desired result with this code :

\begin{tikzpicture}
\draw (4,3) .. controls +(0,-2) and +(0.2,1) .. (5,0) 
    node[pos=0.8] {$\bullet$}
    node[pos=0.8, right] {$P$}
    node[pos=0.1] {$\bullet$}
    node[pos=0.1, right] {$M$};
\end{tikzpicture}

enter image description here

With the intersections library

So first, one needs to add \usetikzlibrary{intersections}

The above solutions enable to place the point everywhere, but do not allow to place it at a specific coordinate. If I want for instance the intersection of my curved line and the y=2.5 line, one needs the follonwing code :

\begin{tikzpicture}
\path[name path=y2] (4,2.5)--(5,2.5);
\path[name path=y1] (4,0.5)--(5,0.5);
\draw[name path=trajectory] (4,3) .. controls +(0,-2) and +(0.2,1) .. (5,0);

\fill name intersections={of=y2 and trajectory} circle (2pt) node[right] {$M$}; \fill name intersections={of=y1 and trajectory} circle (2pt) node[right] {$P$}; \end{tikzpicture}

Important points are : you need to name the objects you want to intersect, and to precise the number of your intersection (here only (intersection-1) as there is just one).

The section Intersections of Arbitrary Paths in the Tikz-pgf manual gives more complex illustrations.

enter image description here