4

I would like to add "dots/points" to each grid intersection in the torus below.

\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:2pi, domain y = 0:2pi, ]( {(1+sin(deg(\x)))cos(deg(\y))}, {(1+sin(deg(\x)))sin(deg(\y))}, {cos(deg(\x))} ); \end{axis} \end{tikzpicture} \end{document}

I tried to add something like this to my code above:

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

but this causes my code to freeze. What should I do?

Black Mild
  • 17,569
aprendiz
  • 143
  • 1
    Welcome! Can you complete your code so people can compile it as-is? An image of your current output might also be helpful. – cfr Sep 21 '23 at 00:03
  • (I am curious) in which context the dots at grid intersections make sense? for decorating only? – Black Mild Sep 21 '23 at 14:53
  • 1
    @BlackMild It makes sense in the context of a toric code: at some of the vertices, I may want to put a vertex type operator (like a cross). I asked about the dots just to make my question clearer. – aprendiz Sep 21 '23 at 15:14

2 Answers2

5
\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}

Torus with lines and marks

  • Thanks a lot, it was already very helpful. I do need only the front points, so far was not able to. – aprendiz Sep 21 '23 at 00:36
  • Markers and surfaces do not share the same depth information. They are drawn on top of each other. -a scatter plot does not have a z-buffer. The only way to do what you want in PGFPlots, is to make several \addplot3 or \draw in e.g. a \foreach (or \pgfplotsinvokeforeach) with manual adjusted domain to fit with the view . You can also describe what is in view with a function and use z filter/.expression. Start e.g. with z filter/.expression={y+x<cos(deg(\x)) ? nan : z} – hpekristiansen Sep 21 '23 at 02:16
4

Is this what you want? I use Asymptote that is maths-oriented.

The code is adapted from one in Asymptote gallery. We can put dots or any decoration at grid intersections. The parameters m and n are the numbers for horizontal and vertical mesh-lines. Feel free to change them, also R and a as you wish.

The code can be run standalone online at asymptote.ualberta.ca or imbbed in a LaTeX document https://www.overleaf.com/read/pffryywkwxqy

enter image description here

// 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+acos(t.y))cos(t.x), (R+acos(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((i2pi/m,j2pi/n)),red);

PS: with opacity option, then we can see the hidden part

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

enter image description here

Black Mild
  • 17,569