4
$\begingroup$

Check the following six piece of code:

Dynamic[Graphics[Rotate[Rectangle[], SessionTime[]], PlotRange -> {{-1, 2}, {-1, 2}}], UpdateInterval -> 1]

DynamicModule[{s = 0}, Graphics[Rotate[Rectangle[], Dynamic[s++, UpdateInterval -> 1, TrackedSymbols :> {}]], PlotRange -> {{-1, 2}, {-1, 2}}]]

DynamicModule[{s = 0}, {Dynamic@s++, Graphics[Rotate[Rectangle[], Dynamic[s, UpdateInterval -> 1, TrackedSymbols :> {}]], PlotRange -> {{-1, 2}, {-1, 2}}]}]

Graphics[Rotate[Rectangle[], Dynamic[SessionTime[], UpdateInterval -> 1, TrackedSymbols :> {}]], PlotRange -> {{-1, 2}, {-1, 2}}]

Graphics[Rotate[Rectangle[], Dynamic[2 SessionTime[], UpdateInterval -> 1, TrackedSymbols :> {}]], PlotRange -> {{-1, 2}, {-1, 2}}]

The first works fine. Rectangle in the second is obviously distorted and UpdateInterval is not working. However, similar to the previous one, the third works fine. The fourth refuse to update, while the first works well, and the fifth return a bug...

Why would these happen? Just feel so confused about Dynamic in Mathematica...

$\endgroup$
  • $\begingroup$ Your second expression behaves as you expect it if the whole Rotate expression is enclosed in Dynamic: DynamicModule[{s = 0}, Graphics[Dynamic[Rotate[Rectangle[], s++], UpdateInterval -> 1, TrackedSymbols :> {}], PlotRange -> {{-1, 2}, {-1, 2}}]]. I cannot claim to fully understand why. However, I suspect that the distortion you observed from your original code may have been an artifact of graphics rendering. $\endgroup$ – MarcoB Jun 8 '18 at 15:32
  • $\begingroup$ @MarcoB I suspect that this is due to calculation issue instead of rendering issue. The error information in the 6th case indicates that there's something wrong with the rotation matrix. It seems that a Cos or something is missing. (My guess) $\endgroup$ – Wjx Jun 9 '18 at 10:50
  • $\begingroup$ @MarcoB True, when Rotate is enclosed in Dynamic then it's fine $\endgroup$ – Wjx Jun 9 '18 at 10:50

Your Answer

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

Browse other questions tagged or ask your own question.