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.

Is there a way to color each face of a Cuboid with a different color?

I looked in the help but couldn't find anything. I found this Coloring the faces of a 3D object different colors (in Mathematica) which proposes building the cuboid with Polygon primitives; any other way?

share|improve this question
1  
Since you want to add a color to each face, You really do need each face to be a separate polygon. I don't think there is a better way to accomplish this. What in particular do you wish could be improved upon this approach? –  jVincent Oct 22 '12 at 20:47
    
Nothing special; I just wish to know if there is any other way of doing that. –  Renan Oct 22 '12 at 20:49
add comment

2 Answers

up vote 8 down vote accepted

I don't think it is possible to color the faces of a single cuboid differently (other than the two sides of one face), though there are multiple methods to create multicolored cuboid-like objects.

Creating multiple polygons:

v = {{-1, -1, -1}, {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}, {-1, -1, 
    1}, {1, -1, 1}, {1, 1, 1}, {-1, 1, 1}};
idx = {{1, 2, 3, 4}, {1, 2, 6, 5}, {2, 3, 7, 6}, {3, 4, 8, 7}, {4, 1, 
    5, 8}, {5, 6, 7, 8}};
Graphics3D[Table[{Glow@Hue[i/6], Polygon[v[[idx[[i]]]]]}, {i, 6}], Lighting -> None]

Mathematica graphics

Using textures, from the help on Texture:

sides = Graphics[{Hue@#, Rectangle[]}, ImageSize -> 50] & /@ 
   Most@Range[0, 1, 1/6];
vtc = {{0.01, 0.01}, {0.99, 0.01}, {0.99, 0.99}, {0.01, 0.99}};
Graphics3D[{Black, EdgeForm[Black],
  Table[{Texture[sides[[i]]], 
    GraphicsComplex[v, Polygon[idx[[i]], VertexTextureCoordinates -> vtc]]}, {i, 6}]}]

Mathematica graphics

share|improve this answer
    
This does nicely and can be easily adapted to other polyhedrons using PolyhedronData. Thanks! –  Renan Oct 22 '12 at 22:40
add comment

Just for completeness:

Graphics3D[{Lighting -> {
    {"Directional", Red, {.5, .5, 1}},
    {"Directional", Green, {1, .5, .5}},
    {"Directional", Blue, {0, 0, 0}}
    },
  Cuboid[]}, Boxed -> False]

cuboid

share|improve this answer
    
Ingenious. Wouldn't have though ot this. Though it only works if there are no other objects casting a shadow. Cannnot something like Glow be used in that case? –  István Zachar Oct 23 '12 at 9:29
    
@IstvánZachar there are no shadows in Graphics3D! –  Oleksandr R. Mar 18 '13 at 10:20
    
@OleksandrR. Yes, silly me. But still adding other objects (like Cuboid[{1, 1, 1}]) messes up the colors, so my guess is this method is only applicable when there is only one object in the scene. –  István Zachar Mar 18 '13 at 10:32
add comment

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.