Bo Sundman
Bo Sundman

Reputation: 434

color surfaces in 3D

I am a great fan of GNUPLOT and it has not failed me often. Usually I just draw 2D figures as the reality I deal with in thermodynamics is multidimensional and using 3D is not really helpful. But I have found a case where I would like to have a 3D plot with a colored plane surface and I do not manage. A simple example is:

set terminal wxt size 840,700 font "Arial,16"
set origin 0.0, 0.0 
set size   1.0000,   1.0000
set xlabel "X"
set ylabel "Y"

set style line 1 lt  1 lc rgb "#FF0000" lw 2
set style line 2 lt  1 lc rgb "#00FF00" lw 2

splot "-" using 1:2:3 with lines ls 1 notitle,\
"" using 1:2:3 with lines ls 2 notitle
0 1 0
0 1 1
1 0 1
1 0 0
0 1 0

e
0 0 0
0 1 0
1 1 0
1 0 0
0 0 0

e

pause mouse

which draws a red and green rectangle. However, I want the interior of the rectangles to be red or green. In 2D I can use "filledcurves" but it does not seem to work in 3D. I have seen examples how to generate a complex surface with a color but I just need a colored planar surface. There should be a simple way to do that also in 3D.

Upvotes: 1

Views: 103

Answers (1)

Ethan
Ethan

Reputation: 15093

set object 1 polygon from 0,1,0 to 0,1,1 to 1,0,1 to 1,0,0 to 0,1,0
set object 1 fillstyle transparent solid 0.5 fillcolor "red"

set object 2 polygon from 0,0,0 to 0,1,0 to 1,1,0 to 1,0,0 to 0,0,0
set object 2 fillstyle transparent solid 0.5 fillcolor "dark-green"

set xrange [0:1]; set yrange [0:1]; set zrange [0:1]
set xyplane 0

splot -1 notitle  # this is out of range so it won't show

The reason for depicting the rectangles as 50% transparent is that the hidden surface algorithm in gnuplot was only designed for surfaces; it is not capable of subdividing arbitrary objects so that partial occlusion of one solid object by another is correctly rendered.
enter image description here

Upvotes: 3

Related Questions