I have three image files that make up a system similar to a mechanical arm.

I wonder if it's possible to be created an assembly that I can import these images and use them in a way to generate an animation.

It may seem strange to my question, I know that there are better tools for this purpose , talking about the animation.

However , I do not believe there is a tool that in addition to running an animation can provide me mathematical results related to this animation.

Below I show an animation made by me using a software called SolidWorks software, but this software just gives me an animation and I can not get mathematical data such as position, velocity and acceleration:

The initial position of the mounted images is shown in the figure below :

The images can be downloaded through this link:

Image1 Image2 Image3

  • $\begingroup$ It would be better to create the elements in Mathematica, then animate them based on your equations of motion ... take a look at this - wolfram.com/mathematica/new-in-9/… $\endgroup$ – Young Jul 7 '16 at 0:17
  • $\begingroup$ I also agree that it is very interesting to do through the graph function. But I created this question to see the possibilities with this idea. $\endgroup$ – LCarvalho Jul 7 '16 at 0:35
  • $\begingroup$ Perhaps you'll like this: Animation of double pendulum $\endgroup$ – Jens Jul 7 '16 at 17:20
  • $\begingroup$ @Jens This is really cool. It will really help with my studies. $\endgroup$ – LCarvalho Jul 7 '16 at 20:00

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[{
   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]

Mathematica graphics

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:

 getComponent[t2, Translate[#, {135, 179} - {52, 60}] &],
 getComponent[t1, Identity]

Mathematica graphics

We can add rotation as well:

renderComponent[] := getComponent[t1, Identity]
renderComponent[theta_] := getComponent[
   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[
   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:

  renderComponent[theta, phi],
  PlotRange -> {{-2000, 2000}, {0, 2000}}
  ], {theta, 0, Pi}, {phi, 0, 2 Pi}]

Robot arm

The precision with which you got the coordinates off of the components will determine how precisely the components fit together.

  • 1
    $\begingroup$ The purpose of import and animation was completed. It is now my responsibility to create control functions. Thanks. $\endgroup$ – LCarvalho Jul 7 '16 at 9:50
  • $\begingroup$ If you have an interest in correcting your GIF because I realized a small failure, I would be grateful, because your answer was fantastic. $\endgroup$ – LCarvalho Jul 7 '16 at 17:03

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:



I have tried to add these commands to find the coordinates:


I have tried to add these commands to find the positions and the path that will be followed:



I changed some values to relate with the points P1, P2, P3 and P4:


g,PlotRange->{{-1000,2000},{0,1500}},ImageSize->700,Axes->True],{theta,0,Pi},{phi,0,2 Pi}]
  • 1
    $\begingroup$ In the response that I presented, the codigo getComponent[t3, Translate[#, p1 - {-983, 80.5}] &] I introduced the values manually to achieve the expected result. What these values indicate? I managed to get the result, but I didn't. $\endgroup$ – LCarvalho Jul 7 '16 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.