Advertisement
sumguytwitches

Untitled

Nov 4th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if not (defined launch_margin) declare global launch_margin is 60.
  2. if not (defined orbital_speed_multiplier) declare global orbital_speed_multiplier is 0.6.
  3. set t0 to time:seconds.
  4. set r0 to ship:position-body:position.
  5. set rh to vxcl(v(0,1,0),r0).
  6. set rv to vxcl(rh,r0).
  7. set ph to vcrs(rh,v(0,1,0)).
  8. lock t to time:seconds.
  9. function pos {parameter x. return positionat(x,t)-x:body:position.}
  10. function vel {parameter x. return velocityat(x,t):obt.}
  11. function nrm {parameter x. return vcrs(vel(x),pos(x)):normalized.}
  12. lock rs to pos(ship). lock vs to vel(ship). lock ns to nrm(ship).
  13. lock rt to pos(target). lock vt to vel(target). lock nt to nrm(target).
  14. set a to vdot(rh,nt).
  15. set b to vdot(ph,nt).
  16. set arg to -vdot(rv,nt)/sqrt(a^2+b^2).
  17. if(abs(arg) > 1) log_error("no solution").
  18. set theta1 to arccos(arg).
  19. set theta2 to 360-theta1.
  20. set q1 to mod(360+theta1+arctan2(b,a),360).
  21. set q2 to mod(360+theta2+arctan2(b,a),360).
  22. set first to min(q1,q2).
  23. set tlaunch to t0 + (first/360)*body:rotationperiod - launch_margin.
  24.  
  25. function hdg {parameter x. return mod(360+arctan2(x*vcrs(up:vector,north:vector),x*north:vector),360).}
  26. set h to hdg(vcrs(rs, nt):normalized*sqrt(body:mu/(body:radius+body:atm:height+10e3))*orbital_speed_multiplier - velocity:obt).
  27. print "Launching at heading " + h.
  28. run launch_to_orbit(0, h).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement