2

I am trying to plot in a 3d space a curve coming from a file and a sphere made with parametric entries.

The idea is to plot the planet Earth and the orbit of a satellite.

The orbit is defined in a file x y z and gnuplot commands are simply

splot 'file.txt' u 1:2:3 title 'Orbit element 1' with lines

Orbit satellite :

I found a script to plot the Earth

#color definitions
set border lw 1.5
set style line 1 lc rgb '#000000' lt 1 lw 2
set style line 2 lc rgb '#c0c0c0' lt 2 lw 1
unset key; unset border 
set tics scale 0
set lmargin screen 0
set bmargin screen 0 
set rmargin screen 1
set tmargin screen 1 

set format ''
set mapping spherical
set angles degrees

set xyplane at -1
set view 56,81

set parametric

set isosamples 25
set urange[0:360]
set vrange[-90:90]
r = 0.99
splot r*cos(v)*cos(u),r*cos(v)*sin(u),r*sin(v) with lines linestyle 2,'world.dat' with lines linestyle 1
unset parametric

Unfortunately, I am not able to mix splot wiht the data file and the splot with the parametric.

Any suggestions more than welcome! Thanks

dwir182
  • 1,539
  • 10
  • 20

1 Answers1

1

In order to generate the plot below, I used the data linked in this blog post. Now, if we want to combine several data sources into one plot, we will need to convert one or the other into a common system of coordinates. If the satellite data is in Cartesian x,y,z coordinates, perhaps the easiest solution would be to convert the world map into Cartesian system as well.

This could be done as shown below. The parameter R denotes the radius of the sphere on the surface of which Gnuplot draws the world map. It should be slightly larger than r so that hidden3d works. The columns in the world_110m.txt file have the meaning of longitude (first column) and latitude (second column), therefore the conversion is given as (R*cos($1)*cos($2)):(R*sin($1)*cos($2)):(R*sin($2)). In the file input.pnts.dat, I just generated coordinates of points on an ellipse with a=1.6 and b=1.2 rotated around the x axis by 45 degrees (counterclockwise). For real satellite data, one would need to rescale the coordinates by dividing by the radius of Earth, i.e., use ($1/Re):($2/Re):($3/Re) instead of 1:2:3, where Re denotes the radius in whichever units your data is (probably meters, judging by the first plot in your question).

set terminal pngcairo
set output 'fig.png'

set xr [-2:2]
set yr [-2:2]
set zr [-2:2]

#color definitions
set border lw 1.5
set style line 1 lc rgb '#000000' lt 1 lw 2
set style line 2 lc rgb '#c0c0c0' lt 2 lw 1

unset key; unset border; set tics scale 0

set format ''
set angles degrees

set xyplane at -1
set view 56,81

set lmargin screen 0
set bmargin screen 0 
set rmargin screen 1
set tmargin screen 1 

set parametric
set isosamples 25
set urange[0:360]
set vrange[-90:90]
r = 0.99
R = 1.00

set hidden3d

#since we are using Cartesian coordinates, we don't want this
#set mapping spherical

splot \
  r*cos(v)*cos(u),r*cos(v)*sin(u),r*sin(v) with lines linestyle 2, \
  'world_110m.txt' u (R*cos($1)*cos($2)):(R*sin($1)*cos($2)):(R*sin($2)) w l lw 2 lc rgb 'black', \
  'input.pnts.dat' u 1:2:3 w l lw 2 lc rgb 'red'

This then gives: enter image description here

ewcz
  • 12,819
  • 1
  • 25
  • 47