使用gnuplot绘制三角形网格

4

使用 gnuplot 经常需要绘制三角形网格。

目前我所看到的唯一方法是使用 with lines 选项制作“线框”,并在每个面的闭合线链之间使用双重换行符(第一个点和最后一个点相同):

$wireframe <<EOD
 0  1 1 p1
 1 -1 1 p2
-1 -1 1 p3
 0  1 1 


 2  1 0 p4
 0  1 1 
 1 -1 1 
 2  1 0 


 0 -2 0 p5
 1 -1 1 
-1 -1 1 
 0 -2 0 


-2  1 0 p6
-1 -1 1 
 0  1 1 
-2  1 0 
EOD
splot '$wireframe' with lines notitle, '' with labels offset character 0, character 1 notitle

这是4个三角形: 1个在中心(p1,p2,p3),另外3个与其边相邻。
对于定义网格的某些方式,存在很多重复。有时将网格定义为三角形带或三角形扇形更为合适。
另一个问题是如何通过某种颜色填充3D三角形的内部。目前我只能使用不同颜色(来自调色板)绘制不同链式线条的框架。但它们会重叠。
比如说,我想画一个二十面体。它是一个封闭的实体,由三角形面限制。
2个回答

4
set terminal wxt size 800,600

#set title "Graph Title"
#set xlabel "X"
#set ylabel "Y"
#set zlabel "Z"

# sets background color
set object 1 rectangle from screen -0.1,-0.1 to screen 1.1,1.1 fillcolor rgb "#ffffff" behind

# allows rendering of polygons with hidden line removal
set hidden3d back offset 0 trianglepattern 3 undefined 1 altdiagonal bentover

# displays borders 0x7F = 0b1111111
set border 0x7F linecolor rgb "#555555"

# displays the x, y and z axis
set xzeroaxis linewidth 0.5 linetype 1
set yzeroaxis linewidth 0.5 linetype 2
set zzeroaxis linewidth 0.5 linetype 3

# displays the x, y and z grid
set grid xtics linecolor rgb "#888888" linewidth 0.2 linetype 9
set grid ytics linecolor rgb "#888888" linewidth 0.2 linetype 9
set grid ztics linecolor rgb "#888888" linewidth 0.2 linetype 9

# moves the x, y grid to 0
set xyplane at 0

# makes the x, y, and z axis proportional
set view equal xyz

# sets the axis range
set xrange [-10:10]
set yrange [-10:10]
set zrange [-10:10]

# moves the key out of the graph
set key outside vertical bottom right

# hides the key
set key off

splot\
"ico.dat" title "ico" with lines linewidth 2.1 linecolor rgb "#88FF88"

ico.dat:

-1.381925 -4.253200 -2.236075
0.000000 0.000000 -5.000000

3.618000 -2.628600 -2.236075
3.618000 -2.628600 -2.236075


3.618000 -2.628600 -2.236075
0.000000 0.000000 -5.000000

3.618000 2.628600 -2.236075
3.618000 2.628600 -2.236075


-4.472125 0.000000 -2.236075
0.000000 0.000000 -5.000000

-1.381925 -4.253200 -2.236075
-1.381925 -4.253200 -2.236075


-1.381925 4.253200 -2.236075
0.000000 0.000000 -5.000000

-4.472125 0.000000 -2.236075
-4.472125 0.000000 -2.236075


3.618000 2.628600 -2.236075
0.000000 0.000000 -5.000000

-1.381925 4.253200 -2.236075
-1.381925 4.253200 -2.236075


3.618000 -2.628600 -2.236075
3.618000 2.628600 -2.236075

4.472125 0.000000 2.236075
4.472125 0.000000 2.236075


-1.381925 -4.253200 -2.236075
3.618000 -2.628600 -2.236075

1.381925 -4.253200 2.236075
1.381925 -4.253200 2.236075


-4.472125 0.000000 -2.236075
-1.381925 -4.253200 -2.236075

-3.618000 -2.628600 2.236075
-3.618000 -2.628600 2.236075


-1.381925 4.253200 -2.236075
-4.472125 0.000000 -2.236075

-3.618000 2.628600 2.236075
-3.618000 2.628600 2.236075


3.618000 2.628600 -2.236075
-1.381925 4.253200 -2.236075

1.381925 4.253200 2.236075
1.381925 4.253200 2.236075


4.472125 0.000000 2.236075
1.381925 -4.253200 2.236075

3.618000 -2.628600 -2.236075
3.618000 -2.628600 -2.236075


1.381925 -4.253200 2.236075
-3.618000 -2.628600 2.236075

-1.381925 -4.253200 -2.236075
-1.381925 -4.253200 -2.236075


-3.618000 -2.628600 2.236075
-3.618000 2.628600 2.236075

-4.472125 0.000000 -2.236075
-4.472125 0.000000 -2.236075


-3.618000 2.628600 2.236075
1.381925 4.253200 2.236075

-1.381925 4.253200 -2.236075
-1.381925 4.253200 -2.236075


1.381925 4.253200 2.236075
4.472125 0.000000 2.236075

3.618000 2.628600 -2.236075
3.618000 2.628600 -2.236075


1.381925 -4.253200 2.236075
4.472125 0.000000 2.236075

0.000000 0.000000 5.000000
0.000000 0.000000 5.000000


-3.618000 -2.628600 2.236075
1.381925 -4.253200 2.236075

0.000000 0.000000 5.000000
0.000000 0.000000 5.000000


-3.618000 2.628600 2.236075
-3.618000 -2.628600 2.236075

0.000000 0.000000 5.000000
0.000000 0.000000 5.000000


1.381925 4.253200 2.236075
-3.618000 2.628600 2.236075

0.000000 0.000000 5.000000
0.000000 0.000000 5.000000


4.472125 0.000000 2.236075
1.381925 4.253200 2.236075

0.000000 0.000000 5.000000
0.000000 0.000000 5.000000

由Blender和Python脚本生成:
https://github.com/lowlevel86/blender-to-gnuplot


完美。数据的意义是什么?我看到了“2个点,空行,空行,…”的模式。 - Tomilov Anatoliy
1
http://www.gnuplot.info/faq/faq.html#x1-370003.14 - user2376639

1
一个解决方法是编写一个 gawk/Python 脚本来解析面的定义,并生成一个 Gnuplot 脚本,在其中手动绘制面作为多边形。
set xr [0:1]
set yr [0:1]
set zr [0:1]

#generate the polygons
set object polygon from 0,0,0 to 1,0,0 to 1,1,0 to 0,1,0 to 0,0,0 fc rgb "cyan" fillstyle solid 1.0 border lt -1
set object polygon from 1,0,0 to 1,1,0 to 1,1,1 to 1,0,1 to 1,0,0 fc rgb "cyan" fillstyle solid 1.0 border lt -1

#do not plot anything
splot 1/0

高多边形网格太昂贵了,但肯定有解决方法。 - Tomilov Anatoliy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接