点画

点画

有什么办法可以生成这样的图形:

在此处输入图片描述

或这个

在此处输入图片描述

使用 TikZ?

答案1

点画

自从 Mark Wibrow 向我们展示how to get stippling,让我们使用它:

在此处输入图片描述

代码:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations,calc,intersections}

%Mark Wibrow's code for stippling
% https://tex.stackexchange.com/a/267037/3954
\pgfkeys{/pgf/decoration/.cd,
  stipple density/.store in=\pgfstippledensity,
  stipple density=.1,
  stipple scaling function/.store in=\pgfstipplescalingfunction,
  stipple scaling function=sin(\pgfstipplex*180)*0.875+0.125,
  stipple radius/.store in=\pgfstippleradius,
  stipple radius=0.25pt
}
\pgfdeclaredecoration{stipple}{draw}{
\state{draw}[width=\pgfdecorationsegmentlength]{
  \pgfmathparse{\pgfdecoratedcompleteddistance/\pgfdecoratedpathlength}%
  \let\pgfstipplex=\pgfmathresult%
  \pgfmathparse{int(\pgfstippledensity*100)}%
  \let\pgfstipplen=\pgfmathresult
  \pgfmathloop
  \ifnum\pgfmathcounter<\pgfmathresult\relax
    \pgfpathcircle{%
      \pgfpoint{(rnd)*\pgfdecorationsegmentlength}%
        {(\pgfstipplescalingfunction)*(rnd^4)*\pgfdecorationsegmentamplitude+\pgfstippleradius}}% 
    {\pgfstippleradius}%
  \repeatpgfmathloop
}
}

