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}
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

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.