Hi,
I'm extending Hagen Wierstorf's scripts for drawing cubes (
http://www.gnuplotting.org/plotting-cubes/) to plot blocks of arbitrary sizes.
Here's my code:
reset
set terminal qt size 700,524 enhanced font 'Verdana,10'
# color definitions
set cbrange [1:10]
set style fill transparent solid 1.0
set palette defined (\
1 '#ff4c4d',\
2 '#ce4c7d',\
3 '#ae559e',\
4 '#df866d',\
5 '#ffb66d',\
6 '#ffe7cf',\
7 '#cecece',\
8 '#6d6d6d',\
9 '#4c4c8e',\
10 '#4c4cef')
set style line 1 lc rgb '#ff2727' lt 1 lw 0.5
set style line 2 lc rgb '#b90046' lt 1 lw 0.5
set style line 3 lc rgb '#8b0b74' lt 1 lw 0.5
set style line 4 lc rgb '#d1512e' lt 1 lw 0.5
set style line 5 lc rgb '#ff972f' lt 1 lw 0.5
set style line 6 lc rgb '#ffddba' lt 1 lw 0.5
set style line 7 lc rgb '#b9b9b9' lt 1 lw 0.5
set style line 8 lc rgb '#2e2e2e' lt 1 lw 0.5
set style line 9 lc rgb '#00005d' lt 1 lw 0.5
set style line 10 lc rgb '#0000e8' lt 1 lw 0.5
unset key
#set border 0
unset border
unset tics
unset colorbox
#set view 58,29,1.5
set view equal xyz
#uset xyplane at 0
#set xlabel "x" offset 10,0,0
#set ylabel "y" offset 0,0,10
#set zlabel "z" offset 5,0,0
# load block function
load 'block.fct'
set pm3d hidden3d
set pm3d implicit
set unhidden3d
set lmargin 2
set rmargin 0
set bmargin 0
set tmargin 0
# get block positions from file
add_block(x,y,z,h,l,w,c) = sprintf('block(%f,%f,%f,%f,%f,%f,%i) w l ls %i,',x,y,z,h,l,w,c,c)
CMD = ''
stats 'proofblocks3.txt' u 1:(CMD = CMD.add_block($1,$2,$3,$4,$5,$6,$7)) nooutput
set xrange [0:4]
set yrange [0:4]
set zrange [0:3]
CMD = 'splot '.CMD.'1/0 w l ls 2'
# plot block
eval(CMD)
Content of block.fct:
# gnuplot function to create a cube
#
# Usage: block(x, y, z, w, l, h, c)
block(x,y,z,w,l,h,c) = sprintf('<echo "\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\
%f %f %f %i\n\n"',\
0.1+x,0.1+y,0.1+z,c,\
0.1+x,0.1+y,(h-0.1)+z,c,\
0.1+x,(l-0.1)+y,(h-0.1)+z,c,\
0.1+x,(l-0.1)+y,0.1+z,c,\
0.1+x,0.1+y,0.1+z,c,\
(w-0.1)+x,0.1+y,0.1+z,c,\
(w-0.1)+x,0.1+y,h-0.1+z,c,\
(w-0.1)+x,(l-0.1)+y,h-0.1+z,c,\
(w-0.1)+x,(l-0.1)+y,0.1+z,c,\
(w-0.1)+x,0.1+y,0.1+z,c,\
0.1+x,0.1+y,0.1+z,c,\
(w-0.1+x),0.1+y,0.1+z,c,\
(w-0.1+x),(l-0.1)+y,0.1+z,c,\
0.1+x,(l-0.1+y),0.1+z,c,\
0.1+x,0.1+y,0.1+z,c,\
0.1+x,0.1+y,(h-0.1+z),c,\
(w-0.1)+x,0.1+y,(h-0.1+z),c,\
(w-0.1)+x,(l-0.1)+y,(h-0.1+z),c,\
0.1+x,(l-0.1)+y,(h-0.1+z),c,\
0.1+x,0.1+y,(h-0.1)+z,c\
)
The problem is that, when a plane (a side of a block) is longer than another in front of it, I suppose because gnuplot doesn't work like a ray tracer, it plots that larger plane in front of plane closer to the viewers because it has a point that's closer to the viewer:
http://imgur.com/a/CcGO1
Is there a way to get around this problem - as in have the surfaces plotted in the correct depth order?