22

I made the following animation, but the disks and the rectangle are shaking, breaking the smoothness of the motion. enter image description here

Here is a minimal example. If you look carefully you will see the disks are shaking.

tab = Table[ConstantArray[Cos[0.3* t], 3], {t, 2, 6, 0.02}];
l0 = 1;
show[x_] := 
 Block[{}, 
  Graphics[{Rectangle[{0, -.5}, {.5, .5}], 
    Rectangle[{5, -.5}, {5.5, .5}], 
    Table[Disk[{x[[i]] + i*l0, 0}, 0.2], {i, 3}]}, ImageSize -> 800]]
plots = Table[show[tab[[i]]], {i, 1, Length@tab, 1}];
Export["temp.gif", plots]

enter image description here

Please not the rectangles are still here, so I don't think it is a scaling issue. This is supported by the fact that specifying PlotRange does not change anything (ImagePadding -> None does not either).

 plots = Table[Show[show[tab[[i]]], PlotRange -> {{0, 5.5}, {-.5, .5}}, 
     PlotRangePadding -> None], {i, 1, Length@tab, 1}]

enter image description here

A comment suggested to change the frame rate; though less obvious, the shaking motion is still present:

  Export["temp.gif", plots, "DisplayDurations" -> 1/50.]

enter image description here

Please not the shaking is not introduced by Export, since it is also observed with ListAnimate@plots.

The question is, of course, how to prevent this shaking?

Interestingly, changing Disks to Point works, but I am looking for a more robust solution (in particular, Arrows also "shake" and can't be easily replaced...).

 show[x_] := Block[{}, Graphics[{Rectangle[{0, -.5}, {.5, .5}], 
   Rectangle[{5, -.5}, {5.5, .5}], PointSize[0.08], 
   Table[Point[{x[[i]] + i*l0, 0}], {i, 3}]}, ImageSize -> 800]]

The following animation is fine: there is no vertical jumps. enter image description here


Animations made with version: 11.0.0 for Linux x86 (64-bit) (July 28, 2016).


Using OSX and MMA 11.1, halirutan reduced the gap between the disks to better highlight the shaking motion:

enter image description here

Of course the motion should be smooth, but that's really not the case.

anderstood
  • 14,301
  • 2
  • 29
  • 80
  • 1
    I guess problem will be solved by increasing the frame rate. Your animation is just 51 frame for ~5 sec of duration but normal video has 24 fps namely for smooth movements. – Rom38 Apr 11 '17 at 03:53
  • 1
    I don't see the problem on Win7 V11.1. Sometimes fixing PlotRange/ImagePadding and friends helps. – Kuba Apr 11 '17 at 06:17
  • the jump at the end is of couse because you arent doing an exact full cycle. – george2079 Apr 11 '17 at 11:52
  • I don't think its aliasing, i think there is some issue with plot scaling. – george2079 Apr 11 '17 at 15:28
  • @Rom38 See edit. The animation rate is 25fps. I added an example with 50fps all the same. Maybe you did not understand what kind of "jumping" (in space, not in time!) I was referring to, so I changed the animations to clarify. – anderstood Apr 11 '17 at 18:32
  • @Kuba Could you please try with the new code? (I'm using V11.0 Linux 64bits) It does not seem to be related to PlotRange or ImagePadding. – anderstood Apr 11 '17 at 18:34
  • @anderstood, time here is an equivalent of X-direction, isn't so? :) By the way, the non-uniformity in motion of the images really presents. Just try to run this: n=1; Manipulate[ImageDifference[plots[[i]], plots[[i + n]]], {i, 1, Length@plots - 1, 1}] You will see that thickness of the white rings is changing with time for n=1,2,... It is true for both Disk and Point – Rom38 Apr 12 '17 at 07:27
  • Have you checked this question - Why is my GIF shaky? – Sumit Apr 12 '17 at 12:59
  • 1
    I'm on V11.0.0.0 on OSX and I do not see the vertical jumping. Sounds like it might be Linux specific. – N.J.Evans Apr 12 '17 at 13:48
  • @Sumit No I had missed it (the word "shaky" did not come to my mind in the first place), however, the solutions did not change anything here. – anderstood Apr 12 '17 at 14:17
  • @Rom38 I meant that of course, if you have 1 fps, the motion won't be smooth, but my question refers to smoothness of the trajectory of the disk. Using ImageDifference is a good idea. You seem to observe the same issue, are you using Linux? – anderstood Apr 12 '17 at 14:20
  • 1
    OSX and Mathematica 11.1 here. I change your animation a bit, putting the disks close together. It looks awful. – halirutan Apr 12 '17 at 18:24
  • @halirutan Thanks, I added your comment to the OP. It seems the saking is only horizontal in your case, or in my reproduction of your case... I am not sure what is happening... – anderstood Apr 12 '17 at 19:32
  • @anderstood, I use MMA 11.1 at Win7 – Rom38 Apr 13 '17 at 03:38
  • I'm having the same problem. But now in 2021 and in WolframCloud. Did anyone find a solution for this problem? – jon jones Sep 01 '21 at 18:17

1 Answers1

2

One way to avoid rasterization rounding issues is to work directly with rasters and ImageCompose

r = 20
n = 5
dx = 50
wbar = 10
amp = 50
back = ImageCompose[
   Image[ConstantArray[
     1, {70, dx (n - 1) + 2 amp + 2 wbar  + 2 r + 1}]] ,
   ConstantArray[Image[ConstantArray[0, {50, wbar}]], 
    2] , {{wbar/2, 35} , {dx (n - 1) + 2 amp + (3/2) wbar  + 2 r + 1, 
     35}}];
frames = (ImageCompose[back, 
        ConstantArray[Image[1 - DiskMatrix[r]], n],
        Table[{# + r + 10 + dx i, 35}, {i, 0, 
          n - 1}]] &@ (amp (Sin[# +  Pi/2] + 1) )) & /@ 
   Range[ 0 , 2 Pi  , Pi/20];

Export["test.gif", frames]

enter image description here

enter image description here

combining with the spring graphics might be a challenge..

george2079
  • 38,913
  • 1
  • 43
  • 110