  # Untitled unknown
python
a month ago
3.5 kB
4
Indexable
Never
```# Built-In Imports:
import math

class Projectile:
"""
This class is responsible for defining a projectile within the system. It will calculate its position and display it on the screen.
This is the general constructor for the projectile class. It sets the initial values for the angle of projection, initial velocity,
initial height, diameter of the projectile, the value for the acceleration due to gravity and the drag coefficient.
"""

def __init__(self, angle_degrees=30, init_velocity=10, init_height=0, diameter=0.1, grav_acceleration=9.81,
drag_coefficient=0):
"""
This is the general constructor for the projectile class. It sets the initial values for the angle of projection, initial velocity,
initial height, diameter of the projectile, the value for the acceleration due to gravity and the drag coefficient.

:param angle_degrees: The initial value for the angle of projection
:param init_velocity: The initial value for the velocity of the projectile.
:param init_height: The initial value for the height of the projectile.
:param diameter: The initial value for the diameter of the projectile.
:param grav_acceleration: The initial value for the acceleration due to gravity.
:param drag_coefficient: The initial value for the drag coefficient.
"""

self.angle_degrees = angle_degrees
self.init_velocity = init_velocity
self.init_height = init_height
self.diameter = diameter
self.grav_acceleration = grav_acceleration
self.drag_coefficient = drag_coefficient

self.max_time = self.get_max_time(init_velocity, init_height, grav_acceleration)

# noinspection PyMethodMayBeStatic
"""
Converts the user inputted angle into radians, so you can utilise the values in various other calculations.

:param angle_degrees: The initial value for the angle of projection
:return: The value of the initial angle converted to radians. (Float)
"""

def get_y_velocity(self, velocity):
"""
Calculates vertical component of the user-inputted value for velocity, so you can compute SUVAT equations in the y-dimension.

:param velocity: The velocity of the projectile.
:return: The value of the vertical component of velocity. (Float)
:return:
"""

def get_x_velocity(self, velocity):
""" The returned argument is the horizontal velocity component of the initial velocity """

def get_max_time(self, velocity, height, grav_acceleration):
parabola_time = 2 * (self.get_y_velocity(velocity) / grav_acceleration)

if height == 0:
return parabola_time

vertical_velocity = self.get_y_velocity(velocity)  # The vertical component of the initial velocity
max_time = parabola_time + (-vertical_velocity + math.sqrt(vertical_velocity ** 2 + 2 * grav_acceleration * height)) / grav_acceleration

return max_time

def get_position(self, time=0):
pass

if __name__ == "__main__":

blobby = Projectile(30, 10, 40)
print(blobby.max_time)```  