首页 > 解决方案 > 来自文件和参数球体的 gnuplot 曲线

问题描述

我正在尝试在 3d 空间中绘制来自文件的曲线和使用参数条目制成的球体。

这个想法是绘制地球和卫星的轨道。

轨道在文件 xyz 中定义,而 gnuplot 命令很简单

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

轨道卫星:

我找到了一个绘制地球的脚本

#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

不幸的是,我无法将 splot 与数据文件和 splot 与参数混合。

任何建议都非常欢迎!谢谢

标签: gnuplot

解决方案


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


推荐阅读