4
$\begingroup$

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.

$\endgroup$
3
  • $\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$ Commented Mar 24, 2016 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$ Commented Mar 24, 2016 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$ Commented Mar 24, 2016 at 17:16

2 Answers 2

10
$\begingroup$

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 ] 

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

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:

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

2D contours

$\endgroup$
6
  • $\begingroup$ As the OP wants to vary time, that could be used as the variable in an animation. $\endgroup$ Commented Mar 24, 2016 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$ Commented Mar 24, 2016 at 16:27
  • $\begingroup$ @MarcoB, unfortunately, my old version 7 doesn't recognize SliceContourPlot3D , while it knows ContourPlot3D. $\endgroup$ Commented Mar 24, 2016 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$ Commented Mar 24, 2016 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$ Commented Mar 24, 2016 at 17:22
7
$\begingroup$

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 ] 

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.

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.