[python] 수식의 가시화 - 포물선(발사체) 운동

 파이썬을 활용하여 포물선(발사체) 운동을 그래프로 표현해 보겠습니다.


초기 속도와 지면과의 각도가 주어지면 아래 공식들을 활용하여 시간에 따른 X, Y 좌표를 구할 수 있습니다. 공식에 대한 자세한 설명은 포물선 운동(Projectile Motion)에 관하여 찾아보시길 바랍니다.


위 수식들을 활용하여 포물선 운동하는 물체의 좌표를 구하는 함수를 정의하고 초기 속도 변화에 따른 포물선 궤적을 가시화해 보겠습니다. 아래는 샘플 코드입니다.


'''
포물선 운동 그래프 생성
'''

from matplotlib import pyplot as plt
import math

def draw_graph(x, y):
    plt.plot(x, y)
    plt.xlabel('x-coordinate')
    plt.ylabel('y-coordinate')
    plt.title('Projectile motion of a ball')

# floating point range
def frange(start, final, increment):
    numbers = []
    while start < final:
        numbers.append(start)
        start = start + increment

    return numbers

def draw_trajectory(u, theta):
    theta = math.radians(theta)
    g = 9.8

    # 체공시간 (Time of flight)
    t_flight = 2 * u * math.sin(theta) / g

    # 시간 인터벌 생성
    intervals = frange(0, t_flight, 0.001)

    # X, Y 좌표 저장
    x = []
    y = []
    for t in intervals:
        x.append(u * math.cos(theta) * t)
        y.append(u * math.sin(theta) * t - 0.5 * g * t * t)

    draw_graph(x, y)

if __name__ == '__main__':
    u_list = [20, 40, 60]
    theta = 45
    for u in u_list:
        draw_trajectory(u, theta)

    plt.legend(['20', '40', '60'])
    plt.show()

아래는 실행결과입니다.


끝.


댓글

이 블로그의 인기 게시물

공압 속도 제어: 미터인 vs 미터아웃

전력(kW) 계산하기 (직류, 교류 단상, 교류 삼상)

[PLC] AWG => SQ 단위 변환

[투자] ETF 투자 가이드 : 카테고리별 ETF 선택 전략

[아두이노] 가변저항(Potential Divider)과 전압분배(Voltage Divider)

[전기실무] 부하 특성 데이터와 KEC 차단기 선정 가이드

[산업자동화] 머신비전 - 프레임 그래버란?

[PLC] 릴레이와 전자 접촉기 (MC)

[수학] 유클리드 기하학, 비-유클리드 기하학, 형식주의란?

Industrial Control with Relay: 파워릴레이와 범용릴레이