ファイル:Inclinedthrow.gif

提供: testwiki
ナビゲーションに移動 検索に移動
    元のファイル (400 × 288 ピクセル、ファイルサイズ: 374キロバイト、MIME タイプ: image/gif、ループします、102 フレーム、10秒)

    このファイルはウィキメディア・コモンズのものであり、他のプロジェクトで使用されている可能性があります。 ウィキメディア・コモンズでのファイル解説ページにある説明を以下に示します。

    概要

    解説
    English: Trajectories of three objects thrown at the same angle (70°). The black object doesn't experience any form of drag and moves along a parabola. The blue object experiences Stokes' drag, and the green object Newton drag.
    日付
    原典 投稿者自身による著作物
    作者 AllenMcC.
    その他のバージョン Inclinedthrow2.gif
    GIF 開発
    InfoField
     この GIF ラスター画像はmatplotlibで作成されました。
    ソースコード
    InfoField

    Python code

    #!/usr/bin/python3
    # -*- coding: utf8 -*-
    
    import os
    import inspect
    from math import *
    import numpy as np
    from scipy.integrate import odeint
    from scipy.optimize import newton
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    from matplotlib import animation
    
    # settings
    mpl.rcParams['path.snap'] = False
    fname = 'inclinedthrow'
    size = 400, 288
    l, w, b, h = 22.5/size[0], 1-23/size[0], 22.5/size[1], 1-23/size[1]
    nframes = 102
    delay = 8
    lw = 1.
    ms = 6
    c1, c2, c3 = "#000000", "#0000ff", "#007100"
    
    def projectile_motion(g, mu, pot, xy0, vxy0, tt):
        # use a four-dimensional vector function vec = [x, y, vx, vy]
        def dif(vec, t):
            # time derivative of the whole vector vec
            v = hypot(vec[2], vec[3])
            vxrel, vyrel = vec[2] / v, vec[3] / v
            return [vec[2], vec[3], -mu * v**pot * vxrel, -g - mu * v**pot * vyrel]
    
        # solve the differential equation numerically
        vec = odeint(dif, [xy0[0], xy0[1], vxy0[0], vxy0[1]], tt)
        return vec[:, 0], vec[:, 1], vec[:, 2], vec[:, 3]  # return x, y, vx, vy
    
    g = 1.
    theta  = radians(70)
    v0 = sqrt(g/sin(2*theta))
    vinf = 2.1
    # use identical terminal velocity vinf for both types of friction
    mu_stokes = g / vinf**1
    mu_newton = g / vinf**2
    x0, y0 = 0.0, 0.0
    vx0, vy0 = v0 * cos(theta), v0 * sin(theta)
    
    T = newton(lambda t: projectile_motion(g, 0, 0, (x0, y0), (vx0, vy0), [0, t])[1][1], 2*vy0/g)
    nsub = 10
    tt = np.linspace(0, T * nframes / (nframes - 1), (nframes - 1) * nsub + 1)
    
    traj_free = projectile_motion(g, 0, 0, (x0, y0), (vx0, vy0), tt)
    traj_stokes = projectile_motion(g, mu_stokes, 1, (x0, y0), (vx0, vy0), tt)
    traj_newton = projectile_motion(g, mu_newton, 2, (x0, y0), (vx0, vy0), tt)
    
    def animate(nframe, saveframes=False):
        print(nframe, '/', nframes)
        t = T * float(nframe) / nframes
        
        plt.clf()
        fig.gca().set_position((l, b, w, h))
        fig.gca().set_aspect("equal")
        plt.xlim(0, 1)
        plt.ylim(0, (h*size[1]) / (w*size[0]))
        plt.xticks([]), plt.yticks([])
        plt.xlabel('Distance', size=12)
        plt.ylabel('Height', size=12)
        
        plt.plot(traj_free[0][:nframe*nsub+1], traj_free[1][:nframe*nsub+1],
            '-', lw=lw, color=c1)
        plt.plot(traj_free[0][nframe*nsub], traj_free[1][nframe*nsub],
            'ok', color=c1, markersize=ms, markeredgewidth=0)
        
        plt.plot(traj_stokes[0][:nframe*nsub+1], traj_stokes[1][:nframe*nsub+1],
            '-', lw=lw, color=c2)
        plt.plot(traj_stokes[0][nframe*nsub], traj_stokes[1][nframe*nsub],
            'ok', color=c2, markersize=ms, markeredgewidth=0)
        
        plt.plot(traj_newton[0][:nframe*nsub+1], traj_newton[1][:nframe*nsub+1],
            '-', lw=lw, color=c3)
        plt.plot(traj_newton[0][nframe*nsub], traj_newton[1][nframe*nsub],
            'ok', color=c3, markersize=ms, markeredgewidth=0)
        
        if saveframes:
            # export frame
            dig = int(ceil(log10(nframes)))
            fsavename = ('frame{:0' + str(dig) + '}.svg').format(nframe)
            fig.savefig(fsavename)
            with open(fsavename) as f: content = f.read()
            content = content.replace('pt"', 'px"').replace('pt"', 'px"')
            with open(fsavename, 'w') as f: f.write(content)
    
    fig = plt.figure(figsize=(size[0]/72., size[1]/72.))
    
    os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
    for i in range(nframes):
        animate(i, True)
    os.system('convert -loop 0 -delay ' + str(delay) + ' frame*.svg +dither ' + fname + '.gif')
    # keep last frame for two seconds
    os.system('gifsicle -k32 --color-method blend-diversity -b ' + fname + '.gif -d' + str(delay) + ' "#0-' + str(nframes-2) + '" -d200 "#' + str(nframes-1) + '"')
    for i in os.listdir('.'):
        if i.startswith('frame') and i.endswith('.svg'):
            os.remove(i)
    

    ライセンス

    この作品の著作権者である私は、この作品を以下のライセンスで提供します。
    w:ja:クリエイティブ・コモンズ
    表示 継承
    このファイルはクリエイティブ・コモンズ 表示-継承 3.0 非移植ライセンスのもとに利用を許諾されています。
    あなたは以下の条件に従う場合に限り、自由に
    • 共有 – 本作品を複製、頒布、展示、実演できます。
    • 再構成 – 二次的著作物を作成できます。
    あなたの従うべき条件は以下の通りです。
    • 表示 – あなたは適切なクレジットを表示し、ライセンスへのリンクを提供し、変更があったらその旨を示さなければなりません。これらは合理的であればどのような方法で行っても構いませんが、許諾者があなたやあなたの利用行為を支持していると示唆するような方法は除きます。
    • 継承 – もしあなたがこの作品をリミックスしたり、改変したり、加工した場合には、あなたはあなたの貢献部分を元の作品とこれと同一または互換性があるライセンスの下に頒布しなければなりません。

    キャプション

    このファイルの内容を1行で記述してください

    このファイルに描写されている項目

    題材

    15 12 2008

    383,363 バイト

    288 ピクセル

    400 ピクセル

    5a4bb20018d8728f19730ee2fba40a20fee4f7b5

    ファイルの履歴

    過去の版のファイルを表示するには、その版の日時をクリックしてください。

    日時サムネイル寸法利用者コメント
    現在の版2020年10月21日 (水) 17:102020年10月21日 (水) 17:10時点における版のサムネイル400 × 288 (374キロバイト)wikimediacommons>Geek3adjusted friction coefficients such to make terminal velocity of both trajectories equal. In this case, the Newton projectile moves further.

    このファイルを使用しているページはありません。