0

I used the following code, below which is altered from https://latexdraw.com/draw-a-plane-intersecting-a-cone-in-latex/

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}

\pgfplotsset{compat = newest}

\begin{document}

%Draw axis x, y and z, with grid on each plane of the axis

\begin{tikzpicture}
        \begin{axis}[
            axis equal image,
            grid = both,
            minor tick num = 2,
            xlabel = {$x$},
            ylabel = {$y$},
            zlabel = {$z$},
            major grid style = {draw = lightgray},
            minor grid style = {draw = lightgray!25},
            legend cell align={left},
            xmin = -1, xmax = 1,
            ymin = -1, ymax = 1,
            scale = 3,
            zmin = 0, zmax = 2,
            z buffer = sort,
        ]                      
        % Here comes the code
    
\addplot3[
    surf,
    shader = interp,
    samples = 50,
    samples y = 20,
    domain = 0:2*pi,
    domain y = 0:1,
    colormap/violet,
]
 (
    {cos(deg(x)) * y},
    {sin(deg(x)) * y},
    {y}
 );

    \end{axis}
\end{tikzpicture}

\end{document}

but it has inverted the cone and I cannot think why, I tried to alter the z-axis to -y but this didn't work. Can anybody help me to turn the cone around? Thanks.

1 Answer 1

2

You can change the z-coordinate to {1-y} instead of {y}:

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}

\pgfplotsset{compat = newest}

\begin{document}

%Draw axis x, y and z, with grid on each plane of the axis

\begin{tikzpicture}
        \begin{axis}[
            axis equal image,
            grid = both,
            minor tick num = 2,
            xlabel = {$x$},
            ylabel = {$y$},
            zlabel = {$z$},
            major grid style = {draw = lightgray},
            minor grid style = {draw = lightgray!25},
            legend cell align={left},
            xmin = -1, xmax = 1,
            ymin = -1, ymax = 1,
            scale = 3,
            zmin = 0, zmax = 2,
            z buffer = sort,
        ]                      
        % Here comes the code
    
\addplot3[
    surf,
    shader = interp,
    samples = 50,
    samples y = 20,
    domain = 0:2*pi,
    domain y = 0:1,
    colormap/violet,
]
 (
    {cos(deg(x)) * y},
    {sin(deg(x)) * y},
    {1-y}
 );

    \end{axis}
\end{tikzpicture}

\end{document}

That adjustment gives this output: Cone "inverted"

You must log in to answer this question.

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