#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ENGG1811 lecture 7 Library for simulation """ # import the math library import math # Constants g = 9.81 # %% Functions for simulation by formula # def parachute(t, mass, drag_air, time_deploy, drag_para): if t < time_deploy: speed = freefall(t, mass, drag_air) else: # Compute speed when parachute is deployed speed_at_deployment = freefall(time_deploy, mass, drag_air) # Calculate terminal speed terminal_speed_para = g*mass/drag_para # Speed at time t decay_now = decay(t-time_deploy,mass,drag_para) speed = speed_at_deployment * decay_now + terminal_speed_para * (1 - decay_now) return speed def decay(t,mass,drag): decay_from_drag = math.exp(-drag/mass*t) return decay_from_drag # Calculte the freefall speed def freefall(t, mass, drag_air): # decay = CalcDecay(currentTime,mass,drag_air); # Compute velocity of freefall terminal_speed_air = g * mass / drag_air speed = terminal_speed_air * (1 - decay(t, mass, drag_air)) return speed