mail@pastecode.io avatar
20 days ago
3.1 kB
# 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.
        :param angle_degrees: The initial value for the angle of projection.
        :param init_velocity: The initial value for the velocity.
        :param diameter: The value for the diameter of the projectile.
        :param grav_acceleration: The value for acceleration due to gravity,
        :param drag_coefficient: The value for the drag coefficient.

    def degrees_to_radians(angle_degrees):
        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)
        return math.radians(angle_degrees)

    def get_vely(init_velocity):
        '''  def __init__(self, angle_degrees = 30, init_velocity = 10, init_height = 0, diameter = 0.1, grav_acceleration = 9.81, drag_coefficient = 0):

            Calculates vertical component of the user-inptted value for velocity, so you can compute SUVAT equations in the y-dimension.
            :param init_velocity: The initial value for the velocity of the projectile.
            :return: The value of tghe vertical component of velocity. (Float)
        return init_velocity * math.sin(self.angle_radians)

    def get_velx(init_velocity):
        ''' The returned argument is the horizontal velocity component of the initial velocity '''
        return init_velocity * math.cos(self.angle_radians)

    def get_max_time(init_velocity, height, grav_acceleration):

        :param height:
        :param grav_acceleration:

        parabola_time = 2 * (get_vely(self.init_velocity) / grav_acceleration)

        if init_height == 0:
            max_time = parabola_time

            max_time = parabola_time + (-get_vely(self.init_velocity) + math.sqrt(
                get_vely(self.init_velocity) ** 2 + 2 * grav_acceleration * init_height)) / grav_acceleration

        return max_time

    self.angle_degrees = angle_degrees
    self.angle_radians = degrees_to_radians(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 = get_max_time(init_velocity, init_height, grav_acceleration)

    def getPosition(self, time=0):

blobby = Projectile(30, 10, 40)