D6. Voxels and isosurfaces
Goal: a 3D scalar field, a value per voxel, shown as the surface where it reaches a level.
gnuplot
# a 3D scalar field on a voxel grid: filled around a helix, then the surface where it reaches a level
set terminal svg size 600,420
set output 'pd06.svg'
set vgrid $helix size 25
set vxrange [-2:2]; set vyrange [-2:2]; set vzrange [0:11]
set xrange [-2:2]; set yrange [-2:2]; set zrange [0:11]
vfill sample [t=0:20] '+' using (cos($1)):(sin($1)):($1):(0.9):(10.0)
set view 60, 30
set xyplane at 0
set style fill transparent solid 0.35
set pm3d depthorder border lc 'black' lw 0.3
set key off
splot $helix with isosurface level 1.0 lc 'sea-green'Why it works
set vgrid $helix size 25makes a grid of 25 x 25 x 25 voxels overvxrange,vyrange,vzrange, all zero.vfilladds to the voxels around each point of its data: here 200 points along a helix (the sampled pseudo-file'+'), each filling a sphere of radius 0.9 with the value 10.with isosurface level 1.0draws the surface where the field crosses 1, marching cubes with gnuplot 6.0's tables, as polygons sorted by depth; the transparent fill shows the inside.
Try this
splot $helix with points pt 7 ps 0.3 above 1.0: the voxels themselves, those above the level.voxel(x, y, z) = ...in an expression reads the grid: plot a slice withsplot [-2:2][-2:2] voxel(x, y, 5).- A field from a simulation: write it as
x y z valuelines and fill the grid withvfill 'field3d.dat' using 1:2:3:(0.0):4.
Pitfalls
- The grid's resolution is the surface's: 25 per side is coarse, 100 per side is a million voxels to fill and scan.
vfilladds, it does not set: run it twice and the values double.
Reference: voxel grids. Next: D7. Turning views.