The methods given as answers to this question do not seem to work here. I suspect it is because of my use of Inset
function.
Consider two .png images hand1 and hand2, which can be overlapped to display an arm that can bend at the elbow. Up until now I was displaying the two pictures and moving them around dynamically by changing the display coordinates. The code is the following:
img1 = Import["...\\hand1.png"];
img2 = Import["...\\hand2.png"];
Gimg1[x_, y_] := Gimg1[x, y] = Graphics[Inset[img1, {0, 0}, {200 + x, 141.5 + y}, 400], PlotRange -> {{-200, 200}, {-141.5, 141.5}}, ImageSize -> 400];
Gimg2[x_, y_] := Gimg2[x, y] = Graphics[Inset[img2, {0, 0}, {200 + x, 141.5 + y}, 400], PlotRange -> {{-200, 200}, {-141.5, 141.5}}, ImageSize -> 400];
Dynamic[Show[{Gimg1[x1, y1], Gimg2[x2, y2]}]]
x1 = 0; y1 = 0; x2 = 0; y2 = 0;
where instead of ...
I put the proper path to the files. Now, if I change x1,y1,x2,y2
I see the pictures moving around dynamically. To rotate the images, I figured that I would have to wrap them with Rotate[...,θ, {218+x, 222+y}]
, where {218, 222}
are the x-y-coordinates where the elbow appears in the untranslated picture. Therefore, I modify my code as:
img1 = Import["...\\hand1.png"];
img2 = Import["...\\hand2.png"];
Gimg1[x_, y_, θ_] := Gimg1[x, y, θ] = Rotate[ Graphics[Inset[img1, {0, 0}, {200 + x, 141.5 + y}, 400], PlotRange -> {{-200, 200}, {-141.5, 141.5}}, ImageSize -> 400],θ, {218+x, 222+y}];
Gimg2[x_, y_, θ_] := Gimg2[x, y, θ] = Rotate[ Graphics[Inset[img2, {0, 0}, {200 + x, 141.5 + y}, 400], PlotRange -> {{-200, 200}, {-141.5, 141.5}}, ImageSize -> 400],θ, {218+x, 222+y}];
Dynamic[Show[{Gimg1[x1, y1, θ1], Gimg2[x2, y2, θ2]}]]
x1 = 0; y1 = 0; x2 = 0; y2 = 0; θ1 = 0; θ2 = 0;
But now, unfortunately, the images do not even appear when using the Show
command. I tried moving the wrapper Rotate[...,θ, {218+x, 222+y}]
to lower levels, wrapping around the Inset
, or even the images themselves. Nothing seems to work here. The question is, how can I rotate overlapped Inset
images around a certain pixel coordinate while maintaining the ability to also translate the pictures and display everything dynamically and keeping it in a frame of fixed size?