2016-08-02 60 views
2

我正在扩展Hagen Wierstorf's scripts for drawing cubes绘制任意大小的块。Gnuplot:用正确的深度顺序绘制3d块使用splot

这里是我的代码:block.fct的

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 
unset border 
unset tics 
unset colorbox 
set view equal xyz 

# load block function 
load 'block.fct' 

set pm3d hidden3d 
set pm3d implicit 
unset hidden3d 

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) 

内容:

# 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\ 
) 

的问题是,当一个面(块的一侧)比另一长在前面它,我想是因为gnuplot不能像射线跟踪器一样工作,它会在飞机前面靠近观看者的大平面,因为它有一个距离观看者更近的点:

用于上述图像个

坐标 - proofblocks3.txt内容:

# x y z w l h color 
0 0 0 1 1 1 1 
1 0 0 1 3 1 2 
2 0 0 1 1 1 3 
0 1 0 1 1 1 4 
2 1 0 1 1 1 5 
0 2 0 1 1 1 6 
2 2 0 1 1 1 7 

有没有办法来解决这个问题 - 如在正确的深度顺序策划了表面?

+1

您是否也可以提供用于测试的'proofblocks3.txt'的内容?与此同时尝试'设置pm3d深度顺序',见http://gnuplot.sourceforge.net/demo/hidden2.html第二个例子 – Christoph

+0

嗨@Christoph,我发布了'proofblocks3.txt'的内容。不幸的是,'深度顺序'并没有改变剧情。请注意,我更正了主脚本,将“set unhidden3d”更正为“unset hidden3d”。谢谢! – Cescante

+1

好的。我不知道如何让它与gnuplot一起工作。只有'设置hidden3d'和没有'pm3d'设置它的作品,但你没有得到的颜色;)我读过,'设置pm3d hidden3d'只适用于非常特殊的情况。这就是gnuplot达到极限的地方。 – Christoph

回答

0

编号

Gnuplot是一个具有一些模拟3D功能的2D绘图程序。

事实上,其他2D绘图程序(如python的matplotlib)也存在同样的问题。为了创建真实的三维图,人们应该考虑MATLAB(粗糙)或Mayavi for Python(参见:Is there something like a depth buffer in matplotlib?)。