2

I am creating a command to graph a surface rotated about the x-axis, only inputting the function, xmin and max and |y|. My issue is, I need to be able to input a value into my function, and use the output to properly move my arcs to be the "top" of the cone. Thus far, I have the following code, which works for just a function x. If I add a constant, or any degree on x, it no longer lines up correctly.

%Rotate about x - surface integral
\newcommand{\surfaceintx}[4]{\begin{tikzpicture}[/pgf/declare function={f=#1;}]
\begin{axis}[
        xmin=#2,xmax=#3+1,ymin=-#4-1,ymax=#4+1,
    domain=#2:#3,
    samples=100,
    axis lines=middle
]
%circle
\filldraw[draw=red,thick,fill=green,fill opacity=0.04]
 (axis cs:#3,-#4) arc[x radius=0.5cm, y radius=0.5cm+0.5*#3cm, start angle=270, end angle=90];
\filldraw[draw=red,dashed,fill=green,fill opacity=0.57]
 (axis cs:#3,-#4) arc[x radius=0.5cm, y radius=0.5cm+0.5*#3cm, start angle=270, end angle=-90];
 %circle
\addplot[name path=f,domain=#2:#3,red] {f};
    \path[name path=axis] (axis cs:#2,#2) -- (axis cs:#3,#2);
\addplot[name path=-#1,domain=#2:#3,red] {-#1};
\addplot [thick,color=green,fill=green,fill opacity=0.25]
    fill between[
        of=f and -#1,
        soft clip={domain=#2:#3},
    ]; 
\end{axis}
\end{tikzpicture}}
  • Welcome to TeX - LaTeX! Please complete your code snippet to a minimal working example (MWE) loading the necessary packages etc. – Andrew Swann Feb 6 '17 at 18:36
  • Could you add a sketch so we know what the output should look like? That would make much easier for us to help you. Thanks. – Stefan Pinnow Feb 8 '17 at 10:02
  • I changed the title of the question, because as the question is I cannot see any relation to \pgfmathparse. – Stefan Pinnow Feb 8 '17 at 10:45
3

As long as a sketch is missing in your question, I can only guess what you meant. Did I guess right?

If yes, you see that there is no need to declare a function or even use pgfplots stuff besides drawing the axis.

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        % use this `compat' level or higher to use the advanced features
        % placing ellipses and arcs
        compat=1.11,
    }
\newcommand{\surfaceintx}[4]{%
\begin{tikzpicture}
    % #1 = xmin  (start position of cone)
    % #2 = xmax  (end position of cone)
    % #3 = y     (start height of cone at xmin)
    % #4 = r     (radius of cone at xmax)
    \begin{axis}[
        xmin=#1,        xmax=#2+1,
        ymin=#3-#4-1,   ymax=#3+#4+1,
        axis lines=middle,
        axis on top,
    ]
        \filldraw [
            draw=red,
            fill=green!50,
        ] (axis cs:#2,#3+#4) -- (axis cs:#1,#3) -- (axis cs:#2,#3-#4);
        %circle
        \filldraw [
            draw=red,
            fill=green,
        ] (axis cs:#2,#3-#4) arc [
                x radius=0.125,
                y radius=#4,
                start angle=270,
                end angle=90,
            ];
        \filldraw [
            draw=red,
            fill=green,
        ] (axis cs:#2,#3-#4) arc [
            x radius=0.125,
            y radius=#4,
            start angle=-90,
            end angle=90,
        ];
    \end{axis}
\end{tikzpicture}
}
\begin{document}
    \surfaceintx{-1}{2}{2}{1}
\end{document}

image showing the result of above code

  • Thats impressive! – Jan Feb 9 '17 at 18:30
2

There is a MWE with PSTricks and TikZ.

enter image description here

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-node}
\begin{document}
\begin{pspicture}[dimen=m](8,10)
    \psellipticarc[linestyle=dotted](4,1)(4,.65){0}{180}
    \psellipticarcn(4,1)(4,.65){0}{180}
    \psline[linecap=0](0,1)(4,10)(8,1)
    \pcline[linestyle=dotted](4,10)(4,1)\naput{$h$}
    \pcline[linestyle=dotted](4,1)(8,1)\naput{$r$}
    \rput(4,1){\psline(0,9pt)(9pt,9pt)(9pt,0)}
\end{pspicture}
\end{document}

or

\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d,calc}

\begin{document}
\begin{tikzpicture}
    \draw (-1,0) arc (180:360:1cm and 0.5cm) -- (0,3) -- cycle;
    \draw[dashed] (-1,0) arc (180:0:1cm and 0.5cm);
    \shade[left color=yellow,right color=yellow,opacity=0.4] (-1,0) arc (180:360:1cm and 0.5cm) -- (0,3) -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

  • Sebastiano, I voted +1, but I think, the author requested TikZ. At least, the tags are set appropriately. – Jan Feb 9 '17 at 18:29
  • 1
    @Jan Thanks. I will work to create a cone with TikZ. – Sebastiano Feb 10 '17 at 9:06

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.