0% found this document useful (0 votes)
9 views3 pages

Code 3 Generate Data For Co

Uploaded by

ashadevi130585
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Code 3 Generate Data For Co

Uploaded by

ashadevi130585
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Code 3 Generate data for co-ordinate of a projectile and plot the trajectory determine the range

maximum height and time of flight for a projectile motion

import numpy as np

import matplotlib.pyplot as plt

# Function to calculate projectile motion

def projectile_motion(initial_velocity, launch_angle, gravity=9.81, time_step=0.01):

# Convert launch angle to radians

launch_angle_rad = np.radians(launch_angle)

# Initial velocity components

v_x = initial_velocity * np.cos(launch_angle_rad)

v_y = initial_velocity * np.sin(launch_angle_rad)

# Time of flight: when the projectile hits the ground

time_of_flight = (2 * v_y) / gravity

# Maximum height: achieved when vertical velocity is zero

max_height = (v_y**2) / (2 * gravity)

# Range: Horizontal distance traveled when projectile hits the ground

range_of_projectile = v_x * time_of_flight

# Create a time array from 0 to the time of flight

t = np.arange(0, time_of_flight, time_step)

# Position equations for x and y

x = v_x * t # Horizontal displacement

y = v_y * t - 0.5 * gravity * t**2 # Vertical displacement

return t, x, y, range_of_projectile, max_height, time_of_flight


# Parameters for the simulation

initial_velocity = 30 # m/s (Initial velocity)

launch_angle = 45 # degrees (Launch angle)

# Call the function to calculate the projectile motion data

t, x, y, range_of_projectile, max_height, time_of_flight = projectile_motion(initial_velocity,


launch_angle)

# Output the results

print(f"Range of the projectile: {range_of_projectile:.2f} meters")

print(f"Maximum height: {max_height:.2f} meters")

print(f"Time of flight: {time_of_flight:.2f} seconds")

# Plot the trajectory

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

plt.plot(x, y, label=f'Launch angle: {launch_angle}°')

plt.title('Projectile Motion Trajectory')

plt.xlabel('Horizontal Distance (m)')

plt.ylabel('Vertical Distance (m)')

plt.axhline(0, color='black',linewidth=0.5) # Ground line

plt.axvline(range_of_projectile, color='r', linestyle='--', label=f'Range = {range_of_projectile:.2f} m')

plt.scatter(range_of_projectile, 0, color='red', zorder=5) # Mark the landing point

plt.grid(True)

plt.legend()

plt.show()
Range of the projectile: 91.74 meters
Maximum height: 22.94 meters
Time of flight: 4.32 seconds

You might also like