Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //launch_util.ks
- //code by "space_is_hard" used as a reference
- //utility functions for the launch script
- @LAZYGLOBAL off.
- //adjust inclination
- //returns a heading angle that should
- FUNCTION initAzimuth
- {
- PARAMETER
- targetAp,
- targetPe,
- targetInc.
- LOCAL azimuthData to LIST().
- LOCAL targetAlt to ((targetAp+targetPe)/2).
- //Step 1: Calculate Orbital Velocity at target altitude
- LOCAL targetOrbVel to (SQRT(BODY:MU/(BODY:RADIUS + targetAlt))).
- //Step 2: Get X and Y components of target orbital velocity
- LOCAL targetXVel to (targetOrbVel * COS(targetInc)).
- LOCAL targetYVel to (targetOrbVel * SIN(targetInc)).
- //Put it in a data structure for real time computing
- azimuthData:ADD(targetXVel). //[0]
- azimuthData:ADD(targetYVel). //[1]
- RETURN azimuthData.
- }
- FUNCTION getAzimuth
- {
- PARAMETER
- azimuthData.
- LOCAL shipInc to SHIP:OBT:INCLINATION.
- //Step 3: Calculate horizontal ship velocity
- LOCAL shipVel to (SHIP:VELOCITY:ORBIT:MAG - ABS(SHIP:VERTICALSPEED)).
- //Step 4: Get X and Y components of horizontal ship velocity.
- LOCAL shipXVel to (shipVel * COS(shipInc)).
- LOCAL shipYVel to (shipVel * SIN(shipInc)).
- //Step 5: Calculate required azimuth vector from combining both velocities.
- LOCAL AzimuthX to (azimuthData[0]-shipXVel).
- LOCAL AzimuthY to (azimuthData[1]-shipYVel).
- //Step 6: Calculating resulting Azimuth to target from this vector.
- Local azimuth to ARCTAN2(AzimuthX, AzimuthY).
- RETURN MOD(azimuth+360, 360).
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement