1

The problem arises when you want to connect two point markers in a diagram with an arrow. Just giving the ccordinates of the points to the arrow results in ugliness, as the arrow then overlaps with the point markers: Two circles, centers connected with an arrow

whereas one might one to "hem in" the arrow on both ends a bit:

Two circles, arrow stopping short of the circumference

Oliver Jennrich
  • 1,194
  • 5
  • 12
  • 1
    From the documentation, "Arrow[{pt1, pt2}, {s1,s2}] sets back s1 from pt1 and s2 from pt2." Using s instead of {s1, s2} uses the same offset for the arrow head and tail. – DavidC Aug 18 '20 at 12:06

2 Answers2

4

You can use the undocumented functions DynamicLocation and and DynamicName to do this (see this answer for more details):

Graphics[
    {
    Arrowheads[{-Medium,Medium}],
    Arrow[{
        DynamicLocation["ID1", Automatic, Center],
        DynamicLocation["ID2", Automatic, Center]
    }],
    Red,
    DynamicName[Disk[{0,0},.1],"ID1"],
    DynamicName[Disk[{1,1},.2],"ID2"]
    }
]

enter image description here

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
0

Ok, here is a small utility function that I named shortenedArrows

Clear[ shortenedArrow];
shortenedArrow[ {p1_, p2_}, {s1_, s2_}] := Module[ {v, a, b},
   v = p2 - p1;
   a = p1 + s1 v;
   b = p1 + (1 - s2) v;
   Return[ Arrow[{a, b}]]
   ];
shortenedArrow[ {p1_, p2_}, s_: 0.05] := 
 shortenedArrow[ {p1, p2}, {s, s}];

The function can be used like Arrow but accepts an (optional) additional parameter that indicates by what fraction the arrow should be hemmed in. If the optional parameter is a list, it gives the fractional shortening at the beginning and the end of the arrow.

The two graphs above are created via

Function[{p1, p2}, 
  Graphics[{Dashed, Red, Disk[#, 0.1] & /@ {p1, p2}, Black, 
    shortenedArrow[{p1, p2}, 0.0] }]][ {0, 0}, {1, 1}]

and

Function[{p1, p2}, 
  Graphics[{Dashed, Red, Disk[#, 0.1] & /@ {p1, p2}, Black, 
    shortenedArrow[{p1, p2}, 0.1] }]][ {0, 0}, {1, 1}]

respectively.

Oliver Jennrich
  • 1,194
  • 5
  • 12