我有这个球体,带有手动绘制的表面(带弧),非常适合初学者的方法。
我想用颜色填充它,告诉我怎么做,像这样:
我的 MWE:
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\shade[ball color = gray!40, opacity = 0.4] (0,0) circle (2cm);
\draw (0,0) circle (2cm);
\draw (-2,0) arc (180:360:2 and 0.6);
\draw[dashed] (2,0) arc (0:180:2 and 0.6);
\fill[fill=black] (0,0) circle (1pt);
\draw (0.71,1.67) arc (180:225:2.5 and 0.8);
\draw (0,0 ) -- node[above]{$r$} (0.8,1.83);
\draw (0,0 ) -- node[above]{$r$} (1.6,1.2);
\draw (0,0 ) -- node[above]{$r$} (2,0);
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}[use Hobby shortcut]
\draw[dashed] (2,0) arc[start angle=0, end angle=180, radius=2, y radius=0.6];
\shadedraw[ball color=blue!40, fill opacity=0.4] (0,0) circle[radius=2];
\draw (-2,0) arc[start angle=180, end angle=360, radius=2, y radius=0.6];
\fill (0,0) circle[radius=1pt];
\draw (0,0) -- node[above, pos=0.6]{$r$} (2,0);
\draw[dashed] (0,0) -- (40:1.6);
\draw[dashed] (0,0) -- (70:1.6);
\clip[closed] (40:1.6) .. (50:1.45) .. (70:1.6) .. (60:1.85);
\shade[ball color=blue!40, fill opacity=0.3] (0,0) circle[radius=2];
\draw[thick, closed] (40:1.6) .. (50:1.45) .. (70:1.6) .. (60:1.85);
\node[font=\small] at (55:1.65) {S};
\end{tikzpicture}
\end{document}
答案2
%% Compile and read me!
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\begin{document}
% Gradient Info
\tikzset {_k6mv1ejnm/.code = {\pgfsetadditionalshadetransform{ \pgftransformshift{\pgfpoint{0 bp } { 0 bp } } \pgftransformrotate{0 } \pgftransformscale{2 } }}}
\pgfdeclarehorizontalshading{_z1ak5ajdj}{150bp}{rgb(0bp)=(0.71,0.96,0.96);
rgb(37.5bp)=(0.71,0.96,0.96);
rgb(62.5bp)=(0.66,0.92,0.99);
rgb(100bp)=(0.66,0.92,0.99)}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,477); %set diagram left start at 0, and has height of 477
%Shape: Circle [id:dp4105016822718395]
\path [shading=_z1ak5ajdj,_k6mv1ejnm] (180,221.9) .. controls (180,153.47) and (235.47,98) .. (303.9,98) .. controls (372.33,98) and (427.8,153.47) .. (427.8,221.9) .. controls (427.8,290.33) and (372.33,345.8) .. (303.9,345.8) .. controls (235.47,345.8) and (180,290.33) .. (180,221.9) -- cycle ; % for fading
\draw [color={rgb, 255:red, 251; green, 253; blue, 254 } ,draw opacity=1 ][line width=1.5] (180,221.9) .. controls (180,153.47) and (235.47,98) .. (303.9,98) .. controls (372.33,98) and (427.8,153.47) .. (427.8,221.9) .. controls (427.8,290.33) and (372.33,345.8) .. (303.9,345.8) .. controls (235.47,345.8) and (180,290.33) .. (180,221.9) -- cycle ; % for border
%Straight Lines [id:da24551258669086784]
\draw [color={rgb, 255:red, 149; green, 208; blue, 225 } ,draw opacity=1 ][line width=1.5] (303.9,221.9) -- (427.08,220.01) ;
%Straight Lines [id:da8242464718458027]
\draw [color={rgb, 255:red, 149; green, 208; blue, 225 } ,draw opacity=1 ][line width=1.5] (303.9,221.9) -- (355.8,161) ;
%Straight Lines [id:da009573593426575266]
\draw [color={rgb, 255:red, 149; green, 208; blue, 225 } ,draw opacity=1 ][line width=1.5] (320.8,121) -- (299.4,221.9) ;
%Shape: Arc [id:dp14552988688203028]
\draw [draw opacity=0][line width=1.5] (180,222.01) .. controls (180.41,231.62) and (235.57,239.4) .. (303.54,239.4) .. controls (366.61,239.4) and (418.63,232.71) .. (426.15,224.06) -- (303.54,221.9) -- cycle ; \draw [color={rgb, 255:red, 152; green, 202; blue, 217 } ,draw opacity=1 ][line width=1.5] (180,222.01) .. controls (180.41,231.62) and (235.57,239.4) .. (303.54,239.4) .. controls (366.61,239.4) and (418.63,232.71) .. (426.15,224.06) ;
%Shape: Arc [id:dp5555036816617602]
\draw [draw opacity=0][dash pattern={on 5.63pt off 4.5pt}][line width=1.5] (427.08,220.01) .. controls (420.4,211.23) and (367.8,204.4) .. (303.9,204.4) .. controls (235.73,204.4) and (180.41,212.18) .. (180,221.79) -- (303.9,221.9) -- cycle ; \draw [color={rgb, 255:red, 152; green, 202; blue, 217 } ,draw opacity=1 ][dash pattern={on 5.63pt off 4.5pt}][line width=1.5] (427.08,220.01) .. controls (420.4,211.23) and (367.8,204.4) .. (303.9,204.4) .. controls (235.73,204.4) and (180.41,212.18) .. (180,221.79) ;
%Shape: Polygon Curved [id:ds004137480371948721]
\draw [color={rgb, 255:red, 149; green, 208; blue, 225 } ,draw opacity=1 ][fill={rgb, 255:red, 226; green, 244; blue, 253 } ,fill opacity=1 ][line width=1.5] (355.8,161) .. controls (359.8,141) and (372.8,128) .. (333.8,118) .. controls (294.8,108) and (351.8,181) .. (355.8,161) -- cycle ;
%Shape: Circle [id:dp2446912683584801]
\draw [color={rgb, 255:red, 7; green, 173; blue, 237 } ,draw opacity=1 ][fill={rgb, 255:red, 7; green, 173; blue, 237 } ,fill opacity=1 ] (297.4,221.9) .. controls (297.4,219.41) and (299.41,217.4) .. (301.9,217.4) .. controls (304.39,217.4) and (306.4,219.41) .. (306.4,221.9) .. controls (306.4,224.39) and (304.39,226.4) .. (301.9,226.4) .. controls (299.41,226.4) and (297.4,224.39) .. (297.4,221.9) -- cycle ;
% Text Node
\draw (291,169.4) node [anchor=north west][inner sep=0.75pt] {$r$};
% Text Node
\draw (343,174.4) node [anchor=north west][inner sep=0.75pt] {$r$};
% Text Node
\draw (343,225) node [anchor=north west][inner sep=0.75pt] {$r$};
% Text Node
\draw (339,128.4) node [anchor=north west][inner sep=0.75pt] {$S$};
\end{tikzpicture}
\end{document}