Reputation: 25704
Plotting a sphere with pm3d
works fine.
However, when I want to give an offset I get some artifact which I don't unterstand.
Any ideas why I get a "black hole" into my sphere when shifting the coordinates by adding some numbers?
Created with gnuplot 5.2.8
Code:
### plotting artifact with splot and pm3d
reset session
set view equal xyz
set view 45,45, 2
unset tics
unset colorbox
unset key
set margins 0,0,0,0
unset border
set style fill solid 1.0 noborder
set pm3d depthorder noborder
set pm3d lighting specular 0.5
# Create a sphere prototype dataset
set parametric
set isosamples 25
set samples 25
set urange [-pi/2:pi/2]
set vrange [0:2*pi]
Radius = 1
set table $Sphere
splot Radius*cos(u)*cos(v), Radius*cos(u)*sin(v), Radius*sin(u)
unset table
unset parametric
set palette defined (0 "#ff0000", 1 "#ff0000")
set view 153, 90
splot $Sphere u 1:2:3 w pm3d
pause -1 "Press OK to see the next plot"
splot $Sphere u ($1+1.0):($2+2.0):($3+3.0) w pm3d
### end of code
Result:
With offset:
Upvotes: 2
Views: 139
Reputation: 15093
The problem is in the lighting model code. It calculates the surface normal for each quadrangle facet of the pm3d surface using the cross product (v1-v0)x(v2-v0). In this case the quadrangles that touch the "poles" of the sphere become degenerate because two of the four vertices lie exactly on the pole, leaving only a triangle. Depending on which of the two vertices coincide, the normal becomes undefined and the lighting calculation bails out, returning 0 = black. So that's a fixable bug, since a different choice of vertices would still allow calculating the normal.
Workaround: Limit the range of the parametric variable 'u' so that the quadrangles do not quite reach the poles:
epsilon=0.0001
set urange [epsilon - pi/2 : pi/2 - epsilon]
For what it's worth, another workaround is set pm3d interpolation 3,3
. I'm not sure why that works, but it might be useful if the same problem crops up when plotting a data set that isn't generated on the spot.
Upvotes: 3