pgf在域 0:2*pi 上繪製 exp(-pow(deg(x),2)

pgf在域 0:2*pi 上繪製 exp(-pow(deg(x),2)

這段程式碼向我拋出一個錯誤,「維度太大」。我不知道如何修復。我剛剛測量了全局錯誤的來源,這個簡短的片段:

\begin{tikzpicture} 
\begin{axis}[axis lines=none,no markers,samples=50,grid=both]
\addplot3[mesh, domain=0:2*pi] {exp(-pow(deg(x),2))}; 
\end{axis}
\end{tikzpicture}

我需要在該域上繪製這個函數。有辦法做到這一點嗎?數學意味著: $$e^{-deg(x)^2}$$ (順便說一句,我不知道,deg(**) 是做什麼用的?)

tikz我的全部目標是:用或繪製克萊因瓶pgfplots

答案1

我使用給出的方程式和參數德文維基「克萊因瓶」的條目給出以下結果。 (此外,我使用了 LuaLaTeX 和 PGFPlots 的 Lua 後端,它計算結果的速度相當快。)

% used PGFPlots v1.14
\RequirePackage{luatex85}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        % use this `compat' level or higher to use the Lua backend
        compat=1.12,
        % used equations and parameters from
        % <https://de.wikipedia.org/w/index.php?title=Kleinsche_Flasche&oldid=160519755#Beschreibung_im_3-dimensionalen_Raum>
        /pgf/declare function={
            b = 2;
            h = 6;
            r(\u) = 2 - cos(\u);
%            x(\u,\v) = b * (1 - sin(\u)) * cos(\u);
%                       + r(\u) * cos(\v) * (2 * exp( -(\u/2 - pi)^2 ) - 1);
%            y(\u,\v) = r(\u) * sin(\v);
%            z(\u,\v) = h * sin(\u)
%                       + 0.5 * r(\u) * sin(\u) * cos(\v) * exp( -(\u-3*pi/2)^2 );
        },
    }
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
%            axis lines=none,
            % use radians as input for the trigonometric functions
            % (this avoids converting the numbers to `deg' format first)
            trig format plots=rad,
            domain=0:2*pi,
            samples=50,
            % change variables from `x' and `y' to `u' and `v'
            variable=u,
            variable y=v,
            colormap/viridis,
        ]
            \addplot3 [
%                mesh,
                % I use suf here, because it just looks better ;)
                surf,
                z buffer=sort,
                fill opacity=0.35,
            ] (
                % unfortunately these give an error ...
%                {x(u,v)},
%                {y(u,v)},
%                {z(u,v)},
                % ... so we write them directly
                {b * (1 - sin(u)) * cos(u) + r(u) * cos(v) * (2 * exp( -(u/2 - pi)^2 ) - 1)},
                {r(u) * sin(v)},
                {h * sin(u) + 0.5 * r(u) * sin(u) * cos(v) * exp( -(u - 3 * pi / 2)^2 )}
            );
        \end{axis}
    \end{tikzpicture}
\end{document}

顯示上述程式碼結果的圖像

答案2

這做到了。

\pgfplotsset{%
        colormap = {black}{%
            color(0cm)  = (black);%
            color(1cm) = (black)}%
    }

\begin{tikzpicture}
\def\rotation{0}

    \begin{axis}[axis lines=none, rotate around={\rotation:(current axis.origin)}]
    \addplot3[mesh, z buffer=sort,domain=0:180, domain y=0:360, samples=41, samples y=25,   point meta=x] 
        (
        {-2/15 * cos(x) * (
            3*cos(y) - 30*sin(x) 
          + 90 *cos(x)^4 * sin(x) 
          - 60 *cos(x)^6 * sin(x)  
          + 5 * cos(x)*cos(y) * sin(x))
         },
         {-1/15 * sin(x) * (3*cos(y) 
          - 3*cos(x)^2 * cos(y) 
          - 48 * cos(x)^4*cos(y) 
          + 48*cos(x)^6 *cos(y) 
          - 60 *sin(x) 
          + 5*cos(x)*cos(y)*sin(x) 
          - 5*cos(x)^3 * cos(y) *sin(x) 
          - 80*cos(x)^5 * cos(y)*sin(x) 
          + 80*cos(x)^7 * cos(y) * sin(x))
         },
        {2/15 * (3 + 5*cos(x) *sin(x))*sin(y)}      
        );
    \end{axis}
\end{tikzpicture}

相關內容