I'm using the 3d library to put a circle on the z=0 plane, and other things. I'd like to fade this circle radially, but the result isn't as I would expect because the fading is not proportional to the distance from the origin. How can I do?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{3d,fadings}
\tikzfading [name=radialfade, inner color=transparent!0, outer color=transparent!100]
\begin{document}
\begin{tikzpicture} [x={(-0.3535,-0.3535cm)}, y={(1cm,0cm)}, z={(0cm,1cm)}, scale=3]
\begin{scope} [canvas is xy plane at z=0]
\fill [blue, path fading=radialfade] circle (1);
\end{scope}
\draw[-latex] (-1,0,0) -- (1,0,0) node [left] {$x$};
\draw[-latex] (0,-1,0) -- (0,1,0) node [below] {$y$};
\draw[-latex] (0,0,-0.5) -- (0,0,0.5) node [left] {$z$};
\end{tikzpicture}
\end{document}
Best Answer
As already mentioned by Andrew Stacey in some comment, TikZ is not a real 3D system - and a radial fading is a two-dimensional construct.
You would need some 3d projection algorithm to compute the colors.
A possibility would be to sample such a projection and to interpolate between the sampled points. This is not directly supported by TikZ (because it involves more complicated shadings), but you can use
pgfplots
and itssurf
plot handler to get the effect:EDIT: I did not realize that you asked explicitly for the axis direction vectors of your example. I added them to the answer.
The idea is to use a sphere parameterization of the form (x(t,y), y(t,y), 0), i.e. to fix z=0. The key
point meta
defines the color data. I figured thatt
would be the correct choice, butt^2
looks better. Thesurf,shader=interp
key draws the sampled parametric plot as surface with interpolated colors.The colormap uses RGB color interpolation. What is
transparent
in your example? I defined acolormap
usingblue
andwhite
.EDIT: just in case you are using pgfplots 1.7 or higher, you can use the new feature
patch type sampling
combined with a higher-order patch likepatch type=bicubic
. This allows to reconstruct the geometry with smooth(er) boundaries.The following example has been generated with
\usepgfplotslibrary{patchplots}
and