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

Example:

``````unitsize(1cm);
defaultpen(linewidth(1bp));

picture pic1,pic2,pic3,pic4;

path bigbox=box((0,0),(4,4));
draw(pic1,Label("Input image",Relative(0.25/2)),bigbox);
draw(pic1,box((1,2),(2,3)),linetype(new real[] {4,4}));

filldraw(pic2,shift(2*(-.5,.5))*bigbox,white);
filldraw(pic2,shift(-.5,.5)*bigbox,white);
filldraw(pic2,bigbox,white);
label(pic2,Label(minipage("\centering Convolution \\ (feature maps)",3cm),Relative(0.25/2)),bigbox);
path dashedbox=box(((1,2)+(2,3))/2,(2,3));
draw(pic2,dashedbox,linetype(new real[] {4,4}));

path box1=box((1,1),(3,3));
filldraw(pic3,shift(2*(-.5,.5))*box1,white);
filldraw(pic3,shift(-.5,.5)*box1,white);
filldraw(pic3,box1,white);
label(pic3,Label("Maxpooling",Relative(0.25/2),9*RightSide),box1);

path cir=circle((3.5,0.5),0.5);
for(int i=6; i>=0;--i){ filldraw(pic4,shift(i*(-.5,.5))*cir,white); }
label(pic4,Label(minipage("\centering Fully- \\ connected \\ layer)",3cm),Relative(0.75),12*RightSide),shift(3*(-.5,.5))*cir);

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

Output:

This is what I need:

Can I draw dashed line connect two dots from `pic1` to `pic2`, `pic2` to `pic3`, ...?

• I’m voting to close this question because this seems to be a pure Asymptote problem and not TeX related. Commented Aug 18, 2020 at 6:41
• I don't agree with closing this question because Asymptote is a part of LaTeX just like pstricks, metapost, metafont. This question is relevant here. Commented Aug 18, 2020 at 6:46
• You can certainly add `draw((1.5,1.5)--(6.5,1.5),black+dashed);` after the `add(shift(5,0)*pic2);` line. Is that what you needed? Commented Aug 18, 2020 at 12:55
• @James I want to ask if Asymptote can have a command such as `pair M=(pic1,(1.5,1.5)), N=(pic2,(1.5,1.5));`, `draw(M--N,dashed);` and then add it after the `add(shift(5,0)*pic2);` line.
– user213378
Commented Aug 18, 2020 at 13:28
• @TobiBS:: Please read the description of the asymptote tag and don't vote to close relevant questions on TeX.SE. Commented Aug 19, 2020 at 16:14

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)
};

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);
}
``````

• Thanks! `transform[] tr={ identity(), shift(6,0), shift(11,0), shift(15,0) }; add(tr[0]*pic1); add(tr[1]*pic2); add(tr[2]*pic3); add(tr[3]*pic4); draw(tr[0]*(2,3)--tr[1]*(min(dashedbox).x,max(dashedbox).y),blue+0.7*bp); draw(tr[0]*(2,2)--tr[1]*min(dashedbox),red+0.7*bp);` ...
– user213378
Commented Aug 20, 2020 at 7:02

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);

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

shipout(bbox(2mm,Fill(white)));
``````
• I understand your answer, however I want to know Asymptote can have a `syntax` like that.
– user213378
Commented Aug 18, 2020 at 14:01
– user213378
Commented Aug 18, 2020 at 14:08
• @user213378: Thank you for your question update. Hopefully someone else will have an answer that makes it easier to draw between pictures. Good luck! Commented Aug 18, 2020 at 14:11
• @James: +1. Perhaps, it would be more convenient to use `transform`, like `transform relPic2=shift(pic2offset);add(relPic2*pic2);` `draw((1.5,1.5)--relPic2*(1.5,1.5),black+dashed);`. Commented Aug 19, 2020 at 16:33

Recall that this task is very easy in drawing with TikZ, both for points or `node`s including all their `anchor` points. In case they are in different parts of the current picture, that is, in different `scope`, just give these nodes some names, say `(A)` and `(B)`. Then we can use `\draw (A)--(B);` or `\draw (A.120)--(B.center);`

For Asymptote, the answer of @g.kov works for points (`pair`) in different pictures. The following is my test for boundary points of different `object`s. The syntax `point(B,dir(45),t)` give us a `pair` in the direction `45` on the boundary of `object` `B`, under action of the transform `t`. Many things works as expected. However we need to test more, e.g.,

1. `unitsize(1cm)` does not work, I have to specify units in each command;
2. `fill(circle(Y,2pt),red);` // did see anything
3. `dot(Y);` // did not work, wrong position `4. `draw(X .. controls X+dir(45) and Y+dir(-50) .. Y,red,Arrow); //give a stright line ` The code

``````//unitsize(1cm);   // did not work, quite annoying
filldraw(circle((0,0),2.5cm),lightgray);
object A=draw("\$A\$",box,(-1cm,-1cm),xmargin=5mm,FillDraw(yellow,blue));
pair X=point(A,dir(120));
dot(X);

transform t=shift(4cm,-1cm);

picture pic;
filldraw(pic,box((0,0),(3cm,3.5cm)),pink);
object B=draw(pic,"\$B\$",ellipse,(2cm,2.5cm),xmargin=3mm,FillDraw(white,blue));
pair Y=point(B,dir(45),t);
fill(circle(Y,2pt),red);  // did not work
dot(Y);                      // did not work

• The `unitsize` command, like most of the `draw` commands, accepts a `picture` argument, which defaults to `currentpicture`. This may explain your difficulties with it here. Commented Feb 1, 2021 at 19:11