Understanding Projectile Motion: A Mathematical and Computational Perspective

Understanding Projectile Motion: A Mathematical and Computational Perspective

In the realm of physics, projectile motion describes the motion of an object projected into the air, moving under the influence of gravity. This fundamental concept finds application in various fields, from physics and engineering to sports and ballistics. In this blog post, we will delve into the logic and mathematics behind projectile motion, exploring how we can simulate and visualize it using Python.

Projectile Motion Graph

The Basics of Projectile Motion

Projectile motion can be broken down into two independent components: horizontal motion and vertical motion. The horizontal motion is characterized by a constant velocity, as there is no horizontal acceleration (neglecting air resistance). On the other hand, the vertical motion is influenced by gravity, causing the object to accelerate downward at a rate of 9.81 m/s² (assuming Earth's gravity).

The Mathematical Formulation

To mathematically describe projectile motion, we can use the following equations:

Horizontal Motion:

`x(t) = v_{x}.t`

where  x(t) is the horizontal position of the object at time t, and `v_{x}` is the horizontal component of the initial velocity.

Vertical Motion:

`y(t) = v(y).t - \frac{1}{2}.g.t ^{2}`

where  y(t) is the vertical position of the object at time t and `v_{y}` is the vertical component of the initial velocity, and  g is the acceleration due to gravity.



Simulating Projectile Motion in Python

Now, let's simulate projectile motion using Python. We will define a function that calculates the trajectory of a projectile given its initial velocity and launch angle. We will then use matplotlib to visualize the trajectory.

Code Link :

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.animation import FuncAnimation

from ipywidgets import interact, widgets


def projectile_motion(v, angle):

    # Constants

    g = 9.81  # Acceleration due to gravity (m/s^2)

    dt = 0.01  # Time step (s)


    # Initial conditions

    vx = v * np.cos(np.radians(angle))  # Initial x velocity

    vy = v * np.sin(np.radians(angle))  # Initial y velocity

    x = 0  # Initial x position

    y = 0  # Initial y position


    # Arrays to store the trajectory

    x_data = [x]

    y_data = [y]


    # Simulation loop

    while y >= 0:

        # Update x and y positions

        x += vx * dt

        y += vy * dt - 0.5 * g * dt**2


        # Update y velocity

        vy -= g * dt


        # Store the new position

        x_data.append(x)

        y_data.append(y)


    return x_data, y_data


@interact(v=widgets.FloatSlider(min=0, max=100, step=1, value=10, description='Velocity (m/s):'),

          angle=widgets.FloatSlider(min=0, max=90, step=1, value=45, description='Angle (degrees):'))

def update(v, angle):

    # Calculate projectile motion

    x_data, y_data = projectile_motion(v, angle)


    # Plot the trajectory

    plt.figure(figsize=(10, 6))

    num_points = 1000  # Limit the number of points plotted in each frame

    step = max(len(x_data) // num_points, 1)  # Ensure step is at least 1

    plt.plot(x_data[::step], y_data[::step])

    plt.title('Projectile Motion')

    plt.xlabel('Distance (m)')

    plt.ylabel('Height (m)')

    plt.axis('equal')

    plt.grid(True)

    plt.show()


Post a Comment

0 Comments