# Merge two graphic objects

I'd like to recursively draw tangles (=knots with open ends). So, the fundamental object O is a crossing, having some fixed size, say fitting into Rectangle[{{-100,-100},{100,100}}], e.g. {Line[{{-100, 100}, {100, -100}}], Line[{{-100, -100}, {-50, -50}}], Line[{{50, 50}, {100, 100}}]}.

I must be able to "add" any two objects O1,O2 (rescale object O1 to fit into Rectangle[{{-100,-100},{0,100}}], object O2 to fit into Rectangle[{{0,100},{100,100}}] - i.e. O1 is compressed into the left and O2 into the right half of the rectangle - merge and store as a new graphic object "O1+O2") and "rotate" any object O1 (rotate O1 around 0,0 by 90 degrees). In both cases the new object fits into the rectangle above again. Visually:

(I assume this can be reused?!)

(EDIT: I think I have an own idea: Since my graphic objects are just lists of Line[[{x1,y1},{x2,y2}}]] statements, I could simply map the contractions over them, I just have to handle when a statement is "left" or "right". I always have trouble with multiple slot syntax, but I guess I manage that...)

• I don't see any rotation in your O1 + O2. Jan 19, 2022 at 12:45

Try this:

tangle = Show[{
Graphics[{White, Rectangle[{-100, 100}]}],
Graphics[{Black, Line[{{-100, 100}, {100, -100}}],
Line[{{-100, -100}, {-50, -50}}], Line[{{50, 50}, {100, 100}}]}]
}, ImageSize -> 100] See the function Rotate to rotate subobjects.

Have fun!

• Sorry, I was too unclear. You just drew my "fundamental" object. See my added pic. (But THX for Rotate.) Jan 19, 2022 at 12:42

I wouldn't mind at all if you optimize the following code which is a bit clumsy but seems to work:

ClearAll["Global*"];
B="|";B="<";B[-1]=">";
FF[]:="";
FF[x___,i_]:=FF[x]<>B[i];
MG[F[x___],F[y___]]:=F[x,y];
BR[F[x___]]:=F[1,x,-1];
RM[{}]:={};
RM[{x_,y___}]:={R0[x],RM[{y}]}//Flatten;
R0[Line[{{x1_,y1_},{x2_,y2_}}]]:=Line[{{y1,-x1},{y2,-x2}}];
AM[{u_,v___},{x_,y___}]:={A1[u],A2[x],AM[{v},{y}]}//Flatten;
AM[{u_,v___},{}]:={A1[u],AM[{v},{}]}//Flatten;
AM[{},{x_,y___}]:={A2[x],AM[{},{y}]}//Flatten;
AM[{},{}]:={};
A1[Line[{{x1_,y1_},{x2_,y2_}}]]:=Line[{{x1/2-50,y1},{x2/2-50,y2}}];
A2[Line[{{x1_,y1_},{x2_,y2_}}]]:=Line[{{x1/2+50,y1},{x2/2+50,y2}}];

RO[o]:=u;
RO[u]:=o;
`