2

I'm trying to draw a 3D picture with some shading to make it look a bit prettier. So far it's just a cuboid, and I discovered the shading command. Here is what I have so far:

\documentclass[varwidth, border=5pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d}    
\begin{document}
\begin{tikzpicture}

\shade[bottom color=blue, top color = white] (0,0,0) -- (0.5,0,0) -- (0.5,2,0) -- (0,2,0) -- cycle;
\shade[bottom color=white, top color=blue] (0,2,0) -- (0,2,-2) -- (0.5,2,-2) -- (0.5,2,0) -- cycle;
\shade[shading=axis,shading angle=45,left color=blue, right color=white] (0.5,0,0) -- (0.5,2,0) -- (0.5,2,-2) -- (0.5,0,-2) -- cycle;

\end{tikzpicture}
\end{document}

My problem is that defining shading angle=45 doesn't work. I can only get shading going from top to bottom, or left to right. Is there a way of defining the shading to go from one corner to another?

Thanks.

Edit: Maybe some technique using radial shading would work? But I'd need to be able to change the centre of the radial shading from the centre of the rectangle to the corner.

4

If I understand properly, you may use shadings library and say

\shade[lower left=blue, upper right=red] (0.5,0,0) -- (0.5,2,0) -- (0.5,2,-2) -- (0.5,0,-2) -- cycle;

enter image description here

I have chosen red just to make it conspicuous.

\documentclass[varwidth, border=5pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,shadings}
\begin{document}
\begin{tikzpicture}

\shade[bottom color=blue, top color = white] (0,0,0) -- (0.5,0,0) -- (0.5,2,0) -- (0,2,0) -- cycle;
\shade[bottom color=white, top color=blue] (0,2,0) -- (0,2,-2) -- (0.5,2,-2) -- (0.5,2,0) -- cycle;
\shade[lower left=blue, upper right=red] (0.5,0,0) -- (0.5,2,0) -- (0.5,2,-2) -- (0.5,0,-2) -- cycle;

\end{tikzpicture}
\end{document}

A random colour choice gives

enter image description here

\documentclass[varwidth, border=5pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,shadings}
\begin{document}
\begin{tikzpicture}

\shade[lower left=red!20,lower right=red, upper left=blue,upper right=blue!20] (0,0,0) -- (0.5,0,0) -- (0.5,2,0) -- (0,2,0) -- cycle;
\shade[lower left=blue,lower right=red!5, upper left=red,upper right=blue!5] (0,2,0) -- (0,2,-2) -- (0.5,2,-2) -- (0.5,2,0) -- cycle;
\shade[lower left=red,lower right=red!50!blue!50,upper left=blue!50!red!50, upper right=blue] (0.5,0,0) -- (0.5,2,0) -- (0.5,2,-2) -- (0.5,0,-2) -- cycle;

\end{tikzpicture}
\end{document}
  • Hi. Thanks for the answer, I'd forgotten about the shadings library. I've made it work with the following: \shae[lower right=red, upper left=red!20!white, lower left=red, upper right=red] etc.. – thosphor Jan 23 '15 at 15:16
  • @user3087409 Glad it was helpful. – user11232 Jan 23 '15 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.