将网格点添加到圆环

将网格点添加到圆环

我想在下面的圆环中的每个网格交叉点添加“点/点”。

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
\pgfplotsset{
    compat=newest
}

\begin{document}   
\begin{tikzpicture}
    \begin{axis}[view={120}{30},
        axis equal image,
        hide axis,
        z buffer = sort,
        scale = 1.5
    ]
    \addplot3[
            surf,
            samples = 20,
            samples y = 40,
            domain = 0:2*pi,
            domain y = 0:2*pi,
        ](
            {(1+sin(deg(\x)))*cos(deg(\y))},
            {(1+sin(deg(\x)))*sin(deg(\y))},
            {cos(deg(\x))}
        );
    \end{axis}
\end{tikzpicture}
\end{document}

我尝试在上面的代码中添加类似这样的内容:

\addplot3 coordinates (
        {(1+sin(deg(\x)))*cos(deg(\y))},
        {(1+sin(deg(\x)))*sin(deg(\y))},
        {cos(deg(\x))}
    );

但这导致我的代码冻结。我该怎么办?

答案1

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={120}{30},
axis equal image,
hide axis,
z buffer=sort,
]
\addplot3[
surf, mark=*, mark size=0.2,
samples=20,
samples y=40,
domain=0:2*pi,
domain y=0:2*pi,
](
{(1+sin(deg(\x)))*cos(deg(\y))},
{(1+sin(deg(\x)))*sin(deg(\y))},
{cos(deg(\x))}
);
\end{axis}
\end{tikzpicture}
\end{document}

带有线条和标记的圆环

答案2

这是你想要的吗?我使用面向数学的 Asymptote。

代码改编自渐近线画廊。我们可以在网格交叉点处放置点或任何装饰。参数mn是水平和垂直网格线的数字。您也可以随意更改它们,R只要a您愿意。

该代码可以在线独立运行渐近线.ualberta.ca或嵌入到 LaTeX 文档中https://www.overleaf.com/read/pffryywkwxqy

在此处输入图片描述

// Run on http://asymptote.ualberta.ca/
// This code is adapted from 
// https://asymptote.sourceforge.io/gallery/3Dwebgl/parametricsurface.asy

import graph3;
size(200,0);
currentprojection=orthographic(4,0,2,zoom=.8);

real R=2;
real a=.8;

triple f(pair t) {return (
  (R+a*cos(t.y))*cos(t.x),
  (R+a*cos(t.y))*sin(t.x),
  a*sin(t.y)
);}

pen p=black+1pt;
int m=20;  // x-mesh
int n=12;   // y-mesh
surface s=surface(f,(0,0),(2pi,2pi),m,n,Spline);

// surface & mesh
draw(s,yellow,meshpen=p);

for (int i=0; i<m; ++i)
for (int j=0; j<n; ++j)
dot(f((i*2pi/m,j*2pi/n)),red);

PS:使用不透明度选项,我们可以看到隐藏的部分

draw(s,yellow+opacity(.5),meshpen=p);

在此处输入图片描述

相关内容