5

I am trying to visualize the volume generated by rotating two graphs around the xaxis. For example for the functions f(x) = x^3 + 1 and g(x) = x + 1 (over the interval [0,1]). Here is what I tried so far:

\begin{document}

  \begin{tikzpicture}
  \pgfmathsetmacro{\u}{1.5}
 \begin{axis}[
   x={(3.2*\u cm,0.0cm)}, 
   y={(0cm,\u cm)},
   z={(-\u*0.3535cm,-\u*0.3535cm)},  
   axis lines=center,
   xmin=0
   ]
  \addplot3[opacity=0.3,surf,shader=flat,
  samples=40,
  domain=0:1,y domain=0:2*pi,
  z buffer=sort]
  (x,{(x + 1)*cos(deg(y))}, {(x+1) * sin(deg(y))});

   \addplot3[opacity=0.3,surf,shader=flat,
  samples=40,
  domain=0:1,y domain=0:2*pi,
  z buffer=sort]
  (x,{(x^3 + 1)*cos(deg(y))}, {(x^3 + 1) * sin(deg(y))});
 \end{axis}
\end{tikzpicture}

enter image description here

I am not a pgfplots expert so I don't have a good feeling what is possible to visually improve this picture (i.e. that structure of the volume becomes more clear). The volume might be filled or not.

So how can this example made look clearer?

The only restriction is that the axis orientation should remain as in my example.

2

I am not sure if I understand your question right, so this is just a "hope" that this is what you are searching for.

First a note:
Hopefully it is clear to you already, that currently there is no way that PGFPlots "combines" several \addplot3s to then have a real perspective view. \addplot3s are simply drawn in order of appearance (see section 4.6.1 "Before You Start With 3D" on page 123 in the manual (v1.14)).

Now a possible solution:
Because of the above you can only make the "contrast" of the two plots greater. One way is to just give them different colors like ...

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
    \pgfplotsset{compat=1.12}
\begin{document}
    \begin{tikzpicture}
        \pgfmathsetmacro{\u}{1.5}
        \begin{axis}[
            x={(3.2*\u cm,0.0cm)},
            y={(0cm,\u cm)},
            z={(-\u*0.3535cm,-\u*0.3535cm)},
            axis lines=center,
            xmin=0,
            %
            % moved all common keys of the plots here
            every axis plot/.append style={
                opacity=0.3,
                surf,
                shader=flat,
                samples=40,
                domain=0:1,
                y domain=0:2*pi,
                z buffer=sort,
            },
        ]
            \addplot3 [
                draw=blue!80,
                fill=blue!50,
            ] (x,{(x + 1)*cos(deg(y))}, {(x+1) * sin(deg(y))});

            \addplot3 [
                draw=red!80,
                fill=red!50,
            ] (x,{(x^3 + 1)*cos(deg(y))}, {(x^3 + 1) * sin(deg(y))});

        \end{axis}
    \end{tikzpicture}
\end{document}

This results in

image showing the result of above code

(If you need real perspective results, maybe the package tikz-3dplot can help?)

| improve this answer | |
3

You could just split the outer plot in different parts, one in the foreground and one in the background, and then also use layers to enhance the 3D effect.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}

  \begin{tikzpicture}
  \pgfmathsetmacro{\u}{1.5}
 \begin{axis}[set layers,
   x={(3.2*\u cm,0.0cm)}, 
   y={(0cm,\u cm)},
   z={(-\u*0.3535cm,-\u*0.3535cm)},  
   axis lines=center,
   xmin=0
   ]
  \addplot3[opacity=0.2,surf,shader=flat,on layer=axis background,
  samples=20,
  domain=0:1,y domain=pi:2*pi,
  z buffer=sort]
  (x,{(x + 1)*cos(deg(y))}, {(x+1) * sin(deg(y))});

   \addplot3[opacity=0.4,surf,shader=flat,on layer=main,
  samples=40,
  domain=0:1,y domain=0:2*pi,
  z buffer=sort]
  (x,{(x^3 + 1)*cos(deg(y))}, {(x^3 + 1) * sin(deg(y))});

  \addplot3[opacity=0.2,surf,shader=flat,on layer=axis foreground,
  samples=20,
  domain=0:1,y domain=0:pi,
  z buffer=sort]
  (x,{(x + 1)*cos(deg(y))}, {(x+1) * sin(deg(y))});
 \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |

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.