TikZ 中的球体 3D 图片

TikZ 中的球体 3D 图片

我想用(普通的)TikZ:
在此处输入图片描述
我该如何绘制“垂直弧”?

梅威瑟:

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}

\begin{tikzpicture}[
background grid/.style={help lines, draw, step=5mm},
gridded,
every path/.style={very thin},
]
\coordinate[label=](M) at (0,0);

\def\Radius{2}
%\shade[ball color = white] (M) circle[radius=\Radius];
\draw (M) circle[radius=\Radius];

\def\R{2}  

\foreach \v in {-6,...,6}{%% 
\pgfmathsetmacro\h{\v*\R/6}
\pgfmathsetmacro\Radius{sqrt(\R^2-abs(\h)^2)}
% Horicontals ================
% front
\def\StartAng{0}
\def\EndAng{-180}
\draw[] ([shift={(\StartAng:\Radius)}]0,\h) arc[start angle=\StartAng, end angle=\EndAng, x radius=\Radius, y radius=0.25*\Radius];
% back
\def\StartAng{0}
\def\EndAng{180}
\draw[help lines] ([shift={(\StartAng:\Radius)}]0,\h) arc[start angle=\StartAng, end angle=\EndAng, x radius=\Radius, y radius=0.25*\Radius];

% Verticals ================
% front
\def\StartAng{0}
\def\EndAng{-180}
\draw[blue] ([shift={(\StartAng:\Radius)}]\h,0) arc[start angle=\StartAng, end angle=\EndAng, y radius=\Radius, x radius=0.25*\Radius];
% back
%\def\StartAng{0}
%\def\EndAng{180}
%\draw[blue,densely dashed] ([shift={(\StartAng:\Radius)}]\h,0) arc[start angle=\StartAng, end angle=\EndAng, y radius=\Radius, x radius=0.25*\Radius];
}%%


%\fill[fill=black] (M) circle (1pt);
%\draw[dashed] (M) -- node[above]{$r$} (\Radius,0);
\end{tikzpicture}
\end{document}

答案1

您可以使用tikz-3dplot-圆球

\documentclass{standalone}
\usepackage{tikz-3dplot-circleofsphere}
\begin{document}
\centering
\def\r{3}
\tdplotsetmaincoords{60}{125}
\begin{tikzpicture}[tdplot_main_coords]
 \draw[tdplot_screen_coords,thin,black!30] (0,0,0) circle (\r);
 \foreach \a in {-75,-60,...,75}
 {\tdplotCsDrawLatCircle[thin,black!30]{\r}{\a}}
 \foreach \a in {0,15,...,165}
 {\tdplotCsDrawLonCircle[thin,black!30]{\r}{\a}}
  \tdplotCsDrawGreatCircle%
[red,thick,tdplotCsFill/.style={opacity=0.1}]{\r}{105}{-23.5}
 \end{tikzpicture}
 \end{document}

在此处输入图片描述

或者3d工具

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\pgfdeclarelayer{background} 
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}    
    \begin{tikzpicture}[3d/install view={phi=110,theta=70},scale=1,line cap=butt,
        line join=round,visible/.style={draw,solid},
        hidden/.style={draw,very thin,cheating dash},declare function={R=3;}] 
        \path (0,0,0) coordinate (I)
        foreach \Z in {-75,-60,...,75}
        {(0,0,{R*sin(\Z)}) coordinate (I\Z)}
        foreach \Z in {-75,-60,...,90}
        {({cos(\Z)},{sin(\Z)},0) coordinate (n\Z)};
        \shade[ball color=white,3d/screen coords,opacity=0.8] (I) circle[radius=R];
        %
        \path foreach \Z in {-75,-60,...,90}
        {pic{3d/circle on sphere={R=R,C={(I)},P={(I)},n={(n\Z)},
                    fore layer=foreground,back layer=background}}};
        %  
        \path foreach \Z in {-75,-60,...,75}
        {pic{3d/circle on sphere={R=R,C={(I)}, P={(I\Z)},
                    fore layer=foreground,back layer=background}}};
    \end{tikzpicture}
\end{document}  

在此处输入图片描述

答案2

您可以使用该blochsphere包:

\documentclass{article}

\usepackage{blochsphere}

\begin{document}
\begin{blochsphere}[radius=2cm,opacity=50]
    \drawBallGrid[]{10}{10}
\end{blochsphere}
\end{document}

在此处输入图片描述

相关内容