# Plotting a complicated 3D wave on the surface of a sphere [duplicate]

Suppose you have a vectorial wave described by a complicated function of time and cartesian coordinates $t$, $x$, $y$ $z$ (very simple example below) :

WaveField[t_, x_, y_, z_] := 0.5{1, 0, 0}Sin[2Pi(z - t) + Pi/3] + 0.75{0, 1, 0}Sin[2Pi(x - t) + Pi/2] + 0.25{0, 0, 1}Sin[2Pi(y - t) + 2Pi/3]


How would you represent its "density", defined as

WaveDensity[t_, x_, y_, z_] := WaveField[t, x, y, z].WaveField[t, x, y, z]


on the surface of the unit sphere ? Or maybe on the $x y$ plane ?

My problem is to create a kind of vizualisation of that wave, which is varying in time and space. Drawing a vectorial 3D representation over a cubic space would be extremely messy.

• You mention in your question that you would also be interested in a projection on a plane. That would probably be faster, but you lose yet another degree of freedom. Could you update your question to specify which ranges of e.g. $t$ and one of the spatial variables you would like to explore? – MarcoB Mar 24 '16 at 17:06
• @MarcoB, any range would do. Any plane would do also, since the wave is actually random. Lets say the $x y$ plane, at $t = 0$ (or using Manipulate, like what I've shown in another answer). – Cham Mar 24 '16 at 17:12
• @Cham Sure, added to answer. That is also almost fast enough for a regular Manipulate. See the edit to my answer. – MarcoB Mar 24 '16 at 17:16

It seems to me that your function depends on too many variables to be represented entirely as a 3D contour. Perhaps we can get to what you need by approximation.

To start off, here is perhaps an example of a 3D contour on the surface of the unit sphere for a specific value of $t$ ($t=1$):

SliceContourPlot3D[
WaveDensity[1, x, y, z], x^2 + y^2 + z^2 == 2,
{x, y, z} ∈ Ball[{0, 0, 0}, 3/2],
PlotPoints -> 75
]


An animated version can be created by pre-calculating an array of SliceContourPlot3D objects, then using ListAnimate. I did the calculations using automatic parallelization, since the tasks are entirely independent and parallelize well.

plots = ParallelTable[
SliceContourPlot3D[
WaveDensity[t, x, y, z], x^2 + y^2 + z^2 == 1,
{x, y, z} ∈ Ball[{0, 0, 0}, 11/10],
PlotPoints -> 50
],
{t, 0, 1, 0.1}
];

ListAnimate[plots]


OP also expressed interest in a planar projection. This is much faster of course, so we can set up a Manipulate to explore different time points and $z$-levels:

Manipulate[
ContourPlot[
WaveDensity[t, x, y, z],
{x, -1, 1}, {y, -1, 1},
PlotPoints -> 25
],
{{t, 0}, 0, 1},
{{z, 0}, -2, 2}
]


• As the OP wants to vary time, that could be used as the variable in an animation. – J. M.'s discontentment Mar 24 '16 at 16:25
• @J.M. You read my mind (-: The plot is too slow for Animate, but I am trying to per-calculate some plots to use in a ListAnimate. – MarcoB Mar 24 '16 at 16:27
• @MarcoB, unfortunately, my old version 7 doesn't recognize SliceContourPlot3D , while it knows ContourPlot3D. – Cham Mar 24 '16 at 16:33
• @MarcoB, the plane version is working. A bit slow, though. Is this normal ? I'll try it on my full function. Oh, and colors aren't the same. – Cham Mar 24 '16 at 17:19
• @MarcoB, try this : Manipulate[ ContourPlot[WaveDensity[t, x, y, 0], {x, -1, 1}, {y, -1, 1}, PlotPoints -> 25, ImageSize -> {700, 700}], {{t, 0, "Time"}, 0, 1, 0.01}] It's working nicely, but the colors aren't the same as your output, and it's crude. How to improve the rendering ? – Cham Mar 24 '16 at 17:22

This uses a function that should be available to version 7,

ContourPlot3D[
x^2 + y^2 + z^2 == 4, {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
ColorFunction ->
Function[{x, y, z}, ColorData["Rainbow"][WaveDensity[1, x, y, z]]],
Mesh -> None, ColorFunctionScaling -> False, PlotPoints -> 80
]


In this case the density values lie between 0 and 1 already, so there is no issue, but if they did not, you would need to use ColorData["Rainbow"][Rescale[WaveDensity[1, x, y, z],{min,max}]] where min and max are the range of values you expect the function to take on the sphere.

• It's working, but it's very slow. – Cham Mar 24 '16 at 16:58
• @Cham The plot does rotate, it's probably just awfully slow. It is quite jerky on my laptop. – MarcoB Mar 24 '16 at 16:59
• It's jerky for you ? On which version ? – Cham Mar 24 '16 at 17:00
• Ok, I can rotate it, but it's awefully slow. This would be horrible on my real function, which is much more complicated than the simple example I gave. – Cham Mar 24 '16 at 17:03
• Reducing the PlotPointsand using a Manipulate gives some interesting results, but it's very crude, and pretty slow : Manipulate[ ContourPlot3D[x^2 + y^2 + z^2 == 4, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, ColorFunction -> Function[{x, y, z}, ColorData["Rainbow"][WaveDensity[t, x, y, z]]], Mesh -> None, Axes -> True, ColorFunctionScaling -> False, PlotPoints -> 30, SphericalRegion -> True, Method -> {"RotationControl" -> "Globe"}, ImageSize -> {500, 500}], {{t, 0, "Time"}, 0, 1, 0.01}] – Cham Mar 24 '16 at 17:08