5

I want to create a graph using Asymptote and this graph consists of quite some circles with lines between them. Let me give a small example using two circles.

pair a1=(4.5,2);
pair a2=(0,0);
real r=0.25;

path c1=circle(a1,r);
path c2=circle(a2,r);

draw(c1);
draw(c2);

Now, I have tried several ways to draw a simple, though nice line:

draw(a1--a2, arrow=MidArrow(size=8));
draw(c1--c2, arrow=MidArrow(size=8));
draw(a1+(0,-r)--a2+(0,r), arrow=MidArrow(size=8));

None one of them gives the result I want. The first has line segments inside the circles, the second does not start the line at logical places and the third solution does not look natural. I would want the line a1--a2, so the shortest line between the two circles, but without the line segments inside the circles.

Is there a way to shorten this line by r at both sides? This way I do not have to calculate the exact coordinates of where the a1--a2 line crosses the circle, since I want to be able to move the circles around.

2 Answers 2

7

Something like that?

A combination of firstcut(p, c1).after which removes the part of path p located before its intersection with c1, and of lastcut(q, c2).before, which removes the part of path q located after its intersection with c2. See Asympote's main manual, p. 35.

unitsize(2cm);
pair a1=(4.5,2);
pair a2=(0,0);
real r=0.25;

path c1=circle(a1,r);
path c2=circle(a2,r);

draw(c1);
draw(c2);
//draw(a1--a2, arrow=MidArrow(size=8));
draw(lastcut(firstcut(a1--a2, c1).after, c2).before, arrow=MidArrow(size=8));

enter image description here

4

@Franck has a fine general answer, but perhaps a simpler solution is to draw the arrow first, then draw AND fill the circles.

unitsize(1cm);
pair a1=(4.5,2);
pair a2=(0,0);
real r=0.25;

path c1=circle(a1,r);
path c2=circle(a2,r);

draw(a1--a2, arrow=MidArrow(size=8));

filldraw(c1, white);
filldraw(c2, white);

enter image description here

1
  • In this case it is indeed simpler, but if the arrow's tip had been located at the end of the line a1--a2 as usual, it would have been partly erased by the filling of c2. May 22, 2015 at 10:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .