Hi all,
I'm trying to solve a somewhat simple problem, but I'm using it as a proxy to better understand the Map/Thread/MapThread aspects of the language, ....
I have 2 lists that I want to combine/add. The list elements are 2D points, but the lists could be arbitrarily long i.e.
aa = {{Ax, Ay}, {Bx, By}, {Cx, Cy}}
bb = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4},{x5, y5}}
and I want to combine the lists to get an output that is :
out = {{Ax + x1, Ay + y1}, {Ax + x2, Ay + y2}, {Ax + x3, Ay + y3}, {Ax + x4,Ay + y4}, {Bx + x1, By + y1}, {Bx + x2, By + y2}, {Bx + x3,By + y3}, {Bx + x4, By + y4}, {Cx + x1, Cy + y1}, {Cx + x2,Cy + y2}, {Cx + x3, Cy + y3}, {Cx + x4, Cy + y4}}
I can do this with a Table command, i.e.
In[1]:= out = Flatten[Table[u + v, {u, aa}, {v, bb}], 1]
Out[1]= {{Ax + x1, Ay + y1}, {Ax + x2, Ay + y2}, {Ax + x3, Ay + y3}, {Ax + x4, Ay + y4}, {Bx + x1, By + y1}, {Bx + x2, By + y2}, {Bx + x3, By + y3}, {Bx + x4, By + y4}, {Cx + x1, Cy + y1}, {Cx + x2, Cy + y2}, {Cx + x3, Cy + y3}, {Cx + x4, Cy + y4}}
However, I was trying to figure out how this could be done using a Map/Thread/MapThread based approach. I got as far as:
In[2]:= Map[aa[[1]] + # &, bb]
Out[2]= {{Ax + x1, Ay + y1}, {Ax + x2, Ay + y2}, {Ax + x3,Ay + y3}, {Ax + x4, Ay + y4}}
or
In[3]:= gg[arg1_, arg2_] := Map[arg1 + # &, arg2]
In[4]:= gg[aa[[1]], bb]
Out[4]= {{Ax + x1, Ay + y1}, {Ax + x2, Ay + y2}, {Ax + x3, Ay + y3}, {Ax + x4, Ay + y4}}
But taking it the next step and having the function take in a list of points aa instead of just one has been problematic (that is without ending up with an unwieldy, messy pit of code). I think part of my problem is that the function Plus acting on a list just gives back the list, i.e.
In[5]:= Plus[{a, b, c}]
Out[5]= {a, b, c}
Thanks of any words of wisdom, and happy new year to all.