\tikzset{stipple/.style={
  decoration={stipple, segment length=2pt, #1},
  decorate,
  fill
}}
% end of stippling code

\newcommand\DrawBlock[3]{
\ifx#1b\relax
  \path[draw]
    (lm\the\numexpr#2-1\relax) -- ++(0,0,#3) coordinate (blocklf)
    (bm\the\numexpr#2-1\relax) -- ++(0,0,#3) coordinate (blocklb)
    (lm#2) -- ++(0,0,#3) coordinate (blockrf)
    (bm#2) -- ++(0,0,#3) coordinate (blockrb);
  \filldraw[fill=white,draw=black]
    (lm\the\numexpr#2-1\relax) -- (blocklf) -- (blocklb) -- (blockrb) -- (blockrf) -- (lm#2);
\else  
  \ifx#1f\relax
    \path[draw]
      (fm\the\numexpr#2-1\relax) -- ++(0,0,#3) coordinate (blocklf)
      (lm\the\numexpr#2-1\relax) -- ++(0,0,#3) coordinate (blocklb)
      (fm#2) -- ++(0,0,#3) coordinate (blockrf)
      (lm#2) -- ++(0,0,#3) coordinate (blockrb);
    \filldraw[fill=white,draw=black]
      (fm\the\numexpr#2-1\relax) -- (blocklf) -- (blocklb) -- (blockrb) -- (blockrf) -- (fm#2);
  \fi
\fi
\draw (blocklf) -- (blockrf);
}

\begin{document}
\begin{tikzpicture}[y={(0:1cm)},x={(225:0.86cm)}, z={(90:1cm)}]

% coordinates for the lower grid
\path
  (1,3,0) coordinate (bm0) -- 
  (4,3,0) coordinate (fm0) coordinate[midway] (lm0) --
  (4,8,0) coordinate[pos=0.25] (fm1) coordinate[midway] (fm2) coordinate[pos=0.75] (fm3) coordinate (fm4) --
  (1,8,0) coordinate (bm4) coordinate[midway] (lm4)--
  (bm0) coordinate[pos=0.25] (bm3) coordinate[midway] (bm2) coordinate[pos=0.75] (bm1);
\draw[dashed]
  (lm0) -- 
  (lm4) coordinate[pos=0.25] (lm1) coordinate[midway] (lm2) coordinate[pos=0.75] (lm3);

% the blocks
\DrawBlock{b}{1}{4}
\DrawBlock{b}{2}{3.7}
\DrawBlock{b}{3}{4.3}
\DrawBlock{b}{4}{5}
\DrawBlock{f}{1}{3.3}
\DrawBlock{f}{2}{3.5}
\DrawBlock{f}{3}{4}
\DrawBlock{f}{4}{4.7}

\foreach \Point/\Height in {lm1/3.7,lm2/4.3,lm3/5}
  \draw[ultra thin,dashed,opacity=0.2] (\Point) -- ++(0,0,\Height);

% the lower grid
\foreach \x in {1,2,3}
  \draw[dashed] (fm\x) -- (bm\x);
\draw[dashed] (fm0) -- (bm0) -- (bm4);
\draw (fm0) -- (fm4) -- (bm4);
\draw[dashed] (lm0) -- (lm4);

% coordinates for the surface
\coordinate (curvefm0) at ( $ (fm0) + (0,0,4) $ );
\coordinate (curvebm0) at ( $ (bm0) + (0,0,4) $ );
\coordinate (curvebm4) at ( $ (bm4) + (0,0,6) $ );
\coordinate (curvefm4) at ( $ (fm4) + (0,0,5.7) $ );

% the surface
\filldraw[ultra thick,fill=gray!25,fill opacity=0.2]
  (curvefm0) to[out=-30,in=210] 
  (curvefm4) to[out=-4,in=260]
  (curvebm4) to[out=215,in=330]
  (curvebm0) to[out=240,in=-20]
  (curvefm0);

% lines from grid to surface
\draw[very thick,name path=leftline] (curvefm0) -- (fm0);
\draw[very thick] (curvefm4) -- (fm4);
\draw[very thick,name path=rightline] (curvebm4) -- (bm4);
\draw[very thick,dashed] (curvebm0) -- (bm0);

% coordinate system
\coordinate (O) at (0,0,0);
\draw[-latex] (O) -- +(5,0,0) node[above left] {$x$};
\path[name path=yaxis] (O) -- +(0,10,0) coordinate (yaxisfinal) node[above] {$y$};
\draw[-latex] (O) -- +(0,0,5) node[left] {$z$};
\path[name intersections={of=yaxis and leftline,by={yaxis1}}];
\path[name intersections={of=yaxis and rightline,by={yaxis2}}];
\draw (O) -- (yaxis1);
\draw[densely dashed,opacity=0.1] (yaxis1) -- (yaxis2);
\draw[-latex] (yaxis2) -- (yaxisfinal);

% the stippling
\path[postaction={stipple={amplitude=1cm,stipple density=0.15}}]
  ( $ (fm4) + (0,0,4.7) $ ) -- (fm4);
\path[postaction={stipple={amplitude=1cm,stipple density=0.05}}]
  ( $ (lm4) + (0,0,4.7) $ ) -- (lm4);

% for debugging
%\foreach \Name in {bm0,fm0,lm0,fm1,fm2,fm3,fm4,bm4,lm4,bm1,bm2,bm3,lm1,lm2,lm3,%
%curvefm0,curvebm0,curvebm4,curvefm4}
%  \node at (\Name) {\Name};  
\end{tikzpicture}

\end{document}

无点画

在此处输入图片描述

代码:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\newcommand\DrawBlock[3]{
\ifx#1b\relax
  \path[draw]
    (lm\the\numexpr#2-1\relax) -- ++(0,0,#3) coordinate (blocklf)
    (bm\the\numexpr#2-1\relax) -- ++(0,0,#3) coordinate (blocklb)
    (lm#2) -- ++(0,0,#3) coordinate (blockrf)
    (bm#2) -- ++(0,0,#3) coordinate (blockrb);
  \filldraw[fill=white,draw=black]
    (lm\the\numexpr#2-1\relax) -- (blocklf) -- (blocklb) -- (blockrb) -- (blockrf) -- (lm#2);
\else  
  \ifx#1f\relax
    \path[draw]
      (fm\the\numexpr#2-1\relax) -- ++(0,0,#3) coordinate (blocklf)
      (lm\the\numexpr#2-1\relax) -- ++(0,0,#3) coordinate (blocklb)
      (fm#2) -- ++(0,0,#3) coordinate (blockrf)
      (lm#2) -- ++(0,0,#3) coordinate (blockrb);
    \filldraw[fill=white,draw=black]
      (fm\the\numexpr#2-1\relax) -- (blocklf) -- (blocklb) -- (blockrb) -- (blockrf) -- (fm#2);
  \fi
\fi
\draw (blocklf) -- (blockrf);
}

\begin{document}
\begin{tikzpicture}[y={(0:1cm)},x={(225:0.86cm)}, z={(90:1cm)}]

% coordinates for the lower grid
\path
  (1,3,0) coordinate (bm0) -- 
  (4,3,0) coordinate (fm0) coordinate[midway] (lm0) --
  (4,8,0) coordinate[pos=0.25] (fm1) coordinate[midway] (fm2) coordinate[pos=0.75] (fm3) coordinate (fm4) --
  (1,8,0) coordinate (bm4) coordinate[midway] (lm4)--
  (bm0) coordinate[pos=0.25] (bm3) coordinate[midway] (bm2) coordinate[pos=0.75] (bm1);
\draw[dashed]
  (lm0) -- 
  (lm4) coordinate[pos=0.25] (lm1) coordinate[midway] (lm2) coordinate[pos=0.75] (lm3);

% the blocks
\DrawBlock{b}{1}{4}
\DrawBlock{b}{2}{3.7}
\DrawBlock{b}{3}{4.3}
\DrawBlock{b}{4}{5}
\DrawBlock{f}{1}{3.3}
\DrawBlock{f}{2}{3.5}
\DrawBlock{f}{3}{4}
\DrawBlock{f}{4}{4.7}

\foreach \Point/\Height in {lm1/3.7,lm2/4.3,lm3/5}
  \draw[ultra thin,dashed,opacity=0.2] (\Point) -- ++(0,0,\Height);

% the lower grid
\foreach \x in {1,2,3}
  \draw[dashed] (fm\x) -- (bm\x);
\draw[dashed] (fm0) -- (bm0) -- (bm4);
\draw (fm0) -- (fm4) -- (bm4);
\draw[dashed] (lm0) -- (lm4);

% coordinates for the surface
\coordinate (curvefm0) at ( $ (fm0) + (0,0,4) $ );
\coordinate (curvebm0) at ( $ (bm0) + (0,0,4) $ );
\coordinate (curvebm4) at ( $ (bm4) + (0,0,6) $ );
\coordinate (curvefm4) at ( $ (fm4) + (0,0,5.7) $ );

% the surface
\filldraw[ultra thick,fill=gray!25,fill opacity=0.2]
  (curvefm0) to[out=-30,in=210] 
  (curvefm4) to[out=-4,in=260]
  (curvebm4) to[out=215,in=330]
  (curvebm0) to[out=240,in=-20]
  (curvefm0);

% lines from grid to surface
\draw[very thick,name path=leftline] (curvefm0) -- (fm0);
\draw[very thick] (curvefm4) -- (fm4);
\draw[very thick,name path=rightline] (curvebm4) -- (bm4);
\draw[very thick,dashed] (curvebm0) -- (bm0);

% coordinate system
\coordinate (O) at (0,0,0);
\draw[-latex] (O) -- +(5,0,0) node[above left] {$x$};
\path[name path=yaxis] (O) -- +(0,10,0) coordinate (yaxisfinal) node[above] {$y$};
\draw[-latex] (O) -- +(0,0,5) node[left] {$z$};
\path[name intersections={of=yaxis and leftline,by={yaxis1}}];
\path[name intersections={of=yaxis and rightline,by={yaxis2}}];
\draw (O) -- (yaxis1);
\draw[densely dashed,opacity=0.1] (yaxis1) -- (yaxis2);
\draw[-latex] (yaxis2) -- (yaxisfinal);

% for debugging
%\foreach \Name in {bm0,fm0,lm0,fm1,fm2,fm3,fm4,bm4,lm4,bm1,bm2,bm3,lm1,lm2,lm3,%
%curvefm0,curvebm0,curvebm4,curvefm4}
%  \node at (\Name) {\Name};  
\end{tikzpicture}

\end{document}

答案2

不确定这是否正确,但无论如何......

\documentclass[tikz,border=5]{standalone}
\begin{document}
\begin{tikzpicture}[
  x=(215:2em/sqrt 2), y=(0:2em), z=(90:2em),
  declare function={f(\x,\y)=((\x-3)^2+(-\y+3)^3)/8+3;}, 
  very thick, line join=round]
\draw [-stealth, black!75] (0,0,0) -- (5,0,0) node [below left] {$x$};
\draw [-stealth, black!75] (0,0,0) -- (0,5,0) node [below right] {$y$};
\draw [-stealth, black!75] (0,0,0) -- (0,0,5) node [right] {$z$};
\foreach \x in {1,...,4}
  \foreach \y [evaluate={\j=\x+.5; \i=\y+.5; \k=f(\j,\i);}] in {1,...,4}{
    \path [fill=black!50, draw=white] (\x, \y+1, 0) -- (\x+1, \y+1, 0) -- 
      (\x+1, \y+1, \k) -- (\x, \y+1, \k) -- cycle;
    \path [fill=black!25, draw=white] (\x+1, \y, 0) -- (\x+1, \y+1, 0) -- 
      (\x+1, \y+1, \k) -- (\x+1, \y, \k) -- cycle;
    \path [fill=black!10, draw=white] (\x, \y, \k)  -- (\x+1, \y, \k) -- 
      (\x+1, \y+1, \k) -- (\x, \y+1, \k) -- cycle;
  }
 \foreach \x in {1,...,4}
   \foreach \y in {1,...,4}{
 \draw [black, fill=black, fill opacity=0.125, 
    domain=0:1, samples=10, variable=\t] 
    plot (\x+\t, \y, {f(\x+\t,\y)}) -- 
    plot (\x+1, \y+\t, {f(\x+1,\y+\t)}) -- 
    plot (\x+1-\t, \y+1, {f(\x+1-\t,\y+1)}) --
    plot (\x, \y+1-\t, {f(\x,\y+1-\t)}) -- cycle;
  }
\end{tikzpicture}
\end{document}

在此处输入图片描述

如果选项中有几件事发生改变tikzpicture

x=(215:2em/sqrt 2), y=(325:2em/sqrt 2), z=(90:1.5em),
declare function={f(\x,\y)=((\x-3)^2+(-\y+2)^3)/8+4;}, 

结果是:

在此处输入图片描述

相关内容