Arrows in metapost

How to make arrows in the centre of the line rather than at the end of the line, and how to make a double arrowhead.

First, an arrowhead in the middle of the line:

	% Draw the path P with a single arrow in the middle of it.
	def goto( expr p ) =
		begingroup;
			path m_q, m_c, m_r;
			draw p;
			drawarrow subpath (0, (1/2)*length(p)) of p;
		endgroup;
	enddef;

Next, a double arrowhead:

	def gotoT( expr p ) =
		begingroup;
			path m_q, m_c, m_r;
			draw p;
			m_c = fullcircle scaled ahlength shifted point 1/2*length(p) of p;
			%draw m_c withpen pencircle scaled 0.25pt;
			% See MetaPost manual pp. 28.
			m_q = p cutbefore m_c;
			drawarrow cuttings;
			
			m_r = p cutafter m_c;
			drawarrow subpath (0, xpart((reverse p) intersectiontimes m_c ) ) of p;
		endgroup;
	enddef;

Home | More stuff | Octad of the week