如何使用 3dplot 绘制球形

如何使用 3dplot 绘制球形

我想使用 3dplot 包绘制一些球面。有人知道如何在这样的坐标系中绘制具有不同直径和位置的球面吗?

\documentclass[a4paper, 12pt,]{scrartcl}

\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english,ngerman]{babel}

\usepackage{graphicx}
\usepackage{epstopdf}

\usepackage{tikz, tikz-3dplot}

\begin{document}

  \tdplotsetmaincoords{60}{130}

  \begin{tikzpicture}[scale=4,tdplot_main_coords]

    \coordinate  (O)  at  (0,0,0);

    \draw[thick,->]  (0,0,0)  --  (1,0,0)  node[anchor=north  east]{$x$};
    \draw[thick,->]  (0,0,0)  --  (0,1,0)  node[anchor=north  west]{$y$};
    \draw[thick,->]  (0,0,0)  --  (0,0,1)  node[anchor=south]{$z$};

  \end{tikzpicture}

\end{document}

编辑:

这是我写的更多代码。我想在每个角上放一个球体来画一个晶格。

\documentclass[a4paper, 12pt,]{scrartcl}

\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english,ngerman]{babel}

\usepackage{graphicx}
\usepackage{epstopdf}

\usepackage{tikz, tikz-3dplot}

\begin{document}

  \tdplotsetmaincoords{60}{130}

  \begin{tikzpicture}[scale=4,tdplot_main_coords]

    \coordinate  (O)  at  (0,0,0);

    \draw[thick,->]  (0,0,0)  --  (1,0,0)  node[anchor=north  east]{$x$};
    \draw[thick,->]  (0,0,0)  --  (0,1,0)  node[anchor=north  west]{$y$};
    \draw[thick,->]  (0,0,0)  --  (0,0,1)  node[anchor=south]{$z$};

    \tdplotsetcoord{P1}{.8}{30}{90}
    \tdplotsetcoord{P2}{.8}{30}{30}
    \tdplotsetcoord{P3}{.8}{30}{330}
    \tdplotsetcoord{P4}{.8}{30}{270}
    \tdplotsetcoord{P5}{.8}{30}{210}
    \tdplotsetcoord{P6}{.8}{30}{150}

    \draw[color=blue] (P1)--(P2)--(P3)--(P4)--(P5)--(P6)--cycle;
    \draw[color=blue] (P1xy)--(P2xy)--(P3xy)--(P4xy)--(P5xy)--(P6xy)--cycle;
    \draw[color=blue] (P1xy)--(P1);
    \draw[color=blue] (P2xy)--(P2);
    \draw[color=blue] (P3xy)--(P3);
    \draw[color=blue] (P4xy)--(P4);
    \draw[color=blue] (P5xy)--(P5);
    \draw[color=blue] (P6xy)--(P6);

  \end{tikzpicture}

\end{document}

答案1

一种方法是使用\pgfdeclareradialshading{sphere}

\pgfdeclareradialshading{sphere}{\pgfpoint{0.5cm}{0.5cm}}
{   
    rgb(0cm)=(1,1,1);
    rgb(0.7cm)=(0.8,0.8,0.8); 
    rgb(1cm)=(0.6,0.6,0.6); 
    rgb(1.05cm)=(0.6,0.6,0.6)
 }
\pgfuseshading{sphere}

可以创建如下内容:

在此处输入图片描述

要了解更多信息,请查看pgf 手册83.2.2.

另一种方法是创建第二个tikzpicture并使用一些 2d 阴影:

\begin{tikzpicture}
    \begin{scope}
        \fill[black] (0,0) circle (0.5);
        \clip (0,0) circle (0.5);
        \shade[outer color=black, inner color=black!30] (-0.15,0.5) circle (0.7);
    \end{scope}
\end{tikzpicture}

像这样:

在此处输入图片描述

致谢第二个建议。有用关联。

答案2

问题的解决方案是命令\pgfpointcylindrical{<degree>}{<radius>}{<height>}。也许这不是最简单的方法,但它确实有效。

\tdplotsetmaincoords{60}{130}

\begin{tikzpicture}[scale=4,tdplot_main_coords, curve/.style={red,densely dotted,thick}]

\coordinate  (O)  at  (0,0,0);

\draw[thick,->]  (0,0,0)  --  (1,0,0)  node[anchor=north  east]{$x$};
\draw[thick,->]  (0,0,0)  --  (0,1,0)  node[anchor=north  west]{$y$};
\draw[thick,->]  (0,0,0)  --  (0,0,1)  node[anchor=south]{$z$};

\tdplotsetcoord{P1}{.8}{30}{90}
\tdplotsetcoord{P2}{.8}{30}{30}
\tdplotsetcoord{P3}{.8}{30}{330}
\tdplotsetcoord{P4}{.8}{30}{270}
\tdplotsetcoord{P5}{.8}{30}{210}
\tdplotsetcoord{P6}{.8}{30}{150}

\draw[color=blue] (P1)--(P2)--(P3)--(P4)--(P5)--(P6)--cycle;
\draw[color=blue] (P1xy)--(P2xy)--(P3xy)--(P4xy)--(P5xy)--(P6xy)--cycle;
\draw[color=blue] (P1xy)--(P1);
\draw[color=blue] (P2xy)--(P2);
\draw[color=blue] (P3xy)--(P3);
\draw[color=blue] (P4xy)--(P4);
\draw[color=blue] (P5xy)--(P5);
\draw[color=blue] (P6xy)--(P6);

\pgfpathcircle{\pgfpointcylindrical{30}{0.4}{.7}}{1pt}
\pgfpathcircle{\pgfpointcylindrical{90}{0.4}{.7}}{1pt}
\pgfpathcircle{\pgfpointcylindrical{150}{0.4}{.7}}{1pt}
\pgfpathcircle{\pgfpointcylindrical{210}{0.4}{.7}}{1pt}
\pgfpathcircle{\pgfpointcylindrical{270}{0.4}{.7}}{1pt}
\pgfpathcircle{\pgfpointcylindrical{330}{0.4}{.7}}{1pt}

\pgfpathcircle{\pgfpointcylindrical{30}{0.4}{0}}{1pt}
\pgfpathcircle{\pgfpointcylindrical{90}{0.4}{0}}{1pt}
\pgfpathcircle{\pgfpointcylindrical{150}{0.4}{0}}{1pt}
\pgfpathcircle{\pgfpointcylindrical{210}{0.4}{0}}{1pt}
\pgfpathcircle{\pgfpointcylindrical{270}{0.4}{0}}{1pt}
\pgfpathcircle{\pgfpointcylindrical{330}{0.4}{0}}{1pt}

\pgfsetfillcolor{red}
\pgfusepath{fill}

\end{tikzpicture}

在此处输入图片描述

相关内容