4

I'm trying to draw a nice three-dimensional diagram using PGFplots. Its Z axis should be logarithmic. Unfortunately when the values get to small, the precision isn't enough to get a smooth curve. Hope this MWE is ok...

Thanks for your tips.

\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{ngerman}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        view={140}{20},
        grid=major,
%
        xlabel style={sloped},
        xlabel={Bildschirmdiagonale $h$},
        x dir=reverse,
%       
        ylabel style={sloped},
        ylabel={Entfernung $d$},
%
        zlabel={Raumwinkel $\Omega$},
        zmode=log,
    ]
        \addplot3[
            mesh,
            domain=20:60,
            y domain=2:20,
        ] { 4*pi/180*atan( ((12*x)*(22*x)) / (2*1000*y*sqrt(4*(1000*y)^2+(22*x)^2+(12*x)^2)) ) };
    \end{axis}
\end{tikzpicture}

\end{document}
New contributor
Florian Strobel is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3

What sometimes helps is to analytically manipulate the expressions. All I did was to divide numerator and denominator by 10, such that the (1000*y)^2 in the square root becomes (100*y)^2. This yields

\documentclass[a4paper,11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        view={140}{20},
        grid=major,
%
        xlabel style={sloped},
        xlabel={Bildschirmdiagonale $h$},
        x dir=reverse,
%       
        ylabel style={sloped},
        ylabel={Entfernung $d$},
%
        zlabel={Raumwinkel $\Omega$},
        zmode=log,
    ]
        \addplot3[
            mesh,
            domain=20:60,
            y domain=2:20,
        ] {0.1* 4*pi/180*atan( ((12*x)*(22*x)) /
        (2*1000*y*sqrt(4*(100*y)^2+(2.2*x)^2+(1.2*x)^2)) ) };
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

As you see the wiggles are gone. And one may go on using this until one is fine with the outcome.

Your Answer

Florian Strobel is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.