daily pastebin goal
85%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2.  
  3. # object
  4. A    = .8               # surface area m^2
  5. C    = 1.4              # drag coefficient
  6. m_prop = 65 # mass of object in kg
  7.  
  8. m = 90                  # number of angles
  9. n = 1000                # number of time steps to simulate
  10. rho = 1.225             # kg/m^3
  11. g = -9.8                # m/s^2
  12. start = 0.0             # seconds
  13. end = 10                # seconds
  14. initial_velocity = 1500 * ((m_prop / 65) ** .45)  # meters/second
  15. initial_height = 5
  16.  
  17.  
  18. # parameters of simulation
  19. angles = np.linspace( 1,m,m )
  20. radians = np.radians( angles )
  21.  
  22. #initalize variables
  23. t  = np.linspace( start,end,n+1 )
  24. vx = np.zeros( ( m,n+1 ) )
  25. vy = np.zeros( ( m,n+1 ) )
  26. x  = np.zeros( ( m,n+1 ) )
  27. y  = np.zeros( ( m,n+1 ) )
  28.  
  29. for i in range(m):
  30.     y[ i,0 ]  = initial_height
  31.     vx[ i,0 ] = initial_velocity * np.cos( radians[ i ] )
  32.     vy[ i,0 ] = initial_velocity * np.sin( radians[ i ] )
  33.  
  34. for i in range( m ):
  35.     for j in range( 1,n+1 ):
  36.         if y[ i,j-1 ] <= 0:
  37.             x[ i,j ]  = x[ i,j-1 ]
  38.             y[ i,j ]  = 0
  39.             vx[ i,j ] = 0
  40.             vy[ i,j ] = 0
  41.         else:
  42.             v  = np.sqrt( vx[ i,j-1 ] ** 2 + vy[ i,j-1 ] ** 2 )
  43.             ax =   - ( 0.5*rho*C*A/m_prop ) * v**2 * ( vx[ i,j-1 ] / v )
  44.             ay = g - ( 0.5*rho*C*A/m_prop ) * v**2 * ( vy[ i,j-1 ] / v )
  45.             # https://www.grc.nasa.gov/www/k-12/airplane/flteqs.html
  46.             dt        = t[ j ] - t[ j-1 ]
  47.             vx[ i,j ] = vx[ i,j-1 ] + ax*dt
  48.             vy[ i,j ] = vy[ i,j-1 ] + ay*dt
  49.             x[ i,j ]  =  x[ i,j-1 ] + vx[ i,j ]*dt
  50.             y[ i,j ]  =  y[ i,j-1 ] + vy[ i,j ]*dt
  51.             if y[ i,j ] <= 0:
  52.                 y[ i,j ]  = 0
  53.                 x[ i,j ]  = x[ i,j-1 ]
  54.                 vy[ i,j ] = 0
  55.                 vx[ i,j ] = 0
  56.  
  57. best_d = 0
  58. best_a = 0
  59. for i in range( m ):
  60.     if x[ i,-1 ] > best_d:
  61.         best_d = x[ i,-1 ]
  62.         best_a = angles[ i ]
  63.  
  64. def dist( angle,m_prop ):
  65.     pass
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top