Guest User

Ship Thruster Calculator

a guest
Sep 5th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. from math import ceil
  2.  
  3. ##############
  4. # User Input #
  5. ##############
  6. # Mass
  7. mass_ship = 5000 #kg of the ship frame (+ estimated adjustor/retro-rocket/fuel mass)
  8. mass_rated = 5000 #kg of desired max cargo mass
  9. mass = mass_ship + mass_rated
  10.  
  11. # Properties for type A thrusters (hover/atmo/space)
  12. # Example: you could plug in the values for a large atmospheric engine here. Try requesting 3g of acceleration.
  13. typeA_name = "Atmo"
  14. accel_typeA = 3*9.8 #m/s2
  15. mass_per_typeA = 100 #kg
  16. force_per_typeA = 20000 #N
  17.  
  18. # Properties for type B thrusters (hover/atmo/space)
  19. # Example: you could plug in the values for a large space engine here. Try requesting 3g of acceleration.
  20. typeB_name = "Space"
  21. accel_typeB = 3*9.8 #m/s2
  22. mass_per_typeB = 300 #kg
  23. force_per_typeB = 60000 #N
  24.  
  25. ################
  26. # Calculations #
  27. ################
  28. # F = ma
  29. # T = Num of Thrusters Needed
  30. # m = m + T*Tm
  31. # TF = ma
  32. # T = (m*a) / (F - a*Tm)
  33. num_typeA = ceil((mass * accel_typeA) / (force_per_typeA - accel_typeA * mass_per_typeA))
  34. num_typeB = ceil((mass * accel_typeB) / (force_per_typeB - accel_typeB * mass_per_typeB))
  35. print("Solutions, not including the weight of the other solution's thrusters:")
  36. print("Num {0} Thrusters = {1}".format(typeA_name, num_typeA))
  37. print("Num {0} Thrusters = {1}".format(typeB_name, num_typeB))
  38.        
  39. for i in range(100):
  40.     imass = mass + (num_typeA * mass_per_typeA) + (num_typeB * mass_per_typeB)
  41.     inum_typeA = ceil((imass * accel_typeA) / (force_per_typeA - accel_typeA * mass_per_typeA))
  42.     inum_typeB = ceil((imass * accel_typeB) / (force_per_typeB - accel_typeB * mass_per_typeB))
  43.    
  44.     if (inum_typeA == num_typeA and inum_typeB == num_typeB):
  45.         print()
  46.         print("Solutions, with the weight of each other's thrusters accounted for:")
  47.         print("Num {0} Thrusters = {1}".format(typeA_name, num_typeA))
  48.         print("Num {0} Thrusters = {1}".format(typeB_name, num_typeB))
  49.         exit()
  50.     elif (inum_typeA < 0 or inum_typeB < 0):
  51.         break;
  52.     else:
  53.         num_typeA = inum_typeA
  54.         num_typeB = inum_typeB
  55.         print()
  56.         print("Converging i={}:".format(i))
  57.         print("Num {0} Thrusters = {1}".format(typeA_name, num_typeA))
  58.         print("Num {0} Thrusters = {1}".format(typeB_name, num_typeB))
  59.  
  60. print()
  61. print("There is no amount of thrusters that can give you those acceleration values")
  62. exit()
Advertisement
Add Comment
Please, Sign In to add comment