3

I need to draw a parallelopiped like this in TikZ:

enter image description here

I want to draw in 3D using views and not in 2D.

Bernard
  • 271,350

2 Answers2

6

TikZ is internally 2D, so you can only draw one 2D projection on the screen plane of the oblique cuboid; some packages like tikz3d-plot, 3dtool or the library perspective may be used.

In case of real 3D Asymptote, you can copy the following code to http://asymptote.ualberta.ca/ click Run, then use the computer mouse to rotate the output figure. You can guess the meaning of the numbers in the 3-dim transform ty for slanting along y-axis; the last column in the matrix is always $(0,0,0,1)^T$.

enter image description here

// http://asymptote.ualberta.ca/
size(4cm);
import three;

// slanting along y-axis transform3 ty={ { 1, 0, 0, 0}, { 0, 1, .4, 0}, { 0, 0, 1, 0}, { 0, 0, 0, 1} };

draw(tyunitcube,yellow+opacity(.5)); draw(tyunitbox,purple+opacity(1));

Black Mild
  • 17,569
6

Try this:

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
    \begin{tikzpicture}
    \draw[fill=cyan] (0,0)--(4,0)--(5,3)--(1,3)--(0,0);
    \draw[fill=green] (5,3)--(1,3)--(2,4)--(6,4)--(5,3);
    \draw[fill=yellow] (4,0)--(5,3)--(6,4)--(5,1)--(4,0);       
    \draw[dashed] (2,4)--(1,1);
    \draw[dashed] (0,0)--(1,1);
    \draw[dashed] (1,1)--(5,1);

\end{tikzpicture}

\end{document}

Output:

enter image description here