How can I draw between 2 pictures or more in Asymptote?

Perhaps, it would be more convenient to track and use transform, like this, for example:

settings.outformat="pdf";
size(9cm);
picture pic;

guide gc=scale(sqrt(2),1)*unitcircle;
guide gc1=shift(-1/sqrt(2),0)*scale(1/sqrt(2))*unitcircle;
guide gc2=shift( 1/sqrt(2),0)*scale(1/sqrt(2))*unitcircle;

pair A=(-1/sqrt(2),0);
pair B=( 1/sqrt(2),0);

filldraw(pic,gc ,orange,   darkblue+0.7bp);
filldraw(pic,gc1,lightred, red+     0.7bp);
filldraw(pic,gc2,lightblue,blue+    0.7bp);

transform[] tr={
  identity(),
  shift(3,2)*rotate(42),
  shift(3,-2)*rotate(242)
};

for(var rel: tr) add(rel*pic);

draw(tr[0]*B--tr[2]*B,blue+0.7*bp);
draw(tr[1]*A--tr[2]*A,red+0.7*bp);

for(var rel: tr){
  dot(rel*(A--B),UnFill);
  label("$A$",rel*A,plain.NE);
  label("$B$",rel*B,plain.NE);
}

enter image description here


Based on your question and comment, you want to draw a line between two coordinates on two different pictures by referencing the pictures. I don't know of a direct way to do this, but maybe the following will suit your needs.

I define the offset of pic2 as a pair. Then you may use this pair to also offset the dashed line endpoint.

unitsize(1cm);
picture pic1,pic2;

draw(pic1,(0,0)--(3,3),Arrow);
dot(pic1,(1.5,1.5));
draw(pic2,(0,3)--(3,0),Arrow);
dot(pic2,(1.5,1.5));

pair pic2offset = (5,0);

add(pic1);
add(shift(pic2offset)*pic2);

draw((1.5,1.5)--pic2offset+(1.5,1.5),black+dashed);

shipout(bbox(2mm,Fill(white)));

Tags:

Asymptote