1
$\begingroup$

I am trying to construct a building with a manipulated sliding roof and other objects that can be manipulated. I have found that the manipulation of translations and rotations of graphics groups of polygons proceeds too slowly, so I have rasterized the moving objects to speed things up, but it seems the rasters don't manipulate, or they don't work in Show. I get the error

Show::gcomb: Could not combine the graphics objects in Show[slider,stationaryObj]. >>

This script abstracts the essentials of my attempt by creating a stationary Cuboid in color Gray and a list of rasterized translated Cuboids that represent the sliding object in Brown. The sliding object should slide along the top of the stationary object. The sliding is supposed to be accomplished by manipulating the presentation of successive translated and then rasterized images from a list. The program does not work. The question is, what am I missing, or is there a better approach?

Clear["Global`*"]

(* dimensions of two-by-four in inches *)
thkns = 1.5;
wdth = 3.5;
len = 12;

(* two by four of length 12 inches *)
slidingObj = Cuboid[{0, 0, 0}, {thkns, len, wdth}];

(* a stationary base on which the two by four should slide *)
stationaryObj = Rasterize[Graphics3D[{Gray, Translate[slidingObj, {0, 0, - wdth}]}]]

slidingImages = Table[
Rasterize[Graphics3D[{Brown, Translate[slidingObj, {0, s, 0}]}]],{s, Range[5]}];

Manipulate[slider = slidingImages[[s]], {s, Range[5]}];

Show[ slider, stationaryObj] // Dynamic

Following suggestions in the comments, I rasterized stationaryObj and removed the semi-colon from the Manipulate function (though I kept it here). The "could not combine objects" error persists. I tried moving stationaryObj inside a list with slidingImages[[s]] in Manipulate.

Manipulate[
slider = {stationaryObj, slidingImages[[s]]}, {s, Range[5]}];

Show[slider]

This produced the error message

Show::gtype: Symbol is not a type of graphics.

Using just

Manipulate[{stationaryObj, slidingImages[[s]]}, {s, Range[5]}]

without the Show function does not produce an error message, but it also doesn't combine the Graphics.

The suggestions by @halirutan deleted the Rasterize, which seem to be needed for the more complicated objects I am working on outside this page, as they move slowly. However, @halirutan's second script worked with Rasterize added. The following works as desired:

With[{thkns = 1.5, wdth = 3.5, len = 12}, 
 With[{slidingObj = Cuboid[{0, 0, 0}, {thkns, len, wdth}]}, 
  Manipulate[
   Rasterize[
    Graphics3D[{Gray, Translate[slidingObj, {0, 0, -wdth}], Brown, 
      Translate[slidingObj, {0, s, 0}]}, 
     PlotRange -> {Automatic, {0, len + 10}, Automatic}]], {s, 0, 10}]]]

But I might have been too hasty in accepting this answer. I do need to combine several different shapes in a single screen in which only two objects will be manipulated. I now realize that the script makes use of only one object.

$\endgroup$
9
  • $\begingroup$ The editor appears to have removed a star from each of these two comments: (* side 1 ) and ( side 2 with connections to side 1 at corners *). They are still in the original material associated with the message. $\endgroup$
    – Gary
    Jun 25, 2013 at 2:28
  • $\begingroup$ mathematica.stackexchange.com/editing-help -- you're in text so the * is starting (and then ending) italic formatting. Formatting the inputs as code will avoid this. $\endgroup$ Jun 25, 2013 at 2:55
  • $\begingroup$ Does that mean I should indent every code block 4 spaces? $\endgroup$
    – Gary
    Jun 25, 2013 at 3:58
  • $\begingroup$ I see that it works. $\endgroup$
    – Gary
    Jun 25, 2013 at 4:52
  • $\begingroup$ slider has head Graphics but stationaryObj has head Graphics3D, so you can't combine them with Show. $\endgroup$
    – cormullion
    Jun 25, 2013 at 13:53

1 Answer 1

2
$\begingroup$

Maybe I miss something important here, but why don't you show your final sliding thing directly in the manipulate?

thkns = 1.5;
wdth = 3.5;
len = 12;
slidingObj = Cuboid[{0, 0, 0}, {thkns, len, wdth}];
slidingImages = 
  Table[Graphics3D[{Brown, Translate[slidingObj, {0, s, 0}]}], {s, 
    Range[5]}];
stationaryObj = 
  Graphics3D[{Gray, Translate[slidingObj, {0, 0, -wdth}]}];
Manipulate[Show[stationaryObj, slidingImages[[s]]], {s, Range[5]}]

enter image description here

And while we are at it: Is there a reason why you want to combine several Graphcis3D? Wouldn't it be shorter to just do the translation inside the Manipulate.

With[{thkns = 1.5, wdth = 3.5, len = 12},
 With[{slidingObj = Cuboid[{0, 0, 0}, {thkns, len, wdth}]},
  Manipulate[Graphics3D[{Gray, Translate[slidingObj, {0, 0, -wdth}],
     Brown, Translate[slidingObj, {0, s, 0}]}, 
    PlotRange -> {Automatic, {0, len + 10}, Automatic}], {s, 0, 10}]
  ]
 ]
$\endgroup$
5
  • $\begingroup$ The program I envision has two independent moving objects each made of several polygons. They move slowly, so I think they should be rasterized prior to inclusion in Manipulate. Other elements and polygons are stationary, so they don't need to be rasterized, unless their rasterization is the only way to combine them with the rasterized objects. $\endgroup$
    – Gary
    Jun 27, 2013 at 20:20
  • $\begingroup$ @GaryPalmer But you do realize, that once a Graphics3D is rasterized, it is a flat 2d image? This can not be combined into a 3D scene in the usual way. Have you tried successfully to combine rasterized 3d graphics? I'm sure you'll be surprised. $\endgroup$
    – halirutan
    Jun 27, 2013 at 20:34
  • $\begingroup$ I don't doubt what you say, and I have not successfully combined moving and stationary rasterized graphics. I have successfully combined moving and stationary non-rasterized objects, but the objects are complex and the result is slow. Maybe what I am asking is not possible. I'm not too disappointed, because I have learned from the comments. $\endgroup$
    – Gary
    Jun 28, 2013 at 0:06
  • $\begingroup$ @GaryPalmer If you like, then join chat and we can discuss some things you might want to try. $\endgroup$
    – halirutan
    Jun 28, 2013 at 0:08
  • $\begingroup$ sorry, I missed this. I will try the chat at the same time tomorrow. $\endgroup$
    – Gary
    Jun 28, 2013 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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