我刚开始使用 TikZ 中的 3d 库,想获得一些建议。我想在 TikZ 中创建一个球体,该球体由 xy 平面上的一个圆(z 从屏幕指向外)和一个 180 度虚线圆弧(“在”xy 圆后面)+ 一个绘制的 180 度圆弧(“在”xy 圆前面)构成。
我觉得我可能没有以正确的方式解决这个问题,所以如果您有任何建议,请告诉我!
\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{3d,calc,positioning}
\begin{document}
\begin{tikzpicture}%[z={(90:10mm)},x={(190:10mm)},y ={(-45:10mm)}]
\coordinate (O) at (0,0,0);
\coordinate (A) at (1,0,0);
\coordinate (B) at (0,1,0);
\coordinate (C) at (0,0,1);
%\draw (O) -- (A) node {$x$};
%\draw (O) -- (B) node {$y$};
%\draw (O) -- (C) node {$z$};
\begin{scope}[canvas is xy plane at z=0]
\draw (A) arc[start angle=0, end angle = 360, radius=1] -- cycle;
\end{scope}
\begin{scope}[canvas is xz plane at y=0]
\draw[dashed] (-1, 0, 0) arc[start angle=180, end angle = 360, radius=1];
\draw[] (1, 0, 0) arc[start angle=0, end angle = 180, radius=1];
\end{scope}
\end{tikzpicture}
\end{document}
我希望它看起来就像你手工绘制的一个球体一样。
更新:尝试使用硬编码来解决问题,但我认为这是一个非常丑陋的解决方案。
\documentclass[border=10mm]{standalone}
\usepackage[UseComma, OpenSans]{MagmaGeometry}
\usepackage{marvosym}
\usetikzlibrary{3d,calc,positioning}
\begin{document}
\begin{tikzpicture}%[z={(90:10mm)},x={(190:10mm)},y ={(-45:10mm)}]
\coordinate (O) at (0,0,0);
\coordinate (A) at (1,0,0);
\coordinate (B) at (0,1,0);
\coordinate (C) at (0,0,1);
%\draw (O) -- (A) node {$x$};
%\draw (O) -- (B) node {$y$};
%\draw (O) -- (C) node {$z$};
\begin{scope}[canvas is xy plane at z=0]
\draw (A) arc[start angle=0, end angle = 360, radius=1] -- cycle;
\end{scope}
\begin{scope}[canvas is xz plane at y=0]
\draw[dashed] (-1, 0, 0) arc[start angle=200, end angle = 310, radius=1.1];
\draw[] (1, 0, 0) arc[start angle=35, end angle = 147, radius=1.215];
\end{scope}
\end{tikzpicture}
\end{document}
[1]: https://i.stack.imgur.com/ykHGG.png
答案1
也许像这样?你可以使用3d工具。
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=110,theta=70},line cap=butt,
line join=round,declare function={R=2.5;},c/.style={circle,fill,inner sep=1pt}]
\path
(0,0,0) coordinate (O)
(0,0,R) coordinate (N)
(0,0,-R) coordinate (S);
\draw[3d/screen coords] (O) circle[radius=R];
\path pic{3d/circle on sphere={R=R,C={(O)}}};
\path pic{3d/circle on sphere={R=R,C={(O)},P={(O)}, n={(0,1,0)}}};
\draw[3d/hidden] (S) -- (N);
\path foreach \p/\g in {O/-30,S/0,N/-30}
{(\p)node[c]{}+(\g:2.5mm) node{$\p$}};
\end{tikzpicture}
\end{document}