拓扑学家需要解释咖啡杯与甜甜圈同胚。有很多画甜甜圈的好方法。到目前为止,我最好的尝试是
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shadings}
\begin{document}
\begin{tikzpicture}
\shade[ball color=gray!10] (-2,0) arc (180:360:2cm);
\shade[left color=gray!10, right color=gray!80] (-2,0) arc (180:540:2cm and 1cm);
\fill[top color=gray!50,bottom color=gray!80] (1.8,-.45) arc (135:225:.35cm) arc (45:-150:.35cm) arc (90:270:.25cm) arc (-90:45:.85cm) -- cycle;
\end{tikzpicture}
\end{document}
答案1
本页上的杯子数量不断增加,这只是其中的一小部分:
\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\tikzfading[name=fade out, inner color=transparent!0, outer color=transparent!100]
\begin{document}
\begin{tikzpicture}
% Saucer
\begin{scope}[shift={(0,-1)}]
\fill [black!87.5, path fading=fade out]
(0,-2/8) ellipse [x radius=6/4, y radius=3/4];
\shade [left color=gray!20, right color=gray!80]
(0,0) ++(180:1.25) arc (180:360:5/4 and 5/8+1/16);
\shade [left color=gray!40, right color=gray!20]
(0,0) ellipse [x radius=5/4, y radius=5/8];
\shade [right color=gray!40, left color=gray!20]
(0,0) ellipse [x radius=5/4/2, y radius=5/8/2];
\shade [left color=gray!40, right color=gray!20]
(0,-1/16) ellipse [x radius=5/4/2-1/16, y radius=5/8/2-1/16];
\end{scope}
% Handle
\begin{scope}[shift=(10:7/8), rotate=-30, yslant=1/2, xslant=-1/8]
\shade [top color=gray!80, bottom color=gray!30]
(0,0) arc (130:-100:3/8 and 1/2) -- ++(0,1/4) arc (-100:130:1/8 and 1/4) -- cycle;
\shade [top color=gray!10, bottom color=gray!60]
(0,0) arc (130:-100:3/8 and 1/2) -- ++(0,1/32) arc (-100:130:1/4 and 1/3) -- cycle;
\end{scope}
% Cup
\fill [black!75, path fading=fade out]
(0,-1) ellipse [x radius=3/4, y radius=1/2];
\shade [left color=gray!60, right color=gray!30]
(-1,0) arc (180:360:1 and 5/4);
\shade [bottom color=gray, top color=gray!30, opacity=1/2]
(-1,0) arc (180:360:1 and 5/4);
\shade [left color=gray!20, right color=gray!40]
(0,0) ellipse [x radius=1, y radius=1/2];
\shade [left color=gray!40, right color=gray!20]
(0,0) ellipse [x radius=1-1/16, y radius=1/2-1/16];
\shade [bottom color=gray, top color=gray!10, opacity=1/2]
(0,0) ellipse [x radius=1-1/16, y radius=1/2-1/16];
% Coffee
\begin{scope}
\clip ellipse [x radius=1-1/16, y radius=1/2-1/16];
\fill [brown!25!black]
(0,-1/4) ellipse [x radius=3/4, y radius=3/8];
\fill [brown!50!black, path fading=fade out]
(0,-1/4) ellipse [x radius=3/4, y radius=3/8];
\end{scope}
\end{tikzpicture}
\end{document}
显然我今天已经放弃做任何“正经”的工作了:
\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings}
\tikzfading[name=fade out, inner color=transparent!0, outer color=transparent!100]
\begin{document}
\begin{tikzpicture}
\foreach \c [count=\i from 0] in {white,gray,red!75!black,blue!25, purple,orange}{
\tikzset{xshift={mod(\i,2)*3cm}, yshift=-floor(\i/2)*3cm}
\colorlet{cup}{\c}
% Saucer
\begin{scope}[shift={(0,-1-1/16)}]
\fill [black!87.5, path fading=fade out]
(0,-2/8) ellipse [x radius=6/4, y radius=3/4];
\fill [cup, postaction={left color=black, right color=white, opacity=1/3}]
(0,0) ++(180:5/4) arc (180:360:5/4 and 5/8+1/16);
\fill [cup, postaction={left color=black!50, right color=white, opacity=1/3}]
(0,0) ellipse [x radius=5/4, y radius=5/8];
\fill [cup, postaction={left color=white, right color=black, opacity=1/3}]
(0,1/16) ellipse [x radius=5/4/2, y radius=5/8/2];
\fill [cup, postaction={left color=black, right color=white, opacity=1/3}]
(0,0) ellipse [x radius=5/4/2-1/16, y radius=5/8/2-1/16];
\end{scope}
% Handle
\begin{scope}[shift=(10:7/8), rotate=-30, yslant=1/2, xslant=-1/8]
\fill [cup, postaction={top color=black, bottom color=white, opacity=1/3}]
(0,0) arc (130:-100:3/8 and 1/2) -- ++(0,1/4) arc (-100:130:1/8 and 1/4) -- cycle;
\fill [cup, postaction={top color=white, bottom color=black, opacity=1/3}]
(0,0) arc (130:-100:3/8 and 1/2) -- ++(0,1/32) arc (-100:130:1/4 and 1/3) -- cycle;
\end{scope}
% Cup
\fill [cup!25!black, path fading=fade out]
(0,-1-1/16) ellipse [x radius=3/4, y radius=1/3];
\fill [cup, postaction={left color=black, right color=white, opacity=1/3/2},
postaction={bottom color=black, top color=white, opacity=1/3/2}]
(-1,0) arc (180:360:1 and 5/4);
\fill [cup, postaction={left color=white, right color=black, opacity=1/3}]
(0,0) ellipse [x radius=1, y radius=1/2];
\fill [cup, postaction={left color=black, right color=white, opacity=1/3/2},
postaction={bottom color=black, top color=white, opacity=1/3/2}]
(0,0) ellipse [x radius=1-1/16, y radius=1/2-1/16];
% Coffee
\begin{scope}
\clip ellipse [x radius=1-1/16, y radius=1/2-1/16];
\fill [brown!25!black]
(0,-1/4) ellipse [x radius=3/4, y radius=3/8];
\fill [brown!50!black, path fading=fade out]
(0,-1/4) ellipse [x radius=3/4, y radius=3/8];
\end{scope}
}
\end{tikzpicture}
\end{document}
答案2
我认为,当有咖啡杯赏金已经存在:
以上所有图片均为开源,可在Inkscape。此外,如果需要,它可以按原样导出为各种矢量格式(如果没有从源下载 PDF),或者使用导出到 TikZinkscape2tikz
(但从未尝试过)。
答案3
那么,如果切开之后真的变成了甜甜圈(或多或少很平滑)呢?
代码
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shadings}
\begin{document}
\foreach \x in {0,...,10}
{ \begin{tikzpicture}
\shade[left color=gray!80, right color=gray!30] (-2,0-\x*0.04) -- (-2,-4+\x*0.04) arc (180:360:2 and 0.5) -- (2,0-\x*0.04) arc (360:180:2 and 0.5);
\shade[left color=gray!60, right color=gray!20,even odd rule] (0,0-\x*0.04) circle (2 and 0.5) (0,0-\x*0.04) circle (1.8+\x*0.02 and 0.45+\x*0.005);
\shade[left color=gray!30, right color=gray!80] (0,0-\x*0.04) circle (1.8+\x*0.02 and 0.45+\x*0.005);
\begin{scope}
\clip (2,-0.4) arc (90:270:0.05-\x*0.005 and 0.2) arc (90:-90:0.6 and 1.2) arc (90:270:0.05-\x*0.005 and 0.2) arc (-90:90:0.8 and 1.6);
\fill[inner color=white, outer color=gray!60] (2,-2) circle (0.8 and 1.6);
\end{scope}
\draw (-2.1,-4.6) rectangle (2.9,0.6);
\end{tikzpicture}
}
\foreach \x in {0,...,10}
{ \begin{tikzpicture}
\shade[left color=gray!80, right color=gray!30] (-2+\x*0.36,-0.4) -- (-2+\x*0.36,-3.6) arc (180:360:2-\x*0.18 and 0.5-\x*0.05) -- (2,-0.4) arc (360:180:2-\x*0.18 and 0.5-\x*0.05);
\shade[left color=gray!30, right color=gray!80] (0+\x*0.18,-0.4) circle (2-\x*0.18 and 0.5-\x*0.05);
\begin{scope}
\clip (2,-0.4) -- ++(0,-0.4) arc (90:-90:0.6 and 1.2) -- ++(0,-0.4) arc (-90:90:0.8 and 1.6);
\fill[inner color=white, outer color=gray!60] (2,-2) circle (0.8 and 1.6);
\end{scope}
\draw (-2.1,-4.6) rectangle (2.9,0.6);
\end{tikzpicture}
}
\foreach \x in {0,...,10}
{ \begin{tikzpicture}
\begin{scope}
\clip (2,-0.4) -- ++(-0.4+\x*0.04,0) arc (90:270:\x*0.08 and 1.6) -| ++(0.4-\x*0.04,0.4) arc (270:90:\x*0.06 and 1.2);
\fill[inner color=white, outer color=gray!60] (1.2,-0.4) rectangle ++(1.6,-3.2);
\end{scope}
\begin{scope}
\clip (2,-0.4) -- ++(0,-0.4) arc (90:-90:0.6 and 1.2) -- ++(0,-0.4) arc (-90:90:0.8 and 1.6);
\fill[inner color=white, outer color=gray!60] (2,-2) circle (0.8 and 1.6);
\end{scope}
\draw (-2.1,-4.6) rectangle (2.9,0.6);
\end{tikzpicture}
}
\foreach \x in {0,...,10}
{ \begin{tikzpicture}
\fill[inner color=white, outer color=gray!60,even odd rule] (2-\x*0.16,-2) circle (0.8+\x*0.16 and 1.6) (2-\x*0.16,-2) circle (0.6+\x*0.09 and 1.2-\x*0.02);
\draw (-2.1,-4.6) rectangle (2.9,0.6);
\end{tikzpicture}
}
\end{document}
输出
答案4
只需稍加添加就可以使杯子的边缘更厚并改善照明:
\usetikzlibrary{shadings}
\begin{tikzpicture}
\shade[ball color=gray!10] (-2,0) arc (180:360:2cm);
\shade[left color=gray!30, right color=gray!80] (-2,0) arc (180:540:2cm and 1cm);
\shade[left color=gray!80, right color= gray!10] (-1.8,0) arc (180:540:18mm and 8mm);
\fill[top color=gray!20,bottom color=gray!90] (1.8,-.45) arc (135:225:.35cm) arc (45:-150:.35cm) arc (90:270:.25cm) arc (-90:45:.85cm) -- cycle;
\end{tikzpicture}