水曜日, 10月 23, 2013

振り子 : oscillation



先日からのスクリプトを,追加修正.

#!/bin/bash

echo "createOscillation.sh"

##################################################
nDiv=50
OutputAnimFile="./output.gif"
TmpFilePrefix="./tmp"
Xmin="-1.25"
Xmax="1.25"
Ymin="-1.25"
Ymax=" 1.25"

grav=9.81
length=10.0
angle=45.0
initTime=0.0
termTime=30.0

##################################################
pi=`echo "scale=8; 4.0*a(1.0)" | bc -l`
dstime=`echo "scale=8; (${termTime}-${initTime})/${nDiv}" | bc -l`

period=`echo "scale=8; 2.0*${pi}*sqrt(${length}/${grav})" | bc -l`
angleRad=`echo "scale=8; (${pi}/180.0)*${angle}" | bc -l`

echo "  nDiv : "${nDiv}
echo "    pi : "${pi}
echo "dtheta : "${dtheta}
echo "period : "${period}


##################################################
rm -f ${TmpFilePrefix}
stime=0.0
for i in `seq -w 1 ${nDiv}` ; do
    theta=`echo "scale=8; ${angleRad}*s((2.0*${pi}/${period})*${stime})" | bc -l`#    theta=`echo "scale=8; ${angleRad}*((2.0*${pi}/${period})*${stime})" | bc -l`

    X=`echo "scale=8; c(${theta}-0.5*${pi})" | bc -l`
    Y=`echo "scale=8; s(${theta}-0.5*${pi})" | bc -l`

    timelabel=`echo time=${stime}`


    check=`echo "scale=8; ${theta}*(180.0/${pi})" | bc -l`
    echo "stime : "${stime}" theta : "${theta}" check: "${check}

    echo 0.0 0.0 ${X} ${Y} > ${TmpFilePrefix}.tmp

    gnuplot << EOF
    set out "${TmpFilePrefix}${i}.gif"
    set size square
    set xrange [$Xmin:$Xmax]
    set yrange [$Ymin:$Ymax]
    set label 1 at screen 0.25    ,0.15 "${timelabel}"
    set term gif
    set grid
    set pointsize 4
    plot "${TmpFilePrefix}.tmp" w vector pointtype 7 title "" , \
         "${TmpFilePrefix}.tmp" using 3:4 w points pointtype 7 title ""
EOF

    stime=`echo "scale=8; ${stime} + ${dstime}" | bc -l`

done


##################################################
convert -delay 10 -loop 0 ./${TmpFilePrefix}*.gif  ${OutputAnimFile}



図: 開き角 45 度



わかりにくいが,振り子は等速運動してないことに注意
(高度が高いほどゆっくり,最下部で,速い).




          図:開き角 80 度


同じ周期(振り子の等時性).



0 件のコメント:

コメントを投稿