This question already has an answer here:

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.


marked as duplicate by Jens, m_goldberg, Jason B., RunnyKine, user9660 Mar 24 '16 at 18:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ 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? $\endgroup$ – MarcoB Mar 24 '16 at 17:06
  • $\begingroup$ @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). $\endgroup$ – Cham Mar 24 '16 at 17:12
  • $\begingroup$ @Cham Sure, added to answer. That is also almost fast enough for a regular Manipulate. See the edit to my answer. $\endgroup$ – 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$):

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

static 3D surface contour plot

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[
     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}


Animated list of 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:

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

2D contours

  • $\begingroup$ As the OP wants to vary time, that could be used as the variable in an animation. $\endgroup$ – J. M. will be back soon Mar 24 '16 at 16:25
  • $\begingroup$ @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. $\endgroup$ – MarcoB Mar 24 '16 at 16:27
  • $\begingroup$ @MarcoB, unfortunately, my old version 7 doesn't recognize SliceContourPlot3D , while it knows ContourPlot3D. $\endgroup$ – Cham Mar 24 '16 at 16:33
  • $\begingroup$ @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. $\endgroup$ – Cham Mar 24 '16 at 17:19
  • $\begingroup$ @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 ? $\endgroup$ – Cham Mar 24 '16 at 17:22

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

 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

enter image description here

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.

  • $\begingroup$ It's working, but it's very slow. $\endgroup$ – Cham Mar 24 '16 at 16:58
  • $\begingroup$ @Cham The plot does rotate, it's probably just awfully slow. It is quite jerky on my laptop. $\endgroup$ – MarcoB Mar 24 '16 at 16:59
  • $\begingroup$ It's jerky for you ? On which version ? $\endgroup$ – Cham Mar 24 '16 at 17:00
  • $\begingroup$ 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. $\endgroup$ – Cham Mar 24 '16 at 17:03
  • $\begingroup$ 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}] $\endgroup$ – Cham Mar 24 '16 at 17:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.