visualizationgnuplotspherical-coordinate

Drawing rectangles in spherical coordinates in gnuplot


I have the following dataset: grid which is a spherical partition using the Leopardi et al, 2006 algorithm. Each grid cell is a rectangle in spherical coordinates, defined by a top left corner (theta0,phi0) and a bottom right corner, (theta1,phi1). I made the plot above by generating a lot of points for each rectangle and using splot to plot all the points. But what I really want is to plot each rectangle with a different solid color.

The example at link is close to what I want to do, using the

set obj 1 rect

command. What I'd like to do is something like:

set obj 1 rect from spherical THETA0,PHI0,R to spherical THETA1,PHI1,R

and then repeat this for lots of different rectangles. But of course this won't work since there is no "spherical" option in the gnuplot coordinates. There is a "polar" option but it only works with 2D polar coordinates, or 3D cylindrical coordinates.

Does anyone know of a way to plot colored rectangles defined in spherical coordinates with gnuplot?


Solution

  • To my knowledge there is no simple drawing of a rectangle in spherical coordinates, please correct me if I'm wrong. You don't show your script how you actually created your graph, except you wrote that you've created a lot of of points for plotting the spherical rectangles. I guess that's what you have to do. However, you can "simply" let gnuplot do it with a "user-friendly" input.

    A few comments without going too much into the detail:

    There is certainly room for improvements.

    Script: (requires gnuplot>=5.2.0, because of using arrays)

    ### plotting spherical rectangles
    reset session
    
    set view equal xyz
    set view 60,100,1.97
    set isosamples 19,25
    set mapping spherical
    set xyplane relative 0
    set angles degrees
    unset key
    unset border
    unset tics
    set parametric
    set hidden3d offset 0
    set urange [-90:90]
    set vrange [0:360]
    
    # LAT0  LON0  LAT1  LON1  color
    $Data <<EOD             
      63     0    35    22    0xff0000
      10    -5   -10    10    0x00cc00
      52   -40     8   -25    0x0000ff
    EOD
    
    R = 6371         # earth radius
    N = 32           # choose a number divisible by 4
    array A[N+1]     # dummy array
    
    rectX(i,t) = t<0.25 ? 4*dx*t : t<0.5 ? dx            : t<0.75 ? 4*dx*(0.75-t) : 0
    rectY(i,t) = t<0.25 ? 0      : t<0.5 ? 4*dy*(t-0.25) : t<0.75 ? dy            : 4*dy*(1-t)
    init(i)    = (x0=real(word($Data[i],2)),    y0=real(word($Data[i],1)), \
                  dx=real(word($Data[i],4))-x0, dy=real(word($Data[i],3))-y0)
    lon(i)     = rectX(i,column(0)/N) + x0
    lat(i)     = rectY(i,column(0)/N) + y0
    color(i)   = int(word($Data[i],5))
    
    splot R*cos(u)*cos(v), R*cos(u)*sin(v), R*sin(u) w l lc rgb "grey" , \
          'world.dat' u 1:2:(R) w l lc "black", \
          for [i=1:|$Data|] tmp=init(i) A u (lon(i)):(lat(i)): \
              (R):(color(i)) w l lw 2 lc rgb var
    ### end of script
    

    Result:

    enter image description here