Guest User

Untitled

a guest
Dec 25th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. // Try to calculate when the phase angle(PA) is equal to the target phase
  2. // angle necessary to get an encounter with a target.
  3. //assumes circular orbits that are coplanar
  4. declare function circularRendezvous{
  5. parameter target.
  6. print " ".
  7.  
  8. set targetSma to target:orbit:semimajoraxis.
  9. set shipSma to ship:orbit:semimajoraxis.
  10. set transferSma to (targetSma + shipSma)/2.
  11.  
  12. //this is the phase angle where a burn will start a transfer to the target
  13. set targetPA to 180 - 360 / (2*sqrt(targetSma^3/transferSma^3)).
  14.  
  15. //vectors from parent body to ship and target, like a clock
  16. set shippos to ship:position - ship:orbit:body:position.
  17. set targetpos to target:position - body:position.
  18.  
  19. //set curPA to the angle ahead of the ship that the target is.
  20. set curPA to vang(shippos, targetpos).
  21. print "Raw vang: " + round(curPA, 1).
  22. set orbitNorm to vcrs(up:vector, ship:velocity:orbit).
  23.  
  24. //Gets whether the target is ahead or behind the ship.
  25. //vcrs gets a normal(90deg from BOTH vectors) of which there are 2: One
  26. //vector pointing at you from the center of the "clock" and one away.
  27. //The direction (and therefore the sign) indicates whether the target
  28. //is ahead or behind. We detect which one it is by comparing to the orbit
  29. //normal using vdot, which will give us a positive value if the result of
  30. //the vcrs is similar. If it is behind we do 360 - ang instead.
  31. IF vdot(vcrs(shippos,targetpos):normalized, orbitNorm:normalized) < 0
  32. set curPA to 360-curPA.
  33. print "vdot-vcrs: " + round(vdot(vcrs(shippos,targetpos):normalized,orbitNorm:normalized), 4).
  34.  
  35. // Get the rate of change of the angle between ship and target.
  36. set shipRate to 360 / ship:orbit:period.
  37. set targetRate to 360 / target:orbit:period.
  38. //TODO: assumes same orbital direction as target(clock vs anticlock orbit)
  39. set combinedRate to abs(shipRate-targetRate).
  40.  
  41. // if this estimation is coming after (or within 10 degrees of) the target
  42. // phase angle, choose the next one instead.
  43. //TODO: crude estimate of time needed to burn
  44. if curPA >= targetPA + 10
  45. set degTotargetPA to curPA - targetPA.
  46. else
  47. set degTotargetPA to curPA + targetPA.
  48.  
  49.  
  50. //The final results. time = dist/vel
  51. set burnETA to degTotargetPA / combinedRate.
  52. set timeOfTargetPA to timestamp() + burnEta.
  53. .
  54.  
  55. print "StartAngle: " + round(curPA, 1).
  56. print "Angle to burn at: " + round(targetPA, 1).
  57. print "ETA till Burn: " + round(burnETA).
  58. print "dist(deg) til burn: " + round(angleToBurn, 1).
  59. print "combinedRate:" + round(combinedRate, 4).
  60.  
  61. return timeOfTargetPA.
  62. }
  63.  
  64. set done to false.
  65. until done{
  66. circularRendezvous(mun).
  67. wait(1).
  68. }
Advertisement
Add Comment
Please, Sign In to add comment