5
$\begingroup$

could you give me some input on how to create a list version of

SphericalPlot3D[r[theta,phi],{theta,min,max},{phi,min,max}]

When r[] is an explicit analytical function it's not an issue, but what if one numerically generates a list {{r1,theta1,phi1},...,{rn,thetan,phin}} and wants to visualize it in a similar manner? Any ideas?

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – chris
    Commented Apr 1, 2013 at 7:02

2 Answers 2

8
$\begingroup$

A quick way of doing this would be to take the data and apply an Interpolation to create a function that can be plotted with SphericalPlot3D. Here is an example:

data = Flatten[
   Table[{{theta, phi}, 
     N@Re@SphericalHarmonicY[2, 1, theta, phi]}, {theta, Pi/10, Pi, 
     Pi/10}, {phi, Pi/10, 2 Pi, Pi/10}], 1];

f = Interpolation[data];

SphericalPlot3D[f[theta, phi], {theta, 0, Pi}, {phi, 0, 2 Pi}]

3D

Here you get a warning because extrapolation was used since the data range is smaller than the angle range I'm plotting. But that's normal.

Note that the data has to be arranged differently from the structure you gave in the question: It's of the form {{{theta1, phi1}, f1}, {{{theta2, phi2}, f2}, ...}

$\endgroup$
2
$\begingroup$

I was considering to advise the use of ListSurfacePlot3D to do this, but after tinkering with it for some while, I found it is awful for reconstruction of spherical plots.

Let's take an example from the documentation:

SphericalPlot3D[1 + 2 Cos[2 θ], {θ , 0, Pi}, {ϕ, 0, 2 Pi}]

Mathematica graphics

The surface could be sampled like this:

data = Flatten[Table[{1 + 2 Cos[2 θ], θ, ϕ}, {θ, 0, Pi, Pi/30}, {ϕ, 0, 2 Pi, 2 Pi/30}], 1];

In v9 we have got an easy way to transform coordinates form spherical to Cartesian:

mapping =  CoordinateTransformData["Spherical" -> "Cartesian", "Mapping"]

{Cos[#1[[3]]] Sin[#1[[2]]] #1[[1]], Sin[#1[[2]]] Sin[#1[[3]]] #1[[1]], Cos[#1[[2]]] #1[[1]]} &

Those without v9 can use the pure function in the output above.

This works fine withListPointPlot3D:

ListPointPlot3D[mapping /@ data, BoxRatios -> Automatic]

Mathematica graphics

However, it gets absolutely horrible results with ListSurfacePlot3D

ListSurfacePlot3D[mapping /@ data, BoxRatios -> Automatic]

Mathematica graphics

Increasing sampling density doesn't help at all. Neither does the application of the MaxPlotPoints->Infinity option. So, it looks like that Jens' answer is the best solution in this case.

$\endgroup$
5
  • $\begingroup$ This is quite odd. With /90 in both Table iterators and MaxPlotPoints -> 125 I get this: i.sstatic.net/s1G7n.png Fairly different, wouldn't you say? :^) $\endgroup$
    – Mr.Wizard
    Commented Apr 1, 2013 at 11:04
  • $\begingroup$ @Mr.Wizard Are you sure you havent used ListPlot3D instead of ListSurfacePlot3D? $\endgroup$ Commented Apr 1, 2013 at 15:57
  • $\begingroup$ @mr.wizard Back at the keyboard and can confirm what you got there. I tried increasing MaxPlotPoints to 500, but it brings my PC to its knees. $\endgroup$ Commented Apr 1, 2013 at 19:44
  • $\begingroup$ I think this is worthy of its own question. I'd like to know why that happens and if there are Method options etc., that better handle this case. Will you ask? $\endgroup$
    – Mr.Wizard
    Commented Apr 1, 2013 at 22:31
  • $\begingroup$ @Mr.Wizard It doesn't look answerable to me. Perhaps more an issue for WRI support. $\endgroup$ Commented Apr 2, 2013 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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