Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import *
- import math
- Pi = math.pi
- g = 1.62 # m/(s^2), Moon
- d_t = 0.1
- def read_commands(name):
- com = []
- int_arr = []
- for line in open(name, 'r'):
- com.append(line.split(" "))
- for line in com:
- int_line = []
- for word in line:
- to_int_word = ""
- for c in word:
- if c.isdigit() or c == '.':
- to_int_word += c
- if to_int_word != "":
- int_line.append(float(to_int_word))
- int_arr.append(int_line)
- return int_arr
- class Shuttle:
- M = 2150 # kg, mass of shuttle + mass of pilot
- m = 1000 # kg, mass of fuel
- a_limit = 29.43 # m/(s^2), 3g
- Vp = 3660 # m/s, speed of fuel
- lim_vx = 1
- lim_vy = 3
- def __init__(self, angle, delta_m, time): # angle (degrees), fuel_consumption (kg / s), time (s)
- self.delta_m = delta_m # расход топлива
- self.angle = angle # начальный угол наклона (к оси OX) в радианах
- self.time = time # время, котоое нужно лететь в каком-то направлении
- self.fuel = self.m # чо по топливу
- self.V = 0 # Общая скорость
- self.y = 0 # актуальная y-координата
- self.x = 0 # актуальная x - координата
- self.all_time = 0 # время прошедшее с начала полёта (можно выпилить, но еды не просит)
- self.Vx = 0 # Компоненты скорости
- self.Vy = 0
- self.Ax = 0 # компоненты ускорения
- self.Ay = 0
- self.A = 0 # само ускорение
- def update_time(self, time): # обновим скорость
- self.time = time
- def update_angle(self, angle): # обновим угол
- self.angle = angle
- def update_delta_m(self, delta_m): # обновим скорость
- self.delta_m = delta_m
- def update_all(self, angle, delta_m, time): # обновим всё
- self.update_time(time)
- self.update_angle(angle)
- self.update_delta_m(delta_m)
- self.recount_parameters() # надо пересчитать всё
- def update_speed(self):
- self.V = self.get_speed() # надо обновить отдельно и компоненты скорости
- def update_high(self):
- self.y = self.get_coordinate_y() # обновим высоту (нахуя?)
- def update_a(self): # обновим общее ускорение
- self.A = self.get_accelerate()
- def recount_parameters(self): # обновим все данные спутника
- # self.fuel -= (self.d_t * self.delta_m)
- # self.y = self.get_coordinate_y()
- # self.x = self.get_coordinate_x()
- # self.V = self.get_speed()
- # self.Vx = self.get_horizontal_speed()
- # self.Vy = self.get_vertical_speed()
- # self.Ax = self.get_horizontal_accelerate()
- # self.Ay = self.get_vertical_accelerate()
- # self.all_time += self.time
- self.Ax = self.get_horizontal_accelerate()
- self.Ay = self.get_vertical_accelerate()
- self.Vx = self.get_horizontal_speed()
- self.Vy = self.get_vertical_speed()
- self.x = self.get_coordinate_x()
- self.y = self.get_coordinate_y()
- self.fuel -= delta_m * self.time
- self.all_time += self.time
- self.V = self.get_speed()
- self.A = self.get_accelerate()
- def get_coordinate_x(self):
- x = self.x + self.Vx * self.time + self.Ax * self.time / 2
- return x
- def get_coordinate_y(self):
- y = self.y + self.Vy * self.time + self.Ay * self.time / 2
- return y
- def check_g(self):
- pass
- def check_fuel(self):
- if self.time * self.delta_m <= self.fuel:
- return True
- return False
- def check_coordinate(self):
- if self.y >= 0:
- return True
- return False
- def time_crash(self):
- pass
- def low_fuel_time(self):
- pass
- def is_soft_landing(self):
- output_file.write(str(round(self.Vx)) + '\t\t' + str(round(self.Vy)) + '\t\t' + str(round(self.x)) +
- '\t\t' + str(round(self.y)) + '\n')
- if abs(self.Vx) > self.lim_vx or abs(self.Vy) > self.lim_vy:
- output_file.write("Landing failed!")
- else:
- output_file.write("Landing succeeded!")
- output_file.close()
- def get_vertical_accelerate(self):
- # a = Vp * sin(self.angle) * (1 / self.get_ksi()) * (-self.delta_m) - g
- a = (math.sin(math.pi * self.angle / 180) * self.delta_m * self.Vp) / (self.M + self.fuel) - g
- return a
- def get_horizontal_accelerate(self):
- # a = Vp * cos(self.angle) * (1 / self.get_ksi()) * (-self.delta_m)
- a = (math.cos(math.pi * self.angle / 180) * self.delta_m * self.Vp) / (self.M + self.fuel)
- return a
- def get_accelerate(self):
- Ax = self.get_horizontal_accelerate()
- Ay = self.get_vertical_accelerate()
- return sqrt(Ax * Ax + Ay * Ay)
- def get_vertical_speed(self):
- # Vy = Vp * sin(self.angle) * log(self.get_ksi()) - g * self.time
- Vy = self.Vy + self.Ay * self.time
- return Vy
- def get_horizontal_speed(self):
- # Vx = Vp * cos(self.angle) * log(self.get_ksi())
- Vx = self.Vx + self.Ax * self.time
- return Vx
- def get_speed(self):
- Vx = self.get_horizontal_speed()
- Vy = self.get_vertical_speed()
- return sqrt(Vx * Vx + Vy * Vy)
- def step(self, angle, f_consumption, m_time):
- for i in range(int(m_time / d_t)):
- self.update_all(angle, f_consumption, d_t)
- self.end()
- tau = m_time - int(m_time / d_t) * d_t
- self.update_all(angle, f_consumption, tau)
- output_file.write(str(round(self.Vx)) + '\t\t' + str(round(self.Vy)) + '\t\t' + str(round(self.x)) + '\t\t'
- + str(round(self.y)) + '\n')
- def fall(self):
- self.angle = 180 * math.atan2(self.Vy, self.Vx) / math.pi
- output_file.write("FALL: ")
- while self.y > 0:
- self.update_all(self.angle, 0, d_t)
- self.end()
- def end(self):
- if not space_shuttle.check_coordinate():
- self.y = 0
- space_shuttle.is_soft_landing()
- exit(0)
- input_file_name = input("Enter file name: ")
- output_file_name = input("Enter output file name: ")
- output_file = open(output_file_name, 'w')
- space_shuttle = Shuttle(90, 0,
- 0) # инициализируем параметры аппарата на стартовой площадке (возможно есть смысл изменить угол к нормали)
- task = input(
- "Enter execution scenario, where \"1\" - flight simulation, \"2\" - calculation of the maximum flight distance: ")
- if task == "1":
- commands = read_commands(input_file_name)
- for instruction in commands:
- angle = instruction[0]
- delta_m = instruction[1]
- time = instruction[2]
- # f_consumption = delta_m / time
- space_shuttle.step(angle, delta_m, time)
- space_shuttle.end()
- space_shuttle.fall()
- elif task == "2":
- pass
- else:
- output_file.write("Unexpected scenario")
- output_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement