我看到了 Mark Wibrow 的 TIkZ 示例(http://www.texample.net/tikz/examples/disc/)。 原文答案在这里:tikz 堆叠磁盘 3D。我只需要一个圆盘,我可以修改圆盘的高度,也可以在其中放置极坐标。我能够将 3 个堆叠的圆盘减少为一个,并使用 Mark 的示例放置极坐标,但无法更改圆盘的高度。我需要降低它。
答案1
这是一个版本马克的精彩代码将参数存储在 pgf 键中。参数包括高度h
、半径r
、纵横比以及阴影的aspect
布尔值。bottom
\documentclass[tikz,border=10pt]{standalone}
\newif\iftikzdiscisbottom
\tikzset{
pics/.cd,
disc/.style = {
code = {
\tikzset{disc/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/disc/##1}}%
\iftikzdiscisbottom
\foreach \i in {0,2,...,30}
\fill [black, fill opacity = 1/60] (0,-0.1)
ellipse [x radius = \pv{r}+\i/40, y radius = \pv{r}*\pv{aspect}+\i/60];
\fi
\fill (0,\pv{h})[white] ellipse [x radius = \pv{r}, y radius = \pv{r}*\pv{aspect}];
\path [left color = black!50, right color = black!50,
middle color = black!25]
(-0.975*\pv{r},0) arc[start angle=180,end angle=360,
x radius=\pv{r}*0.975,y radius=\pv{r}*\pv{aspect}*0.975] -- cycle;
\path [top color = black!25, bottom color = white]
(0,.05*\pv{r}*\pv{aspect}+\pv{h})
ellipse [x radius = 0.975*\pv{r}, y radius = \pv{r}*\pv{aspect}*0.975];
\path [left color = black!25, right color = black!25,
middle color = white] (-\pv{r},\pv{h}) -- (-\pv{r},0)
arc[start angle=180,end angle=360,
x radius=\pv{r},y radius=\pv{r}*\pv{aspect}]
-- (\pv{r},\pv{h})
arc[start angle=360,end angle=180,
x radius=\pv{r},y radius=\pv{r}*\pv{aspect}];
\foreach \r in {225,315}
\foreach \i [evaluate = {\s=30;}] in {0,2,...,30}
\fill [black, fill opacity = 1/50]
(0,\pv{h}) -- ++ (\r+\s-\i:\pv{r} and \pv{r}*\pv{aspect})
-- ++(0,-\pv{h})
arc[start angle=\r+\s-\i,end angle=\r-\s+\i,
x radius = \pv{r}, y radius = \pv{r}*\pv{aspect}]
-- ++(0,\pv{h}) -- cycle;
\foreach \r in {45,135}
\foreach \i [evaluate = {\s=30;}] in {0,2,...,30}
\fill [black, fill opacity = 1/50]
(0,\pv{h}) -- ++ (\r+\s-\i:\pv{r} and \pv{r}*\pv{aspect})
arc[start angle=\r+\s-\i,end angle=\r-\s+\i,
x radius = \pv{r}, y radius = \pv{r}*\pv{aspect}] -- cycle;
}
},/tikz/disc/.cd,h/.initial=1.1,r/.initial=2,aspect/.initial=1/3,
bottom/.is if=tikzdiscisbottom
}
\begin{document}
\begin{tikzpicture}
\path (0,0) pic {disc={h=2,bottom=true}}
(5,0) pic {disc={h=3,r=1.5,aspect=1/4}};
\end{tikzpicture}
\end{document}