0
$\begingroup$

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

$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$
    – DavidC
    Aug 18, 2020 at 12:06

2 Answers 2

3
$\begingroup$

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

$\endgroup$
0
$\begingroup$

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.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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