Importing and animating images
The trick is to create rectangles that cover the bounding boxes of each component image and use the images as textures, then we can use Rotate
and Translate
to animate the robot arm the way we want.
To that end, we may use this code:
t1 = Import["~/Downloads/ElementosPNG/1.png"];
t2 = Import["~/Downloads/ElementosPNG/2.png"];
t3 = Import["~/Downloads/ElementosPNG/3.png"];
width[texture_] := ImageDimensions[texture][[1]]
height[texture_] := ImageDimensions[texture][[2]]
getComponent[texture_, transform_] := Graphics[{
Texture[texture],
transform@Polygon[{{0, 0},
{width[texture], 0},
{width[texture], height[texture]},
{0, height[texture]}},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
}]
Now we can do, e.g.,
getComponent[t1, Identity]
and similarly for the two other components. The second argument of getComponent
is a transform function that can be used to translate and rotate the component. Right click on the image of the first component and choose "get coordinates" to get the coordinate of the center of the hole, then plot the second component and find out the coordinates for its axis. I found that the coordinates were {135, 179}
and {52, 60}
. Testing the values, we can see that this is approximately right:
Show[
getComponent[t2, Translate[#, {135, 179} - {52, 60}] &],
getComponent[t1, Identity]
]
We can add rotation as well:
renderComponent[] := getComponent[t1, Identity]
renderComponent[theta_] := getComponent[
t2,
Composition[
Rotate[#, theta, {135, 175}] &,
Translate[#, {135, 179} - {52, 60}] &
]
]
Henceforth I'm going to be using renderComponent
for all three of the components. No arguments means it it will plot the first component, one argument is the second component and two arguments is the third component.
In order to figure out the transform for the third component, plot the second argument and find out the distances between the axes. Also plot the third component and find out the coordinates for its axis. This is what I got:
renderComponent[theta_, phi_] := getComponent[
t3,
Composition[
Rotate[#, phi, {135, 179} - {52, 60} + 1025 {Cos[theta], Sin[theta]} + {80, 80}] &,
Translate[#, {135, 179} - {52, 60} + 1025 {Cos[theta], Sin[theta]}] &
]
]
Plotting this, it seems to be approximately right:
Manipulate[Show[
renderComponent[theta],
renderComponent[theta, phi],
renderComponent[],
PlotRange -> {{-2000, 2000}, {0, 2000}}
], {theta, 0, Pi}, {phi, 0, 2 Pi}]
The precision with which you got the coordinates off of the components will determine how precisely the components fit together.
My answer is nothing more than a complement of learned with @C. E.:
t1 = Import["~/Downloads/ElementosPNG/1.png"];
t2 = Import["~/Downloads/ElementosPNG/2.png"];
t3 = Import["~/Downloads/ElementosPNG/3.png"];
I added some points for me to locate:
p1={136,173.4};p2={54.8,54.2};p3={1009.2,54.2};
p4={81.3,80.5};
width[texture_]:=ImageDimensions[texture][[1]]
height[texture_]:=ImageDimensions[texture][[2]]
getComponent[texture_,transform_]:=Graphics[{Texture[texture],transform@Polygon[{{0,0},{width[texture],0},{width[texture],height[texture]},{0,height[texture]}},VertexTextureCoordinates->{{0,0},{1,0},{1,1},{0,1}}]}]
I have tried to add these commands to find the coordinates:
getComponent[t1,Identity];
getComponent[t2,Identity];
getComponent[t3,Identity];
I have tried to add these commands to find the positions and the path that will be followed:
g=Graphics[{Dashed,Red,Thickness[0.003],Circle[p1,1064],
Line[{{0,p1[[2]]},{1200,p1[[2]]}}],
Line[{{p1[[1]]+p3[[1]]+p2[[1]],0},{p1[[1]]+p3[[1]]+p2[[1]],400}}],
Line[{{p1[[1]],0},{p1[[1]],400}}]}];
Show[
getComponent[t2,Translate[#,p1-p2]&],
getComponent[t1,Identity],
getComponent[t3,Translate[#,p1-{-983,80.5}]&],
g,
PlotRange->{{0,2000},{0,400}},
ImageSize->700,Axes->True]
I changed some values to relate with the points P1, P2, P3 and P4:
renderComponent[]:=getComponent[t1,Identity]
renderComponent[theta_]:=getComponent[t2,Composition[Rotate[#,theta,p1]&,Translate[#,p1-p2]&]]
renderComponent[theta_,phi_]:=getComponent[t3,Composition[Rotate[#,phi,p1-p4+(p2[[1]]+p3[[1]]){Cos[theta],Sin[theta]}+p4]&,Translate[#,p1-p4+(p2[[1]]+p3[[1]]){Cos[theta],Sin[theta]}]&]]
Manipulate[
Show[
renderComponent[theta],
renderComponent[theta,phi],
renderComponent[],
g,PlotRange->{{-1000,2000},{0,1500}},ImageSize->700,Axes->True],{theta,0,Pi},{phi,0,2 Pi}]