I'm looking to make a rectangular prism that has color shading, with red at the bottom of the entire prism and blue at the top. So I adapted the following code from here
\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{3d}
\begin{tikzpicture}[x = {(2cm,1.5cm)},
y = {(5.75cm,0cm)},
z = {(0cm,3cm)}]
\begin{scope}[canvas is yz plane at x=-1]
\shade[bottom color = red!50, top color = blue!50] (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is xz plane at y = 1]
\shade[bottom color = red!50, top color = blue!50] (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is yx plane at z = 1]
\fill[blue!50] (-1,-1) rectangle (1,1);
\end{scope}
\end{tikzpicture}
which yields
Now, there are some issues with the above picture that I was hoping someone could help me with.
- The first is that the left and right edges of the top (lid) of the prism aren't parallel, and changing the dimensions in the tikz picture never fixes this. Why is this and how can it be fixed?
- I actually want the shading to be red along the entire bottom of the prism and blue along the entire top. The colouring on front face and the top are both fine. However, the side face has red in the top left corner of the face, when it should be blue to match the colour on the top. I played around with the shadings but to no avail, so I was wondering if this was fixable too?
- I was hoping to bold the edges of the prism to outline where each face begins and ends, though I am having trouble finding code that works with what I have already done.
- Finally, is it possible to get the 'hidden' edges put in the back of the cuboid? By hidden, I mean those three edges from the back face that meet the bottom and top of the prism.
Sorry for the many questions, I'm not very competent with tikz yet. Thanks in advance.
EDIT:
Thanks to the responses below. I managed to get the hidden sides on the picture, as well as the colouring on the bottom of the side face correct. However, the colouring at the top of the side face isn't correct, it is too red and doesn't match the colour of the top face (lid) of the cuboid. Here is the code
\begin{tikzpicture}[join = round, xscale = 12, yscale = 6]
\colorlet{bcolor}{red!60}
\colorlet{tcolor}{blue!100}
\colorlet{ttcolor}{blue!100}
\shadedraw[bottom color = bcolor, top color = tcolor]
(-1,-1) coordinate (A) rectangle (0,0);
\shadedraw[xscale = 0.5, yslant = 0.5, bottom color = bcolor, top color = tcolor, shading angle = 25]
(0,-1) rectangle (1,0)
(1,-1) coordinate (B)
(-1,0) coordinate (O);
\draw[yscale = 0.5, xslant = 0.5, fill = ttcolor] (-1,0) rectangle (0,1) (-1,1) coordinate (C);
\draw[dashed, opacity = 0.7] (O)--(A) (O)--(B) (O)--(C);
\end{tikzpicture}
which gives
The shade at the top of the side face (touching the lid of the cuboid) should be a darker blue, to match the colour of the lid.