5

I am new to latex but heard about tikz from this site. I don't know whether tikz can draw the graph attached. The picture is a curve revolving to generate a volume. I used to use MS Office to get it done but take a long to draw and edit. Hopefully, latex can help. Thanks

revolving to generate volume

2
  • Please, show us what you have tried. Even with errors or ugly results.
    – Sigur
    Jun 18, 2015 at 9:49
  • Don't forget that you can and should accept the answer that best solves the question! Our reputations depend on it. Jun 24, 2015 at 3:20

2 Answers 2

13

One possibility

enter image description here

The code (includes comments):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,calc,bending,shapes.arrows,shadows,backgrounds}

\definecolor{myred}{RGB}{232,75,68}

\begin{document}

\begin{tikzpicture}[
  >=latex,
  tharrow/.style={
    fill=myred,
    single arrow,
    minimum height=1.5cm,
    drop shadow,
  }
]
% the axis lines
\draw[help lines,->,name path=xaxis]
  (-4.5,0) -- (4.5,0);
\draw[help lines,->,name path=yaxis]
  (0,-5) -- (0,4.5);
% the curve to the left
\draw[name path=leftcurve,thick] 
  (0.5,-4)  to[out=40,in=-110] 
  (2,0) to[out=70,in=-90] (3,4) node[above] {$x=f(y)$};
% the curve to the right (it's a reflection of the left curve)
\begin{scope}[xscale=-1]
\draw[name path=rightcurve,thick] 
  (0.5,-4)  to[out=40,in=-110] 
  (2,0) to[out=70,in=-90] (3,4);
\end{scope}  
% paths for the dashed horizontal lines
\path[name path=upperline] 
  (-4,2.5) -- (4,2.5);
\path[name path=lowerline] 
 (-4,-2.5) -- (4,-2.5);
% calculation of intersection points
% for the dashed lines and the curves 
\path[name intersections={of=upperline and rightcurve,by={a}}];
\path[name intersections={of=upperline and leftcurve,by={b}}];
\path[name intersections={of=lowerline and rightcurve,by={c}}];
\path[name intersections={of=lowerline and leftcurve,by={d}}];
% calculation of intersection points
% for the dashed lines and the y-axis
\path[name intersections={of=upperline and yaxis,by={e}}];
\path[name intersections={of=lowerline and yaxis,by={f}}];
% draw the dashed lines
\draw[dashed]
  (a) -- (b);
\draw[dashed]
  (c) -- (d);
% draw the upper ellipse
\draw[dashed] let
  \p1=(a),
  \p2=(b)
   in
  (b) arc(0:180:0.5*\x2-0.5*\x1 and 12pt);
\draw[thick] let
  \p1=(a),
  \p2=(b)
   in
  (b) arc(0:-180:0.5*\x2-0.5*\x1 and 12pt);
% draw the lower ellipse
\draw[dashed] let
  \p1=(c),
  \p2=(d)
   in
  (d) arc(0:180:0.5*\x2-0.5*\x1 and 10pt);
\draw[thick] let
  \p1=(c),
  \p2=(d)
   in
  (d) arc(0:-180:0.5*\x2-0.5*\x1 and 10pt);
% the gray background shading
\begin{pgfonlayer}{background}
\clip
  (a|-c) rectangle (b);
\fill[gray!20]
  (-3,4)  to[out=-90,in=110] 
  (-2,0) to[out=-70,in=140] 
  (-0.5,-4) --
  (0.5,-4) to[out=40,in=-110] 
  (2,0) to[out=70,in=-90] 
  (3,4) -- cycle;
\end{pgfonlayer}
% the arc indication rotation
\draw[->]
  (15pt,-4.7) arc(0:-325:15pt and 3pt);
% the thick red arrows
\node[tharrow,rotate=-50] 
  at (-2,3.7) {};
\node[tharrow,rotate=-50] 
  at (-1.2,-1.4) {};
\node[tharrow,rotate=-20] 
  at (-1.5,-4.4) {};
\node[tharrow,rotate=10] 
  at (-2.5,0.75) {};
% Some labels
\node[below left] 
  at (e) {$b$};
\node[below left] 
  at (f) {$a$};
\node[below right] 
  at (0,0) {$0$};
\node[below] 
  at (4.5,0) {$x$};
\node[left] 
  at (0,4.5,0) {$y$};
\end{tikzpicture}

\end{document}
2

This solution permits you to draw the rotated solid of an arbitrary function of y.

For this I've borrowed some superficial elements from Gonzalo Medina's superb answer, namely the thick red arrows and the arc indicating rotation.

rotated solid

Here is the code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows, shadows}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

% This function is a contrivance, but it looks about right!
\newcommand\fofy[1]{{((#1*0.8)^3 - 2*(#1*0.8)^2 + 6*(#1*0.8) + 40) / 20}}
\newcommand\Bbound{2.5}
\newcommand\Abound{-2.25}
\newcommand\BboundYval{(\fofy{\Bbound})}
\newcommand\AboundYval{(\fofy{\Abound})}

\definecolor{myred}{RGB}{232,75,68}

\begin{document}
    \begin{tikzpicture}[>=latex, tharrow/.style={ fill=myred, single arrow, minimum height=1.5cm, drop shadow,}]
        % background shading
        \fill [black!15, domain=\Bbound:\Abound] plot({\fofy{\x}}, {\x}) -- ( {-\fofy{\Abound}}, \Abound)  [domain=\Abound:\Bbound] plot({-\fofy{\x}}, {\x}) -- ({\fofy{\Bbound}}, \Bbound);

        % function and mirror
        \begin{scope}
            [domain=-2.75:3]
            \draw plot({\fofy{\x}}, {\x}) node [above] {$x = f(y)$} ;
            \draw[black!60] plot({-\fofy{\x}}, {\x});
        \end{scope}

        % Ellipses and Limits
            % Lower
        \draw [dotted] ({\fofy{\Abound}}, \Abound) arc (0:180:{\AboundYval} and {\AboundYval * 0.18 } );
        \draw  ({\fofy{\Abound}}, \Abound) arc (0:-180:{\AboundYval} and {\AboundYval * 0.18 } );
        \draw[dashed] ({\fofy{\Abound}}, \Abound) -- ({-\fofy{\Abound}}, \Abound cm) node [midway, below left] {$a$};
            % Upper
        \draw [dotted] ({\fofy{\Bbound}}, \Bbound) arc (0:180:{\BboundYval} and {\BboundYval * 0.18 } );
        \draw  ({\fofy{\Bbound}}, \Bbound) arc (0:-180:{\BboundYval} and {\BboundYval * 0.18 } );
        \draw[dashed] ({\fofy{\Bbound}}, \Bbound) -- ({-\fofy{\Bbound}}, \Bbound) node [midway, above left] {$b$};

        % arc indicating rotation
        \draw[->] (10pt,-3.15) arc(0:-310:10pt and 3pt);
        % big red arrows
        \node[tharrow,rotate=-50] at (-2,3.7) {};
        \node[tharrow,rotate=-55] at (-0.8,-1.3) {};
        \node[tharrow,rotate=-20] at (-1.4,-2.8) {};
        \node[tharrow,rotate=10]  at (-2.5,0.75) {};

        % axes
        \begin{scope}
            [very thin, ->]
            \draw (0, -3.5cm)  -- (0, 3.5cm) node [at end, left] {$y$} ;
            \draw  (-3cm,0) -- node [black, below right] {$0$} (3cm,0) node [at end, below] {$x$};
        \end{scope}
    \end{tikzpicture}
\end{document}

The ability to plot arbitrary functions makes this useful for writing exam problems and solutions!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .