我想做像下图这样的网格或者格子壳?
\documentclass[tikz]{standalone}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{backgrounds,patterns,calc}
\usepackage{xparse}
\begin{document}
\pgfmathsetmacro{\x}{5}
\pgfmathsetmacro{\y}{-60}
\tdplotsetmaincoords{\x}{\y}
\begin{tikzpicture}[tdplot_main_coords]
\filldraw[ fill=white,looseness=1] (3.6,0,-21)to[bend right] (1.7,3.2,-13)--(1.8,3.5,-12) to[bend left] (4,0,-22)-- cycle;
\filldraw[ fill=green!20,looseness=1] (4,0,-22)to[bend right] (1.8,3.5,-12)--(1.8,3.5,30) to[bend left] (4,0,20)-- cycle;
\end{tikzpicture}
\end{document}
答案1
我想不出更自动化的方法:
\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc}
\begin{document}
\pgfmathsetmacro{\x}{5}
\pgfmathsetmacro{\y}{-60}
\tdplotsetmaincoords{\x}{\y}
\newcommand*{\gridstep}{0.15}
\begin{tikzpicture}[tdplot_main_coords]
\filldraw[fill=white,looseness=1] (3.6,0,-21) coordinate (under surface right) to[bend right] (1.7,3.2,-13) coordinate (under surface left) -- coordinate (middle left) (1.8,3.5,-12) coordinate (bottom left) to[bend left] (4,0,-22) coordinate (bottom right) -- coordinate (middle right) cycle;
\filldraw[fill=green!20,looseness=1] (4,0,-22) to[bend right] (1.8,3.5,-12) -- (1.8,3.5,30) coordinate (top left) to[bend left] (4,0,20) coordinate (top right) -- cycle;
\foreach[count=\ii] \i in {0,\gridstep,...,1}{
\path (bottom left) to[bend left] coordinate[pos=\i](p\ii) (bottom right);
\path (under surface left) to[bend left] coordinate[pos=\i](k\ii) (under surface right);
\draw (p\ii) -- ++(0,0,42);
\draw (p\ii) -- (k\ii);
\draw ($(bottom left)!\i!(top left)$) to[bend left] ($(bottom right)!\i!(top right)$);
};
\draw (middle left) to[bend left] (middle right);
\end{tikzpicture}
\end{document}
一切都围绕中间路径指定的坐标进行设置,因此如果您决定更改几何图形,网格应该会正确遵循它。我还创建了一个\gridstep
保存步长值的命令(以百分比表示),更改它将重新制作整个网格,除了从底部表面到顶部的线,该线是单独绘制的。