Advertisement
Guest User

Untitled

a guest
May 27th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. Public Structure State
  2. Dim posX As Single
  3. Dim posY As Single
  4. Dim velX As Single
  5. Dim velY As Single
  6. End Structure
  7.  
  8. Private Structure Derivative
  9. Dim dx As Single ' dx/dt = velocity
  10. Dim dy As Single
  11. Dim dvx As Single ' dv/dt = acceleration
  12. Dim dvy As Single
  13. End Structure
  14.  
  15. Private Function evaluate(ByVal initial As State, ByVal t As Single, ByVal dt As Single, ByVal d As Derivative) As Derivative
  16. Dim state As New State()
  17. state.posX = initial.posX + d.dx * dt
  18. state.posY = initial.posY + d.dy * dt
  19. state.velX = initial.velX + d.dvx * dt
  20. state.velY = initial.velY + d.dvy * dt
  21.  
  22. Dim output As New Derivative()
  23. output.dx = state.velX
  24. output.dy = state.velY
  25. output.dvy = accelerationY(state, t + dt)
  26. output.dvx = accelerationX(state, t + dt)
  27. Return output
  28. End Function
  29.  
  30. Private Function accelerationX(ByVal state As State, ByVal t As Single) As Single
  31. Dim k As Single = 0 'Ball.Force.Net.X '
  32. Const b As Single = 1
  33. Return (k * state.posX) - b * (state.velX)
  34. End Function
  35.  
  36. Private Function accelerationY(ByVal state As State, ByVal t As Single) As Single
  37. Dim k As Single = Calculate_Gravitational_Force(Ball.Mass, EARTH_GRAVITY) '- Calculate_Air_Resistance(Ball.Drag_Coefficient, AIR_DENSITY, Ball.Area, Ball.Velocity.Y) '10
  38. Const b As Single = 1
  39. Return (k * state.posY) - b * (state.velY)
  40. End Function
  41.  
  42. Private Function integrate(ByVal state As State, ByVal t As Single, ByVal dt As Single) As State
  43. Dim a As Derivative
  44. Dim b As Derivative
  45. Dim c As Derivative
  46. Dim d As Derivative
  47.  
  48. a = (evaluate(state, t, 0.0F, New Derivative()))
  49. b = (evaluate(state, t, dt * 0.5F, a))
  50. c = (evaluate(state, t, dt * 0.5F, b))
  51. d = (evaluate(state, t, dt, c))
  52.  
  53. Dim dxdt As Single = (1.0F / 6.0F) * (a.dx + 2.0F * (b.dx + c.dx) + d.dx)
  54. Dim dydt As Single = (1.0F / 6.0F) * (a.dy + 2.0F * (b.dy + c.dy) + d.dy)
  55.  
  56. Dim dvxdt As Single = (1.0F / 6.0F) * (a.dvx + 2.0F * (b.dvx + c.dvx) + d.dvx)
  57. Dim dvydt As Single = (1.0F / 6.0F) * (a.dvy + 2.0F * (b.dvy + c.dvy) + d.dvy)
  58.  
  59. state.posX += dxdt * dt
  60. state.posY += dydt * dt
  61. state.velX += dvxdt * dt
  62. state.velY += dvydt * dt
  63.  
  64. Return state
  65.  
  66. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement