Message Boards Message Boards

1
|
3091 Views
|
7 Replies
|
7 Total Likes
View groups...
Share
Share this post:

How to avoid recalculation of Graphics with moving object?

Posted 2 years ago
POSTED BY: Werner Geiger
7 Replies

One point I would like to clear up that @Werner Geiger might be confused about is that Graphics does no computation - ever. It has no evaluation rules. Plot and other functions that produce a Graphics as part of their computation, but the resulting graphics object is inert.

POSTED BY: Jason Biggs

Jason,

excellent point - thank you! If I understand this correctly then the situation you are describing can be seen by looking at the FullForm, e.g. of my code above (there is still the locator which can be moved!):

Manipulate[
 FullForm@Show[background, 
   Graphics[{Translate[grgr, {xy}]}]], {{xy, {1, 1}}, Locator}]
POSTED BY: Henrik Schachner
Posted 2 years ago

Check out this. Maybe useful?

Manipulate[
    redcircle = Circle[center, radius];
    Graphics[{
        {Blue, Circle[]},
        {Red, redcircle},
        {Opacity@0.5, Rectangle[]}
    }],
    {center, Locator},
    {{radius, 0.5}, 0.1, 0.9, 0.1},
    {redcircle, None}
 ]
POSTED BY: Hans Milton
POSTED BY: Henrik Schachner
Posted 2 years ago

I am not shure, Henrik, if I understand you or you understood me. Where is that static Background in your example?

I added a randomly rotated LightBlue rectangle as such. Of course it is recalculated with each step, i.e. move of the locator:

grgr = GraphicsGroup[{Red, Disk[], Blue, Rectangle[{.5, .5}], Green, 
   Sphere[{.5, .3}, 1.4]}]; Manipulate[
 Graphics[{LightBlue, 
   GeometricTransformation[Rectangle[{-3, -3}, {3, 3}], 
    RotationTransform[RandomReal[{0, Pi/2}]]],
   Translate[grgr, {xy}]}, PlotRange -> {{-4, 4}, {-4, 4}}, 
  Axes -> True], {{xy, {1, 1}}, Locator}]
POSTED BY: Werner Geiger

And how about this approach:

grgr = GraphicsGroup[{Red, Disk[], Blue, Rectangle[{.5, .5}], Green, Sphere[{.5, .3}, 1.4]}];
background = Graphics[{LightBlue, GeometricTransformation[Rectangle[{-3, -3}, {3, 3}], 
     RotationTransform[RandomReal[{0, Pi/2}]]]}, PlotRange -> {{-4, 4}, {-4, 4}}, Axes -> True];

Manipulate[Show[background, Graphics[{Translate[grgr, {xy}]}]], {{xy, {1, 1}}, Locator}]
POSTED BY: Henrik Schachner
Posted 2 years ago

This actually works! At first I was surprised, because I thought the Show would be recalculated as a whole.

But now I understand it: xy is Dynamic, so only grgr is recalculated, background is not, because it does not depend on xy. Pretty simple and pretty stupid of me not to figure it out myself.

Thanks a lot!

Liebe Grüße and Glück auf!, Werner

POSTED BY: Werner Geiger
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract