cube.tex 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. % Source: http://tex.stackexchange.com/a/12069/5645
  2. \begin{tikzpicture}[scale=0.5]
  3. \clip (-3,-3) rectangle (3,3);
  4. \coordinate (tf) at (0,0);
  5. \coordinate (bf) at (0,-3);
  6. \coordinate (tr) at (15:2.5cm);
  7. \coordinate (tl) at (165:2.5cm);
  8. % You can change the perspective by playing with the 5, 5, 15:
  9. \coordinate (fr) at ($ (tf)!5!(tr) $);
  10. \coordinate (fl) at ($ (tf)!5!(tl) $);
  11. \coordinate (fb) at ($ (tf)!15!(bf) $);
  12. \path[name path=brpath] (bf) -- (fr);
  13. \path[name path=rbpath] (tr) -- (fb);
  14. \path[name path=blpath] (bf) -- (fl);
  15. \path[name path=lbpath] (tl) -- (fb);
  16. \path[name path=trpath] (tl) -- (fr);
  17. \path[name path=tlpath] (tr) -- (fl);
  18. \draw[name intersections={of=brpath and rbpath}] (intersection-1)coordinate (br){};
  19. \draw[name intersections={of=blpath and lbpath}] (intersection-1)coordinate (bl){};
  20. \draw[name intersections={of=trpath and tlpath}] (intersection-1)coordinate (tb){};
  21. \shade[right color=gray!10, left color=black!50, shading angle=105] (tf) -- (bf) -- (bl) -- (tl) -- cycle;
  22. \shade[left color=gray!10, right color=black!50, shading angle=75] (tf) -- (bf) -- (br) -- (tr) -- cycle;
  23. \begin{scope}
  24. \clip (tf) -- (tr) -- (tb) -- (tl) -- cycle;
  25. \shade[inner color = gray!5, outer color=black!50, shading=radial] (tf) ellipse (3cm and 1.5cm);
  26. \end{scope}
  27. \draw (tf) -- (bf);
  28. \draw (tf) -- (tr);
  29. \draw (tf) -- (tl);
  30. \draw (tr) -- (br);
  31. \draw (bf) -- (br);
  32. \draw (tl) -- (bl);
  33. \draw (bf) -- (bl);
  34. \draw (tb) -- (tr);
  35. \draw (tb) -- (tl);
  36. %set the sizes of the little cubes:
  37. \def\tone{.4}\def\ttwo{.75}\def\fone{.36}\def\ftwo{.70}
  38. \draw ($ (bf)!\tone!(br) $) -- ($ (tf)!\tone!(tr) $) -- ($ (tl)!\tone!(tb) $);
  39. \draw ($ (bf)!\ttwo!(br) $) -- ($ (tf)!\ttwo!(tr) $) -- ($ (tl)!\ttwo!(tb) $);
  40. \draw ($ (bf)!\tone!(bl) $) -- ($ (tf)!\tone!(tl) $) -- ($ (tr)!\tone!(tb) $);
  41. \draw ($ (bf)!\ttwo!(bl) $) -- ($ (tf)!\ttwo!(tl) $) -- ($ (tr)!\ttwo!(tb) $);
  42. \draw ($ (tl)!\fone!(bl) $) -- ($ (tf)!\fone!(bf) $) -- ($ (tr)!\fone!(br) $);
  43. \draw ($ (tl)!\ftwo!(bl) $) -- ($ (tf)!\ftwo!(bf) $) -- ($ (tr)!\ftwo!(br) $);
  44. \end{tikzpicture}