TransWikia.com

Which function should I use to spherically 3D plot an interpolation function of two variables

Mathematica Asked by A. Chitzac on May 11, 2021

I have a dataset in the form:

valuesfitC12 = {{{-180, 0}, 21.14`}, {{-180, 5}, 21.29`}, {{-180, 10},
     21.44`}, {{-180, 20}, 21.74`}, {{-180, 30}, 21.84`}, {{-170, 0}, 
    21.14`}, {{-170, 5}, 21.34`}, {{-170, 10}, 21.44`}, {{-170, 20}, 
    21.69`}, {{-170, 30}, 21.79`}, {{-160, 0}, 21.14`}, {{-160, 5}, 
    21.34`}, {{-160, 10}, 21.39`}, {{-160, 20}, 21.74`}, {{-160, 30}, 
    21.84`}, {{-150, 0}, 21.14`}, {{-150, 5}, 21.34`}, {{-150, 10}, 
    21.44`}, {{-150, 20}, 21.69`}, {{-150, 30}, 21.79`}, {{-140, 0}, 
    21.14`}, {{-140, 5}, 21.29`}, {{-140, 10}, 21.49`}, {{-140, 20}, 
    21.69`}, {{-140, 30}, 21.69`}, {{-130, 0}, 21.14`}, {{-130, 5}, 
    21.34`}, {{-130, 10}, 21.39`}, {{-130, 20}, 21.74`}, {{-130, 30}, 
    21.84`}, {{-120, 0}, 21.14`}, {{-120, 5}, 21.29`}, {{-120, 10}, 
    21.44`}, {{-120, 20}, 21.74`}, {{-120, 30}, 21.84`}, {{-110, 0}, 
    21.14`}, {{-110, 5}, 21.34`}, {{-110, 10}, 21.44`}, {{-110, 20}, 
    21.69`}, {{-110, 30}, 21.79`}, {{-100, 0}, 21.14`}, {{-100, 5}, 
    21.34`}, {{-100, 10}, 21.39`}, {{-100, 20}, 21.74`}, {{-100, 30}, 
    21.84`}, {{-90, 0}, 21.14`}, {{-90, 5}, 21.34`}, {{-90, 10}, 
    21.44`}, {{-90, 20}, 21.69`}, {{-90, 30}, 21.79`}, {{-80, 0}, 
    21.14`}, {{-80, 5}, 21.29`}, {{-80, 10}, 21.49`}, {{-80, 20}, 
    21.69`}, {{-80, 30}, 21.69`}, {{-70, 0}, 21.14`}, {{-70, 5}, 
    21.34`}, {{-70, 10}, 21.39`}, {{-70, 20}, 21.74`}, {{-70, 30}, 
    21.84`}, {{-60, 0}, 21.14`}, {{-60, 5}, 21.29`}, {{-60, 10}, 
    21.44`}, {{-60, 20}, 21.74`}, {{-60, 30}, 21.84`}, {{-50, 0}, 
    21.14`}, {{-50, 5}, 21.34`}, {{-50, 10}, 21.44`}, {{-50, 20}, 
    21.69`}, {{-50, 30}, 21.79`}, {{-40, 0}, 21.14`}, {{-40, 5}, 
    21.34`}, {{-40, 10}, 21.39`}, {{-40, 20}, 21.74`}, {{-40, 30}, 
    21.84`}, {{-30, 0}, 21.14`}, {{-30, 5}, 21.34`}, {{-30, 10}, 
    21.44`}, {{-30, 20}, 21.69`}, {{-30, 30}, 21.79`}, {{-20, 0}, 
    21.14`}, {{-20, 5}, 21.29`}, {{-20, 10}, 21.49`}, {{-20, 20}, 
    21.69`}, {{-20, 30}, 21.69`}, {{-10, 0}, 21.14`}, {{-10, 5}, 
    21.34`}, {{-10, 10}, 21.39`}, {{-10, 20}, 21.74`}, {{-10, 30}, 
    21.84`}, {{0, 0}, 21.14`}, {{0, 5}, 21.29`}, {{0, 10}, 
    21.44`}, {{0, 20}, 21.74`}, {{0, 30}, 21.84`}, {{10, 0}, 
    21.14`}, {{10, 5}, 21.34`}, {{10, 10}, 21.44`}, {{10, 20}, 
    21.69`}, {{10, 30}, 21.79`}, {{20, 0}, 21.14`}, {{20, 5}, 
    21.34`}, {{20, 10}, 21.39`}, {{20, 20}, 21.74`}, {{20, 30}, 
    21.84`}, {{30, 0}, 21.14`}, {{30, 5}, 21.34`}, {{30, 10}, 
    21.44`}, {{30, 20}, 21.69`}, {{30, 30}, 21.79`}, {{40, 0}, 
    21.14`}, {{40, 5}, 21.29`}, {{40, 10}, 21.49`}, {{40, 20}, 
    21.69`}, {{40, 30}, 21.69`}, {{50, 0}, 21.14`}, {{50, 5}, 
    21.34`}, {{50, 10}, 21.39`}, {{50, 20}, 21.74`}, {{50, 30}, 
    21.84`}, {{60, 0}, 21.14`}, {{60, 5}, 21.29`}, {{60, 10}, 
    21.44`}, {{60, 20}, 21.74`}, {{60, 30}, 21.84`}, {{70, 0}, 
    21.14`}, {{70, 5}, 21.34`}, {{70, 10}, 21.44`}, {{70, 20}, 
    21.69`}, {{70, 30}, 21.79`}, {{80, 0}, 21.14`}, {{80, 5}, 
    21.34`}, {{80, 10}, 21.39`}, {{80, 20}, 21.74`}, {{80, 30}, 
    21.84`}, {{90, 0}, 21.14`}, {{90, 5}, 21.34`}, {{90, 10}, 
    21.44`}, {{90, 20}, 21.69`}, {{90, 30}, 21.79`}, {{100, 0}, 
    21.14`}, {{100, 5}, 21.29`}, {{100, 10}, 21.49`}, {{100, 20}, 
    21.69`}, {{100, 30}, 21.69`}, {{110, 0}, 21.14`}, {{110, 5}, 
    21.34`}, {{110, 10}, 21.39`}, {{110, 20}, 21.74`}, {{110, 30}, 
    21.84`}, {{120, 0}, 21.14`}, {{120, 5}, 21.29`}, {{120, 10}, 
    21.44`}, {{120, 20}, 21.74`}, {{120, 30}, 21.84`}, {{130, 0}, 
    21.14`}, {{130, 5}, 21.34`}, {{130, 10}, 21.44`}, {{130, 20}, 
    21.69`}, {{130, 30}, 21.79`}, {{140, 0}, 21.14`}, {{140, 5}, 
    21.34`}, {{140, 10}, 21.39`}, {{140, 20}, 21.74`}, {{140, 30}, 
    21.84`}, {{150, 0}, 21.14`}, {{150, 5}, 21.34`}, {{150, 10}, 
    21.44`}, {{150, 20}, 21.69`}, {{150, 30}, 21.79`}, {{160, 0}, 
    21.14`}, {{160, 5}, 21.29`}, {{160, 10}, 21.49`}, {{160, 20}, 
    21.69`}, {{160, 30}, 21.69`}, {{170, 0}, 21.14`}, {{170, 5}, 
    21.34`}, {{170, 10}, 21.39`}, {{170, 20}, 21.74`}, {{170, 30}, 
    21.84`}, {{180, 0}, 21.14`}, {{180, 5}, 21.29`}, {{180, 10}, 
    21.44`}, {{180, 20}, 21.74`}, {{180, 30}, 21.84`}}; 

… and I’m creating a interpolation function the following way:

newvalfit = 
 Partition[
  Riffle[Reverse[valuesfitC12[[All, 1]]*Pi/180, 2], 
   valuesfitC12[[All, 2]]], 2]; (*convert to radian*)
f =  Interpolation[newvalfit]

… which gives me an interpolation function of form f[theta,phi].

I can’t seem to find a way how get a spherical plot by limiting theta=[0,Pi/6] and phi[-Pi,Pi] since every other value of the function is extrapolated and I can’t use. I’ve tried this but the ranges are totally off, even though I explicitly set them:

SphericalPlot3D[f[theta, phi], {theta, 0, Pi/6}, {phi, -Pi, Pi}, 
 BoxRatios -> {1, 1, 0.5}]

spherical plot3d of interpolation function

Also my function values should only lie between {21.14 , 21.84} but that doesn’t seem to be the case. Is there another way to plot it? What am I doing wrong? Many thanks in advance!

One Answer

Straighforward:

valuesfitC12[[All, 1, 1]] 2 π/360
valuesfitC12[[All, 1, 2]] π/180
Partition[
 Riffle[Partition[Riffle[%%, %], 2], valuesfitC12[[All, 2]]], 2]
r = Interpolation@%

ListSurfacePlot3D[
 Flatten[Table[{r[ϕ, θ] Cos[ϕ] Sin[θ], 
    r[ϕ, θ] Sin[θ] Sin[ϕ], 
    r[ϕ, θ] Cos[θ]}, {ϕ, -π, π, π/
     18}, {θ, 0, π/6, π/36}], 1], 
 PlotRange -> {{-22, 22}, {-22, 22}, {-22, 22}}] 

ListSurfacePlot3D

After transforming the -180,180 to -pi,pi, and the other angular value. Then interpolate this transformed radial values as above. This result suggests that the SphericalPlot3D is in need of that transformation too.

ListSurfacePlot3D[
 Flatten[Table[{r[ϕ, θ] Cos[ϕ] Sin[θ], 
    r[ϕ, θ] Sin[θ] Sin[ϕ], 
    r[ϕ, θ] Cos[θ]}, {ϕ, -π, π, π/
     18}, {θ, 0, π/6, π/36}], 
  1](*,PlotRange[Rule]{{-22,22},{-22,22},{-22,22}}*), 
 MaxPlotPoints -> 20, Mesh -> All]

different view less PlotPoints

ListSurfacePlot3D[
 Flatten[Table[{r[ϕ, θ] Cos[ϕ] Sin[θ], 
    r[ϕ, θ] Sin[θ] Sin[ϕ], 
    r[ϕ, θ] Cos[θ]}, {ϕ, -π, π, π/
     18}, {θ, 0, π/6, π/36}], 1], 
 PlotRange -> {{-2, 2}, {-2, 2}, {18, 22}}, MaxPlotPoints -> 50, 
 Mesh -> All]

the tower towards the center of the sphere

Correct answer by Steffen Jaeschke on May 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP