如何为球坐标绘制 3D 球体和 3D 圆锥体

如何为球坐标绘制 3D 球体和 3D 圆锥体

我正在尝试复制这个数字:

在此处输入图片描述

现在,我有这个代码:

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[yzx, scale = 0.9]
        \draw[->] (0,0,0) -- (5.5,0,0) node(x)[left]{$x$};
        \draw[->] (0,0,0) -- (0,5,0) node(y)[right]{$y$};
        \draw[->] (0,0,0) -- (0,0,4) node(z)[right]{$z$};

        \def\px{4}; \def\py{4}; \def\pz{4};
        \coordinate (o) at (0,0,0);
        \coordinate (p) at (\px,\py,\pz);
        \coordinate (pxy) at (\px,\py,0);


        % Spherical coordinates
        \begin{scope}[canvas is xy plane at z=0]
            \draw[->, cadmiumorange] (2,0) arc(0:45:2) node[pos = 0.5, below]{$\phi$};

            \draw[dotted, cadmiumorange] (o) -- (pxy);
        \end{scope}

        \draw[cadmiumorange] (o) -- (p) node[above left, pos = 0.5]{$r$};

        \draw[dotted] (pxy) -- (p) node[pos = 0.5, right]{$z$};

        \begin{scope}[canvas is zy plane at x=0]
            \draw[->, cadmiumorange] (1,0) arc(0:45:1) node[pos = 0.5, above]{$\theta$};
        \end{scope}


        % x-y-z coordinates
        \draw[bleudefrance] (o) -- (\px,0,0) node[above, pos = 0.5, sloped]{$x$};

        \draw[bleudefrance] (\px,0,0) -- (pxy) node[pos = 0.5, below]{$y$};


        % Point
        \filldraw (p) circle(3pt) 
        node[above right]{$P(r, \theta, \phi)$} 
        node[below right]{$P(x,y,z)$};
    \end{tikzpicture}
    \caption{Coordenadas cartesianas y esf\'ericas.}
    \label{c2:definiciones:esfericasB}
\end{figure}

产生

![在此处输入图片描述

这就是我自己能画的全部了。我不知道如何画这个“立体”球体和圆锥体。第一个图中的文字是西班牙语,但答案中不需要它。

这个问题的理想答案是类似于这个问题的答案:如何绘制参考圆柱坐标的立体图形。这个答案(相对)容易理解和修改。

我的代码中也有这个:

\documentclass[11pt, oneside]{book}

\usepackage{pgfplots}
\pgfplotsset{compat = newest} 

\usepackage{tikz-3dplot}
\usepackage{tikz}
    \usetikzlibrary{snakes, calc, quotes, babel, hobby, trees, arrows, patterns, patterns.meta, calligraphy, backgrounds, chains, shapes.geometric, shapes, angles, 3d, fillbetween,
    decorations, decorations.pathreplacing, 
    decorations.pathmorphing, decorations.markings, decorations.text}


    \tikzstyle{yzx} = [
        x={(-.385cm, -.385cm)},
        y={(1cm, 0cm)},
        z={(0cm, 1cm)},
    ]
    \tikzset{zxplane/.style={canvas is zx plane at y=#1,very thin}}
    \tikzset{yxplane/.style={canvas is yx plane at z=#1,very thin}}


    \usepackage{tkz-euclide}
    \tikzset{every picture/.style = {line width = 1pt, > = Triangle},
        %
        %
        %
        set arrow inside/.code = {\pgfqkeys{/tikz/arrow inside}{#1}},
        set arrow inside={end/.initial = >, opt/.initial =},
        /pgf/decoration/Mark/.style = {
            mark/.expanded = at position #1 with {
                \noexpand\arrow[\pgfkeysvalueof{/tikz/arrow inside/opt}]{\pgfkeysvalueof{/tikz/arrow inside/end}}
            }
        },
        arrow inside/.style 2 args = {
            line width = 2pt,
            set arrow inside = {#1},
            postaction = {
                decorate, decoration={
                    markings, Mark/.list = {#2}
                }
            }
        },
    }

\usepackage{physics} 
\usepackage[italic = true]{derivative}
\usepackage[scr = rsfso]{mathalfa}
\usepackage{mathtools}
\usepackage{amssymb}

\definecolor{cadmiumorange}{rgb}{0.93, 0.53, 0.18}

感谢您的阅读并继续帮助!

答案1

canvas is...您可以使用库中的选项绘制类似于图片的内容3d。例如:

\tikzset
{
   xz/.style={canvas is xz plane at y=0},
   xz rotated/.style={rotate around z=\mytheta,xz},
}

这里我定义了两种样式。第一种在 xz 平面上绘制(如果你选择不同的,y则在距离 的平行平面上绘制y)。第二种在另一个平面上绘制,获得围绕 z 轴旋转 xy 平面的\mytheta度数(定义为 60)。

使用这些新平面,您只需要绘制几条直线和几个圆弧,它们都与角度\mytheta和相关\myphi

一个完整的例子(好吧......我为你留下了标签)可能是:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{3d} % for 'canvas is...' options

\tikzset
{% styles
   axis/.style={thick,-latex},
   yz/.style={canvas is yz plane at x=0},
   xz/.style={canvas is xz plane at y=0},
   xz rotated/.style={rotate around z=\mytheta,xz},
   xy elevated/.style={canvas is xy plane at z={\myradius*cos(\myphi)},scale={sin(\myphi)}},
   sphere/.style={shading=ball,fill opacity=0.3},
   plane/.style={fill=teal,fill opacity=0.3},
   cone/.style={fill=yellow,fill opacity=0.3},
   vector/.style={very thick,-stealth},
   point/.style={shading=ball,ball color=red}
}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,
                    x={(-0.4cm,-0.4cm)}, y={(1cm,0)},z={(0,1cm)}]
% dimensions
\def\myradius{5}
\def\mytheta{60}
\def\myphi{30}
% axes
\draw[axis] (0,0,0) -- (1.3*\myradius,0,0) node[below] {$x$};
\draw[axis] (0,0,0) -- (0,1.3*\myradius,0) node[right] {$y$};
\draw[axis] (0,0,0) -- (0,0,1.3*\myradius) node[above] {$z$};
% sphere
\draw[sphere] (0,\myradius,0) {[yz] arc (0:90:\myradius)} {[xz rotated] arc (90:0:\myradius)} arc (\mytheta:90:\myradius);
% plane
\draw[plane,xz rotated] (0,\myradius) arc (90:0:\myradius) -| cycle;
% cone
\draw[cone] {[xy elevated] (\myradius,0) arc (0:\mytheta:\myradius) coordinate (P)} -- (0,0,0) -- cycle;
% other arcs
\draw (\mytheta:\myradius) arc (\mytheta:0:\myradius) {[xz] arc (0:90:\myradius)};
\draw[-latex] (1,0,0) arc (0:\mytheta:1) node[midway,below] {$\theta$};
\draw[xz rotated,-latex] (0,2) arc (90:90-\myphi:2) node[midway,above] {$\varphi$};
% vectors
\draw[xz rotated ,vector] (P) --++ (90-\myphi:1.5) node[above] {$\hat{r}$};
\draw[xz rotated ,vector] (P) --++ (-\myphi:1.5)   node[right] {$\hat{\theta}$};
\draw[xy elevated,vector] (P) --++ (90+\mytheta:3) node[right] {$\hat{\varphi}$};
% point
\fill[point] (P) circle (0.1cm);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容