以下可能是一个起点。由于我没有足够的数据来说明,我生成了一些数据(注意:它不是“真实的”双摆数据)。假设锚点是 a at 0,0
。此外,可能不仅需要绘制点with points
,还需要绘制钟摆的条with vectors
。如何绘制第二个柱有点棘手且不明显,因为您必须记住 mass1 的先前位置。我希望你能弄清楚代码是如何工作的。
代码:
### animate double pendulum
reset session
# create some test data (no "real" double pendulum data, just for illustration)
set print $Data
do for [t=0:15] {
print sprintf("%d. %g %g %g", 1, t, x1=cos(t*pi/20+pi/8), y1=-sin(t*pi/20+pi/8))
print sprintf("%d. %g %g %g", 2, t, x2=x1+cos(t/10.), y2=y1-sin(t/10.))
}
set print
set size ratio -1
set xrange[-1.5:2.0]
set yrange[-2:0.1]
set term gif size 400,300 animate delay 20
set output "DoublePendulum.gif"
do for [i=0:15] {
plot $Data u (0):(0):3:4 every ::2*i::2*i w vectors lc "grey" nohead notitle, \
x2=y2=NaN '' u (x1=x2,x2=$3):(y1=y2,y2=$4):(x1-x2):(int($0)%2==0 ? NaN: y1-y2) every ::2*i::2*i+1 w vectors lc "grey" nohead notitle, \
'' u 3:4 every ::2*i::2*i w p pt 7 ps 3 lc "red" title "1", \
'' u 3:4 every ::2*i+1::2*i+1 w p pt 7 ps 2 lc "blue" title "2", \
}
set output
# just for illustration: plot all positions at the same time
set term wxt # or any other terminal
plot $Data u (0):(0):3:4 every 2 w vectors lc "grey" nohead notitle, \
x2=y2=NaN '' u (x1=x2,x2=$3):(y1=y2,y2=$4):(x1-x2):(int($0)%2==0 ? NaN: y1-y2) w vectors lc "grey" nohead notitle, \
'' u 3:4 every 2 w p pt 7 ps 3 lc "red" title "1", \
'' u 3:4 every 2::1 w p pt 7 ps 2 lc "blue" title "2", \
### end of code
结果:(没有“真实的”双摆数据,仅用于说明)
所有职位(在 wxt 终端中):