0
$\begingroup$

I'm very new to Mathematica. I'm trying to spherical plot a sphere from an n-row, 3-column matrix. The radius is a constant, the first and second columns are theta and phi of the points, and the last column is the (intensity) color corresponding to that theta, phi.

I have tried to interpolate {theta, phi} with intensity. My data has almost 20000 points(rows), so I just used 3 points to try. Following is my coding:

theta = {Pi/4, Pi/6, Pi/2}
phi = {Pi/6, 0, Pi/2}
intensity = {2, 1, 3}
dat = Table[{{theta[[m]], phi[[m]]}, intensity[[m]]}, {m, 1, Length[theta]}]
f = Interpolation[dat]
f[theta, phi]
points = N@ CoordinateTransformData["Spherical" -> "Cartesian", "Mapping", #] & /@ {{2, Pi/6, 0}, {2, Pi/4, Pi/6}, {2, Pi/2, Pi/2}};
Show[SphericalPlot3D[2, {theta, 0, Pi/2}, {phi, 0, Pi/2}, ColorFunction -> 
   Function[{theta, phi}, ColorData["Rainbow"][f[theta, phi]]]], 
 ListPointPlot3D[points, PlotStyle -> Directive[Green, PointSize -> .03]]]

And I got the result like this enter image description here

It shows my points lie outside the range of data, and the color change of the sphere seems irreverent from the original data points (the green ones I marked on the sphere).

I appreciate it a lot if you can help me solve this problem! Thanks!

$\endgroup$
2
  • $\begingroup$ Try using Interpolation on your entire 2D array. $\endgroup$
    – bbgodfrey
    Jan 16, 2022 at 17:41
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) 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, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Jan 16, 2022 at 17:42

1 Answer 1

1
$\begingroup$

First,with only 3 points you can only use "InterpolationOrder->1". Toward this aim I create new "intensity" data and function "f" like (note the point at the north pole is double, what will not harm):

dat = Flatten[Table[{{th, ph}, th ph}, {th, 0, Pi/2}, {ph, 0, Pi/2}], 
  1];
f = Interpolation[dat, InterpolationOrder -> 1];

To get the cartesian coordinates of the points we define

trans[{th_, ph_}] = 
 CoordinateTransformData["Spherical" -> "Cartesian", 
  "Mapping", {2, th, ph}];
points = trans /@ dat[[All, 1]] // N;

Finally we can plot:

Show[SphericalPlot3D[2, {th, 0, Pi/2}, {ph, 0, Pi/2}, 
  ColorFunction -> 
   Function[{x, y, z, \[Theta], \[Phi], r}, 
    ColorData["Rainbow"][f[\[Theta], \[Phi]]]]], 
 ListPointPlot3D[points, 
  PlotStyle -> Directive[Black, PointSize -> .03]]]

enter image description here

$\endgroup$
7
  • $\begingroup$ Hi Daniel, thanks for your reply. Maybe I didn't describe my question clear. What I have is a matrix with first two columns about coordinations (theta phi), and the last column is the intensity corresponding to these coordinates. So the color (intensity) is not like what you created maximum at one side of the sphere and minimum at another side. I tried to add interpolation order as 1 in my previous codes but it still give me the same result in the question. I guess probably I shouldnt use interpolation, but I dont know what else I can use... $\endgroup$
    – tll
    Jan 16, 2022 at 23:55
  • $\begingroup$ If you want to use "Interpolation" you must give points over the whole domain to be plotted. That is from 0 to Pi/2 for theta and phi. As I did not know the intensities there, I used arbitrary intensities. You are free to insert the right ones. $\endgroup$ Jan 17, 2022 at 8:47
  • $\begingroup$ I used my whole data (almost 20k points) interpolation and plotting, but the sphere is quite strange losing lots of intensity information, (I was hoping to see a few hot spots on the sphere, instead, there is only a block of red and another block of purple on the sphere. Seems like interpolation cannot allow me to assign the color to the point on the sphere precisely. $\endgroup$
    – tll
    Jan 17, 2022 at 17:05
  • $\begingroup$ Try to determine what the max and min of you intensities are. And also if the intensities are evenly distributed between these 2 values or not. $\endgroup$ Jan 17, 2022 at 17:25
  • $\begingroup$ The intensities range from 1577 to -2094, and they are not evenly distributed (large difference among data near two extremes and tiny difference among data near 0, I guess thats the reason I cannot precisely assign the intensity... $\endgroup$
    – tll
    Jan 17, 2022 at 20:19

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.