Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Gary Palmer Jun 25 '13 at 2:28
    
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. –  Brett Champion Jun 25 '13 at 2:55
    
Does that mean I should indent every code block 4 spaces? –  Gary Palmer Jun 25 '13 at 3:58
    
I see that it works. –  Gary Palmer Jun 25 '13 at 4:52
    
slider has head Graphics but stationaryObj has head Graphics3D, so you can't combine them with Show. –  cormullion Jun 25 '13 at 13:53

1 Answer 1

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}]
  ]
 ]
share|improve this answer
    
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. –  Gary Palmer Jun 27 '13 at 20:20
    
@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. –  halirutan Jun 27 '13 at 20:34
    
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. –  Gary Palmer Jun 28 '13 at 0:06
    
@GaryPalmer If you like, then join chat and we can discuss some things you might want to try. –  halirutan Jun 28 '13 at 0:08
    
sorry, I missed this. I will try the chat at the same time tomorrow. –  Gary Palmer Jun 28 '13 at 5:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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