# Plot on the surface of a Torus I'm trying to plot a system with a variable (or field) $$\theta(x,t)\in[-\pi,\pi]$$ which is an angle at every position $$x$$. The positional argument $$x$$ itself is a periodic coordinate $$x\in[-\pi,\pi]$$. I'm trying to show some topological properties of this field, and I felt that a natural way to do so would be to plot the curve $$\theta$$ versus $$x$$ for $$\theta = \theta(x)$$ at a fixed time $$t$$ on the surface of a torus ($$S^1\times S^1$$). This would clearly represent the periodic nature of $$\theta$$ and $$x$$. Is there a neat way to do this on Mathematica?

For example, my idea was to use the blue coordinate (refer image) as the position variable $$x$$ and the red coordinate at each $$x$$ to represent $$\theta(x)$$. In this way both $$x$$ and $$\theta$$ are periodic.

Edit: $$t$$ is time. I just put it there for completeness. I need to plot the variable at different time slices.

• Maybe the word 'field' is a bit misleading. I just need to plot a function which has a periodic domain and range. For example, if I have a function \theta(x)=x, and x and theta are periodic. I wanted to use the toroidal angle for the variable x and the poloidal angle for theta. Dec 7 '18 at 4:32
• (1) What's t in first line? How is that suppose to enter into the plot? (2) My take on your comment: You wish to plot a curve on the surface of $S^1 \times S^1$ that represents a function $S^1 \rightarrow S^1$ given by $\theta = f(x)$? Dec 7 '18 at 11:42
• Example from your comment, $\theta = x$: With[{f = Function[x, x]}, ParametricPlot3D[{(2 + Cos[\[Theta]]) Cos[ x], (2 + Cos[\[Theta]]) Sin[x], Sin[\[Theta]]}, {x, -Pi, Pi}, {\[Theta], -Pi, Pi}, MeshFunctions -> {Function[{x0, y0, z0, x, \[Theta]}, \[Theta] - f[x]], #4 &, #5 &}, Mesh -> {{0}}, MeshStyle -> {Directive[Thick, ColorData], Thin, Thin}, BoundaryStyle -> None]] -- the thick, bluish line represents the graph, the thin lines are the $\theta,x$ axes. Is that what you're after? Dec 7 '18 at 11:43
• Thank you! This seems to be what I was looking for. However, when I tried slightly more general functions, the plot seems to be incomplete. For example \theta=2x seems to cutoff at some point, when it should wind around the torus twice. Dec 7 '18 at 17:31
• Thanks for the accept. I edited the question to try to clarify that the graph (curve) of $\theta(x)$ is what it being plotted on the torus. I do think the word "field" is misleading. To me it means a function that is defined at every point on the torus, either a scalar field or a (tangent) vector field. I left it in the question, but you might want to rephrase it. If I've messed up, feel free to roll back the edit. Dec 8 '18 at 11:44

Ignoring $$t$$, which might seem irrelevant after some of the comments, one can plot $$\theta = \theta(x)$$ for $$(x,\theta)\in S^1\times S^1$$ with ParametricPlot3D. One issue is that some aspects of plotting functions do not automatically deal very well with discontinuities, such as MeshFunctions. To make x periodic over $$[\pi, \pi]$$, one might use Mod[#, 2 Pi, -Pi] &, but it creates discontinuities that cause spurious mesh lines along the discontinuities. Instead, consider the homeomorphism $$S^1 \cong{\Bbb R}/(2\pi{\Bbb Z})$$. If $$x,\theta \in S^1$$, then we can use the subgroup $$2\pi{\Bbb Z}$$ for the Mesh specification. However, a Mesh specification must be finite, so we need to know the bounds on $$f(x)$$ or otherwise specify a sufficiently broad range for Mesh.

With[{f = Function[x, 2 x]},
ParametricPlot3D[{(2 + Cos[θ]) Cos[x], (2 + Cos[θ]) Sin[x], Sin[θ]},
{x, -Pi, Pi}, {θ, -Pi, Pi},
MeshFunctions -> {Function[{x0, y0, z0, x, θ}, θ - f[x]], #4 &, #5 &},
Mesh -> {2 Pi*Range[-10, 10], {0}, {0}},
MeshStyle -> {Directive[Thick, ColorData], Thin, Thin},
BoundaryStyle -> None]] What you probably need is: https://reference.wolfram.com/language/ref/SliceDensityPlot3D.html

and the equation(s) of a Torus is(are) given by: http://mathworld.wolfram.com/Torus.html

Assuming that you want to work with (u as x) and (v as t), I guess you should try something like this:

\[Theta][u_, v_] := u + v;

c = 1; a = 4;
x = (c + a*Cos[v]) Cos[u];
y = (c + a*Cos[v]) Sin[u];
z = a*Sin[v];

SliceDensityPlot3D[\[Theta][u,
v], {(c - Sqrt[x^2 + y^2])^2 + z^2 == a^2}, {u, 0, 2 \[Pi]}, {v, 0,
2 \[Pi]}]

• This seems unlikely to be a convenient approach, since SliceDensityPlot[] plots in rectangular (x,y,z) coordinates and the field is given in circular/angular coordinates. Not sure why it was upvoted. Besides which the OP indicates three parameters $\theta,x,t$ to be plotted on a 2D surface generated by $\theta$ and $x$, the role of $t$ being unspecified. It's unclear what's being asked, so it's unclear how this is an answer. Again, not sure why it was upvoted. Dec 7 '18 at 3:42
• I agree with you about the issue with 't' whose role is not being clearly specified by the OP but I disagree with you about the coordinates: Transforming angular coordinates into rectangular is not a problem at all (the second link I posted gives you an example). Dec 7 '18 at 15:06
• I'm interpreting OP's question as follows: He wants to use the (Azimuthal angle to represent x) and (The other angle to represent t), hence, he'll be able to plot theta(x,t) on a Torus using SliceDensityPlot[]. Dec 7 '18 at 15:09
• Well, that was close my original interpretation, too, although I thought the OP made it clear that the coordinates of the torus were to be $x$ and $\theta$, not $t$.; however, it didn't seem like the OP thought the code I posted solved the problem. -- As for convenience, one would have to get angular coordinates in terms of rectangular coordinates, which is not explained in the MathWorld page or in the answer. By inconvenient, I didn't mean unsolvable, though. Dec 7 '18 at 15:31
• Okay, I just wrote the above, when you posted the new code. What does your output look like? I get this: i.stack.imgur.com/UE9ei.png -- Is there a typo in the posted code? Dec 7 '18 at 15:32