Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
963 views
in Technique[技术] by (71.8m points)

gnuplot: how to avoid viewing angle dependent semitransparent 3D surfaces?

I stumbled accross the following. If I plot, e.g. a cube using pm3d and define the sides to be semitransparent, I would expect that the cube looks the same if I rotate it by multiple of 90 degrees. However, apparently depending on the viewing angle a particular surface appears brighter or darker than the others. In the example below the views at 30 and 120 degrees have 3 different shades of red whereas the view at 210 and 300 degrees have only 2 shades of red. There is no pm3d lighting involved.

Questions: How can this be explained? How can this be avoided? Is something wrong with my definition of the cube? Did I miss anything in the documentation under help pm3d or help pm3d algorithm or help pm3d color_assignment? Am I using a too old gnuplot version (5.2.8) or "wrong" terminal (wxt)?

Code:

### semitransparent 3D surfaces
reset session

$Cube <<EOD
0 0 0
0 0 1
0 1 1
0 1 0
0 0 0

1 0 0
1 0 1
1 1 1
1 1 0
1 0 0

0 0 0
1 0 0
1 1 0
0 1 0
0 0 0

0 0 1
1 0 1
1 1 1
0 1 1
0 0 1
EOD

set view equal xyz
set cbrange [0.9:1]
set palette defined (1 'red')
set pm3d depthorder hidden3d
set pm3d implicit
unset hidden3d
unset label
unset tics
unset border
unset key
unset colorbox

set multiplot layout 2,3
    a=75
    b=30
    r=1.3
    set title sprintf("opaque view: %d, %d",a,b)
    set view a,b,r
    set style fill transparent solid 1
    splot $Cube u 1:2:3:(1) w l lw 0.5 lc "black"
    
    set style fill transparent solid 0.3
    do for [i=30:300:90] {
        set title sprintf("transparent view: %d, %d",a,i)
        set view a,i
        replot
    }
unset multiplot
### end of code

Result:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Multiple things are happening here

  1. Initially I thought that part of what you are seeing is evidence that the compositing operation of the graphics rendering in whichever terminal you are using is non-transitive. However I think that most or all of the effect can be explained without this.

      (background ° 0.3red) ° 0.3red  ?=?  background ° (0.3red ° 0.3red)
    
  2. One key is that your "cube" is not really a cube; it is missing 2 faces. Differential effect of the view angle is much more obvious if you draw them as polygons:

    unset pm3d
    splot $Cube u 1:2:3 w polygons
    
  3. Because you are using with pm3d, the program is trying to interpret the vertices as a set of scan lines defining a surface. This doesn't really work. I am not entirely sure what it ends up with but I suspect some of the areas are drawn twice. You can get a feel for what is going wrong here by drawing it again with

     set pm3d interpolate 2,2
    

enter image description here

If you add the missing two faces of the cube and draw the faces with polygons the effect disappears entirely.

set view equal xyz
unset hidden3d
unset tics
unset border
unset key

set multiplot layout 2,3
    a=75
    b=30
    r=1.3
    set title sprintf("opaque view: %d, %d",a,b)
    set view a,b,r
    set style fill transparent solid 1
    set pm3d border lw 0.5 lc "black"
    splot $Cube u 1:2:3 w polygons fc "red"
    
    set style fill transparent solid 0.3
    do for [i=30:300:90] {
        set title sprintf("transparent view: %d, %d",a,i)
        set view a,i
        replot
    }
unset multiplot

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...