I'm trying to find the easiest way to draw a 3D cube (it's for my UML diagram) with TikZ. Could you please give an example?
Like this:

|
|
I'm sure that there are better ways, but here's one:
|
|||||||||||||
|
|
Since you want to use this for UML diagrams, I think a custom node shape is the right way to go here. It's a lot more overhead and requires getting under PGF's hood/bonnet, but the payoff is that it the drawing code looks just like any other TikZ code:
Take a look at the files |
|||||||||||||||
|
|
I know that this is not what the question was about, but it is an attempt of a 3D cube, with perspective. I don't know how to do it with grids like Stefan's example, but with coordinate calculations and intersections, one can do something like this. It is not mathematically correct, but I think it looks pretty good.
|
|||||
|
|
Drawing a cube seems to be a fairly common task! There are a few other questions here that involve drawing cubes. It's not always right to merge them, but I thought it worth doing a little more than just linking. So this answer is a Community Wiki (so almost anyone can update it) list of the other cubical questions here. The intent is to include at least one representative picture from the answers.
|
||||
|
|
|
Here's an example for a shaded 3D cube with TikZ:
I used on on my blog. |
|||||||||||||
|
|
There is already a lot of nice answers to this question, but I would like to promote the
Again, the tricky part is to fine tune the perspective and shading, but in my opinion the
|
|||
|
|