Je ne sais pas si c'est le meilleur moyen, mais c'en est un :-)
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing}
\begin{document}
L'idée vient de cette décoration :
\begin{tikzpicture}[>=stealth, every node/.style={midway, sloped, font=
\tiny},
decoration={show path construction,
moveto code={
\fill [red] (\tikzinputsegmentfirst) circle (2pt)
node [fill=none, below] {moveto};},
lineto code={
\draw [blue,->] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast)
node [above] {lineto};
},
curveto code={
\draw [green!75!black,->] (\tikzinputsegmentfirst) .. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
..(\tikzinputsegmentlast) node [above] {curveto};
},
closepath code={
\draw [orange,->] (\tikzinputsegmentfirst) --
(\tikzinputsegmentlast)
node [above] {closepath};}
}]
\path[decorate] (1,0) rectangle ++(1,2);
\end{tikzpicture}
On la transforme en...
\tikzset{%
make middle of lineto a coordinate/.style = {%
postaction = {%
/utils/exec = {\xdef\CoordCountMacro{0}},
decorate,
decoration = {%
show path construction,
lineto code = {%
\show\CoordCountMacro
\xdef\CoordCountMacro{\number\numexpr\CoordCountMacro+1\relax}%
\path (\tikzinputsegmentfirst) -- node[coordinate]
(Middle-\CoordCountMacro) {} (\tikzinputsegmentlast);},
closepath code={%
\xdef\CoordCountMacro{\number\numexpr\CoordCountMacro+1\relax}%
\path (\tikzinputsegmentfirst) -- node[coordinate]
(Middle-\CoordCountMacro) {} (\tikzinputsegmentlast);}}}}}
\begin{tikzpicture}
\draw[make middle of lineto a coordinate] (1,0) rectangle ++(1,2);
\foreach \i in {1,...,4} {%
\node[circle,fill,red,inner sep=2pt,label=above:$A_\i$] at (Middle-\i)
{};}
\end{tikzpicture}
et voilà...
\end{document}
--
Christophe