Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Try to calculate when the phase angle(PA) is equal to the target phase
- // angle necessary to get an encounter with a target.
- //assumes circular orbits that are coplanar
- declare function circularRendezvous{
- parameter target.
- print " ".
- set targetSma to target:orbit:semimajoraxis.
- set shipSma to ship:orbit:semimajoraxis.
- set transferSma to (targetSma + shipSma)/2.
- //this is the phase angle where a burn will start a transfer to the target
- set targetPA to 180 - 360 / (2*sqrt(targetSma^3/transferSma^3)).
- //vectors from parent body to ship and target, like a clock
- set shippos to ship:position - ship:orbit:body:position.
- set targetpos to target:position - body:position.
- //set curPA to the angle ahead of the ship that the target is.
- set curPA to vang(shippos, targetpos).
- print "Raw vang: " + round(curPA, 1).
- set orbitNorm to vcrs(up:vector, ship:velocity:orbit).
- //Gets whether the target is ahead or behind the ship.
- //vcrs gets a normal(90deg from BOTH vectors) of which there are 2: One
- //vector pointing at you from the center of the "clock" and one away.
- //The direction (and therefore the sign) indicates whether the target
- //is ahead or behind. We detect which one it is by comparing to the orbit
- //normal using vdot, which will give us a positive value if the result of
- //the vcrs is similar. If it is behind we do 360 - ang instead.
- IF vdot(vcrs(shippos,targetpos):normalized, orbitNorm:normalized) < 0
- set curPA to 360-curPA.
- print "vdot-vcrs: " + round(vdot(vcrs(shippos,targetpos):normalized,orbitNorm:normalized), 4).
- // Get the rate of change of the angle between ship and target.
- set shipRate to 360 / ship:orbit:period.
- set targetRate to 360 / target:orbit:period.
- //TODO: assumes same orbital direction as target(clock vs anticlock orbit)
- set combinedRate to abs(shipRate-targetRate).
- // if this estimation is coming after (or within 10 degrees of) the target
- // phase angle, choose the next one instead.
- //TODO: crude estimate of time needed to burn
- if curPA >= targetPA + 10
- set degTotargetPA to curPA - targetPA.
- else
- set degTotargetPA to curPA + targetPA.
- //The final results. time = dist/vel
- set burnETA to degTotargetPA / combinedRate.
- set timeOfTargetPA to timestamp() + burnEta.
- .
- print "StartAngle: " + round(curPA, 1).
- print "Angle to burn at: " + round(targetPA, 1).
- print "ETA till Burn: " + round(burnETA).
- print "dist(deg) til burn: " + round(angleToBurn, 1).
- print "combinedRate:" + round(combinedRate, 4).
- return timeOfTargetPA.
- }
- set done to false.
- until done{
- circularRendezvous(mun).
- wait(1).
- }
Advertisement
Add Comment
Please, Sign In to add comment