4
$\begingroup$

I have an old notebook that uses the now obsolete Arrow package. For example, I have an expression containing

Arrow[{1,2}, {6,7}, HeadLength -> 0.005, HeadCenter -> 0.5]

I suppose I know how to translate this in absence of options. I should have

Arrow[{{1,2}, {6,7}}]

but how can I obtain the same arrow shape as given by the old-style options using Arrowheads?

$\endgroup$

1 Answer 1

9
$\begingroup$

You can replace old arrows to new with the following pattern

arw = Arrow[pt__List, opts : OptionsPattern[]] :> 
  {Arrowheads[HeadLength] /. {opts, HeadLength -> Automatic}, Arrow[{pt}]};

Graphics[Arrow[{1, 2}, {6, 7}, HeadLength -> 0.1]] /. arw
Graphics[{Arrowheads[0.1], Arrow[{{1, 2}, {6, 7}}]}]

enter image description here

Arrowheads specifies the length of arrowheads as a fraction of the total width of the graphic. If you need another behavior see this question.

To take into account HeadCenter and HeadWidth you can specify your own graphics for the arrowheads

arw2 = Arrow[pt__List, opts : OptionsPattern[]] :> 
 {Arrowheads[{{HeadLength, Automatic, 
    Graphics@{EdgeForm[Black], Polygon@{{-1, HeadWidth/2}, {0, 0}, 
        {-1, -HeadWidth/2}, {-HeadCenter, 0}}}}}] /. 
    {opts, HeadLength -> Automatic, HeadCenter -> 1, HeadWidth -> 0.5}, 
  Arrow[{pt}]};

Show[Graphics[Table[Arrow[{0, 0}, {Sin[x], Cos[x]},
     HeadCenter -> x, HeadLength -> 0.1] /. arw2,
   {x, 0, 1.6, 0.2}],
  PlotRange -> {{-0.1, 1}, {-0.2, 1.1}}]]

enter image description here

It is very close to the original behavior

enter image description here

$\endgroup$
5
  • $\begingroup$ Thank you for the pattern, but I prefer not to use it and switch to the new format. I wonder were in the Help System they say that Arrowheads[{{a,b}}] has the same meaning of the old HeadLength->a and HeadCenter->b. $\endgroup$
    – enzotib
    Commented Nov 3, 2013 at 13:35
  • $\begingroup$ @enzotib I mean that the pattern will help you to automate the process of converting if you have a huge number of this arrows. $\endgroup$
    – ybeltukov
    Commented Nov 3, 2013 at 13:43
  • $\begingroup$ Ok, thanks again. But I am now realizing there is an interpretation error, because the old HeadCenter gave the position of the junction marked with the red circle in this image: dl.dropboxusercontent.com/u/503888/arrow.png $\endgroup$
    – enzotib
    Commented Nov 3, 2013 at 13:58
  • $\begingroup$ @enzotib OK, now I understand better. See my update! $\endgroup$
    – ybeltukov
    Commented Nov 3, 2013 at 15:26
  • $\begingroup$ This is exactly what I was looking for. $\endgroup$
    – enzotib
    Commented Nov 3, 2013 at 15:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.