This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Add-ons / Standard Packages / Graphics  /


It is possible to create in top-level Mathematica code a graphic representing a two-dimensional arrow. However, since such a graphic is in the standard Mathematica coordinate system, it does not maintain its aspect ratio when the aspect ratio of the coordinate system is changed. This can lead to a rather odd looking arrow. This package implements a new graphics primitive to generate arrows that can maintain their aspect ratio, and can be quite flexible.

The Arrow graphics primitive.

The Arrow primitive behaves much as built-in Graphics primitives. It obeys color directives, and the line of the arrow follows thickness and dashing directives.

  • This loads the package.
  • In[1]:= <<Graphics`Arrow`

  • Here is a simple example of two arrows in different colors.
  • In[2]:= Show[Graphics[{Arrow[{0, 0},{1, 1}],
    Hue[0], Arrow[{.75, .25},{.25, .75}]}]]

  • We can even place arrows in options.
  • In[3]:= Plot[Sin[x], {x, 0, 2Pi},
    Epilog -> {Arrow[{4, .25}, {Pi/2, 1}],
    Text["Here", {4, .15}, {0, -1}]}

    Options for the Arrow primitive.

    There are several options that can be used to adjust the style of the arrowhead. HeadScaling determines the scaling of the coordinate system used in drawing the arrowhead. When it is Automatic, the coordinate system is centered at the tip of the arrow, and is rotated to lie along the arrow (with the negative direction towards the tail of the arrow). It is scaled by the default attributes coordinate scaling, where the distance across the bottom of the graphic is one unit. This allows the arrowheads to be scaled directly to the size of the graphic. When it is Relative, the coordinate system is scaled so that

    0,0 is at the head of the arrow, and

    0,-1 is at the tail of the arrow. This means that the size of a given arrowhead will vary with the length of the arrow. When HeadScaling is Absolute, the device coordinate scaling is used, centered at the head of the arrow, and rotated along the arrow. In this coordinate system, units are identical to those used by the standard graphics directives AbsoluteDashing and AbsoluteThickness. Whichever coordinate system is being used must be taken into account when specifying a style of arrowhead other than the default.
    There are two ways to specify the shape of an arrowhead. One is a parameterized method, used when HeadShape is Automatic. The parameterized arrowhead is based on three values: HeadLength, HeadWidth, and HeadCenter. HeadLength specifies the distance from the tip of the arrowhead to its base. It is measured in the coordinate system given by HeadScaling, that is, if HeadScaling is Relative, the length is a factor of the length of the entire arrow, and if HeadScaling is Absolute, the length is in printer's points. HeadWidth specifies the greatest distance between the sides of the arrowhead, as a factor of the length of the arrowhead. HeadCenter specifies the location of the center of the base of the arrowhead as a factor of the length of the arrowhead. When HeadCenter is 1, the center of the base is as long as the length of the head, so the head is a triangle; when it is 0, the arrow is reduced to a line.
    The other way of specifying the shape of an arrowhead is by a list of Graphics primitives. Currently, the routines only understand a subset of the graphics primitives; they are Point, Line, Polygon, and the various style directives. They are drawn in the same coordinate system as specified by the HeadScaling option, so the heads are automatically rotated to be along the length of the arrow, with the origin of the coordinate system at the tip of the arrow.
    An arrow whose starting and ending points are identical has no length, and hence no direction. Thus, we usually use a different shape to describe it. The option ZeroShape can be used for this purpose. When it is set to Automatic

    , the zero length vector is drawn as a point. The coordinate system is left unrotated, because no direction can be determined.

  • With relative scaling, the size of the arrowhead varies with the length of the arrow.
  • In[4]:= Show[Graphics[
    Table[Arrow[{0, 0}, x {Sin[x], Cos[x]},
    HeadScaling -> Relative],
    {x, 0, 2 Pi, .3}]
    ], PlotRange -> All]

  • With absolute scaling, all arrowheads are the same size.
  • In[5]:= Show[Graphics[
    Table[Arrow[{0, 0}, x {Sin[x], Cos[x]},
    HeadScaling -> Absolute],
    {x, 0, 2 Pi, .3}]
    ], PlotRange -> All]

  • This shows how the shape of the arrowhead can be modified by the parameters HeadCenter and HeadLength.
  • In[6]:= Show[Graphics[
    Table[Arrow[{0,0},{Sin[x], Cos[x]},
    HeadCenter -> x,
    HeadLength -> .1],
    PlotRange -> {{-.1,1},{-.2,1.1}},
    AspectRatio -> Automatic]

  • More general objects can be used to describe the head of an arrow. Note that the head is in a special coordinate system rotated along the arrow. The first arrow depicted here has a HeadShape consisting of two triangular polygons. The second arrow depicted has a HeadShape consisting of a cross formed by two intersecting lines.
  • In[7]:= Show[Graphics[{
    HeadScaling -> Relative,
    HeadShape ->
    Arrow[{.25, .25}, {.75,.75},
    HeadShape -> {Line[{{.1,.1},{-.1,-.1}}],
    PlotRange ->All]]

    Note that the primary difficulty with the arrows created in this package is that the arrowheads are not involved in the scaling calculations that automatically determine the plot range. It is possible for the head to be inadvertently cut off by a poorly set plot range; in some cases it may be necessary to adjust plot ranges by hand.