1
votes

I`m trying to draw a sphere with X, Y, Z, R given in file with the help of gnuplot.

sphere1.dat:

# X     Y      Z       R
219.3  342.5  3153.2  213.08

In most examples spheres are drawn this way:

set parametric
set angle degree
set urange [0:360]
set vrange [-90:90]
set isosample 72,36
splot cos(u)*cos(v),sin(u)*cos(v),sin(v)

Is there any way to combine u,v values with ones from file? Something like that:

set angle degree
set urange [0:360]
set vrange [-90:90]
set isosample 72,36
splot 'sphere1.dat' using ($4*cos(u)*cos(v)+$1):($4*sin(u)*cos(v)+$2):($4*sin(v)+$3) title "Sphere1"
1

1 Answers

1
votes

You can get x,y,z,r from your datafile using tail and awk.

tail -1 data

prints last line of data

awk '{print $i}'

returns i'th space-separated part of line

x = "`tail -1 sphere1.dat| awk '{print $1}'`"
y = "`tail -1 sphere1.dat| awk '{print $2}'`"
z = "`tail -1 sphere1.dat| awk '{print $3}'`"
r = "`tail -1 sphere1.dat| awk '{print $4}'`"

set parametric
set angle degree
set urange [0:360]
set vrange [-90:90]
set isosample 30,30
splot r*cos(u)*cos(v)+x,r*sin(u)*cos(v)+y,r*sin(v)+z