我希望有人能帮助我。我想用乳胶制作这样的图片。我搜索到的所有地方都有例子,但我觉得它们太复杂了。
我可以画一个圆,但 LaTeX 无法将其识别为 3D 对象。所以我无法获得正确的半径。我会给你我的 MWE,但它非常小,我希望它这次不会给你带来太多困扰。
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{quotes,angles,shapes,arrows}
\pgfplotsset{compat=1.11}
\tikzset{>=latex}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={35}{15},
unit vector ratio=1 1 1,
ticks = none,
ymin=-2.8,
ymax=0,
xmax=2.8,
xmin=0,
zmin=0,
zmax=2,
axis lines=middle,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
every axis x label/.style={at={(ticklabel* cs:1)},anchor=west,},
every axis y label/.style={at={(ticklabel* cs:0)},anchor=north east,},
every axis z label/.style={at={(ticklabel* cs:1)},anchor=south,},
x axis line style=-,
y axis line style=-,
z axis line style=-,
clip=false
]
\draw[->](0,0)--(-2,2) node[midway, fill=white]{$r$};
\shade[ball color = blue, opacity = 0.2] (0,0,0) circle [radius=2];
\draw (0,0,0) circle [radius=2];
\filldraw(0,0) circle (1pt) node[align=right,above,xshift=0.8em] {$G$};
\end{axis}
\end{tikzpicture}
\end{document}
先感谢您,
基斯
答案1
欢迎使用 TeX-SE!它之所以不能按预期工作,是因为您在平面上绘制了圆xy
,因此它被投影了。当然,您可以使用pgfplots
来绘制球体。事实上,如果您这样做,您可以访问这些强大的工具。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={35}{15},
unit vector ratio=1 1 1,
ticks = none,
ymin=-2.8,
ymax=0,
xmax=2.8,
xmin=0,
zmin=0,
zmax=2,
axis lines=middle,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
every axis x label/.style={at={(ticklabel* cs:1)},anchor=west,},
every axis y label/.style={at={(ticklabel* cs:0)},anchor=north east,},
every axis z label/.style={at={(ticklabel* cs:1)},anchor=south,},
x axis line style=-,
y axis line style=-,
z axis line style=-,
clip=false
]
\draw[->](0,0)--(-2,2) node[midway, fill=white]{$r$};
\addplot3[surf,shader=interp,domain=0:360,y domain=-90:90,opacity=0.5,
colormap={bluewhite}{color=(blue) color=(blue!30)},
point meta=z+0.8*x+0.3*y] ({2*cos(y)*cos(x)},
{2*cos(y)*sin(x)},{2*sin(y)});
\addplot3[samples y=0,domain=0:360,smooth]({2*cos(x)}, {2*sin(x)},0);
\filldraw(0,0) circle (1pt) node[align=right,above,xshift=0.8em] {$G$};
\end{axis}
\end{tikzpicture}
\end{document}
但是,如果您想制作类似于屏幕截图的东西,您可能希望改用tikz-3dplot
。这允许您在屏幕坐标中绘制一个圆圈。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{105}{-30}
\begin{tikzpicture}[tdplot_main_coords,thick]
\path (0,0,0) coordinate (O);
\pgfmathsetmacro{\Radius}{2}
\draw[gray] (O) -- (\Radius,0,0) coordinate(X);
\draw[gray] (O) -- (0,\Radius,0) coordinate(Y);
\draw[gray] (O) -- (0,0,\Radius) coordinate(Z);
\draw[tdplot_screen_coords,-stealth] (O) -- (45:\Radius) node[midway,fill=white]{$r$};
\shade[ball color=blue,tdplot_screen_coords,opacity=0.4] (O) circle[radius=\Radius];
\foreach \X/\Y in {xy/z,yz/x,zx/y}
{\begin{scope}[canvas is \X\space plane at \Y=\Radius]
\fill circle[radius=2pt];
\end{scope}}
\draw[-stealth] (X) -- (1.5*\Radius,0,0) node[pos=1.2] {$y$};
\draw[-stealth] (Y) -- (0,2*\Radius,0) node[pos=1.2] {$x$};
\draw[-stealth] (Z) -- (0,0,1.5*\Radius) node[pos=1.1] {$z$};
\draw[thin] (xyz spherical cs:radius=\Radius,latitude=45,longitude=-20)
to[bend right=20] node[pos=1.1,left]{$V=\frac{4}{3}\pi r^3$} (xyz spherical
cs:radius=1.5*\Radius,latitude=45,longitude=-20);
\end{tikzpicture}
\end{document}