【问题标题】:Gnuplot: Drawing 3d blocks with correct depth order using splotGnuplot:使用 splot 绘制具有正确深度顺序的 3d 块
【发布时间】:2016-08-02 00:51:45
【问题描述】:

我正在扩展 Hagen Wierstorf's scripts for drawing cubes 以绘制任意大小的块。

这是我的代码:

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)

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

问题是,当一个平面(块的一侧)比它前面的另一个长时,我想是因为 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

有没有办法解决这个问题——比如表面是否以正确的深度顺序绘制?

【问题讨论】:

  • 能否也把proofblocks3.txt的内容给测试一下?同时尝试set pm3d depthorder,参见gnuplot.sourceforge.net/demo/hidden2.html的第二个示例
  • 嗨@Christoph,我已经发布了“proofblocks3.txt”的内容。不幸的是,“depthorder”并没有改变情节中的任何东西。请注意,我更正了主脚本以将“set unhidden3d”更正为“unset hidden3d”。谢谢!
  • 好的。我不知道你如何让它与 gnuplot 一起工作。只有set hidden3d 而没有pm3d 设置它可以工作,但你不会得到颜色;)我读过,set pm3d hidden3d 只在非常特殊的情况下工作。这就是 gnuplot 达到其极限的地方。

标签: gnuplot


【解决方案1】:

没有。

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

事实上,其他 2D 绘图程序也存在同样的问题,例如 matplotlib for python。

要创建真正的 3D 绘图,应考虑使用 MATLAB(粗略)或 Mayavi for Python(参见:Is there something like a depth buffer in matplotlib?)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    相关资源
    最近更新 更多