Asymptote FAQ - Section 5
Questions about arrows


Question 5.1. How do I draw two arrows at arbitrary positions along a path?

Assuming that at least one of the arrowheads is to be filled, you can do this:
size(200); 
path g = (0,0)..(1,3)..(3,0); 
draw(g,Arrow(Relative(0.9))); 
add(arrow(g,invisible,FillDraw(black),Relative(0.5))); 
add(arrow(reverse(g),invisible,FillDraw(white,black),Relative(0.9))); 
If both of the arrowheads are to be drawn with filltype NoFill, one will need to create a specialized version of the arrow routine in plain_arrows.asy:
void arrow(frame f, arrowhead arrowhead=DefaultHead,
           path g, pen p=currentpen, real size=0,
           real angle=arrowangle, filltype filltype=arrowhead.defaultfilltype,
           position position=EndPoint, bool forwards=true,
           margin margin=NoMargin, bool center=false);

Question 5.2. How do I reverse the direction of an arrowhead?

Simply reverse the direction of the path.
path g=((0,0)--(5cm,0));
draw(reverse(g),Arrow(Relative(0.55)));

Question 5.3. How do I change the size of all arrows?

To override the arrowsize you can give every Arrow drawing attribute a real size argument. If you want to do this globally, you can override the pen-dependent arrowsize function like this:
DefaultHead.size=new real(pen p=currentpen) {return 2mm;};

Question 5.4. Can I create other arrowhead styles?

Yes, you can build custom arrowheads like this (see the predefined arrowhead styles in plain_arrows.asy for further examples):
arrowhead DotHead;
DotHead.head=new path(path g, position position=EndPoint, pen p=currentpen,
                      real size=0, real angle=arrowangle) {
  if(size == 0) size=DotHead.size(p);
  bool relative=position.relative;
  real position=position.position.x;
  if(relative) position=reltime(g,position);
  path r=subpath(g,position,0);
  pair x=point(r,0);
  real t=arctime(r,size);
  pair y=point(r,t);
  return circle(0.5(x+y),0.5size);
};

size(100);
draw((0,0)..(1,1)..(2,0),Arrow(DotHead));
dot((2,0),red);
If you submit your alternate arrowheads to the Forum or the Patch Tracking System, we'll consider including them in a future release.
Next: Questions about 2D graphs.
Back: Questions about labels.
Return to contents.

Asymptote - 2024-10-07

Extracted from Asymptote Frequently Asked Questions, Copyright © 2024 .