파일:Inclinedthrow2.gif

testwiki
둘러보기로 이동 검색으로 이동
    원본 파일 (400 × 288 픽셀, 파일 크기: 378 KB, MIME 종류: image/gif, 반복됨, 102 프레임, 10초)

    이 파일은 위키미디어 공용에 있으며, 다른 프로젝트에서 사용하고 있을 가능성이 있습니다. 해당 파일에 대한 설명이 아래에 나와 있습니다.

    파일 설명

    설명
    English: Animations of an inclined throw with no drag (black), Stokes drag (blue) and Newton drag (green). Launch angle: 70°, g=1, v0=1.25, terminal velocity for both drag types: vmax=0.65.
    날짜
    출처 자작
    저자 Geek3
    다른 버전 Inclinedthrow.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 = 'inclinedthrow2'
    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 = 0.65
    # 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],
            'o', 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],
            'o', 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],
            'o', 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:ko:크리에이티브 커먼즈
    저작자표시 동일조건변경허락
    이용자는 다음의 권리를 갖습니다:
    • 공유 및 이용 – 저작물의 복제, 배포, 전시, 공연 및 공중송신
    • 개작 – 저작물의 개작, 수정, 2차적저작물 창작
    다음과 같은 조건을 따라야 합니다:
    • 저작자표시 – 적절한 저작자 표시를 제공하고, 라이선스에 대한 링크를 제공하고, 변경사항이 있는지를 표시해야 합니다. 당신은 합리적인 방식으로 표시할 수 있지만, 어떤 방식으로든 사용권 허가자가 당신 또는 당신의 사용을 지지하는 방식으로 표시할 수 없습니다.
    • 동일조건변경허락 – 만약 당신이 이 저작물을 개작 또는 변형하거나 이 저작물을 기반으로 제작하는 경우, 당신은 당신의 기여물을 원저작물과 동일하거나 호환 가능한 라이선스에 따라 배포하여야 합니다.

    설명

    이 파일이 나타내는 바에 대한 한 줄 설명을 추가합니다

    파일 역사

    날짜/시간 링크를 클릭하면 해당 시간의 파일을 볼 수 있습니다.

    날짜/시간섬네일크기사용자설명
    현재2020년 10월 21일 (수) 17:282020년 10월 21일 (수) 17:28 판의 섬네일400 × 288 (378 KB)wikimediacommons>Geek3Uploaded own work with UploadWizard

    이 파일을 사용하는 문서가 없습니다.