from net.willware.Orbits import System, Vector, PointMass, Tether
from java.awt import Color
import sys

incomingStartingRadius = System.earthRadius + 3000 * System.mile
outgoingStartingRadius = System.earthRadius + 20 * System.mile
incomingStartingVelocity = 14100

s = System()
LET_GO_TIME = 1530
s.tmax = 5000
s.dt = 0.1
s.time = 0.0

def getarg(args=sys.argv[1:]):
    return args.pop(0)

while 1:
    try:
        arg = getarg()
        if arg == "-tmax":
            s.tmax = eval(getarg())
        elif arg == "-letgo":
            LET_GO_TIME = eval(getarg())
    except IndexError:
        break

incomingShip = PointMass(s, "IncomingShip", System.airplaneMass,
                         Vector(0, incomingStartingRadius, 0),
                         Vector(incomingStartingVelocity, 0, 0),
                         Color.MAGENTA)

vlow = System.airplaneVelocity + System.earthRotationalVelocity
outgoingShip = PointMass(s, "OutgoingShip", System.airplaneMass,
                         Vector(0, outgoingStartingRadius, 0),
                         Vector(-vlow, 0, 0),
                         Color.ORANGE);

tether = Tether(incomingStartingRadius - outgoingStartingRadius,
                LET_GO_TIME)
tether.setEnd1(incomingShip)
tether.setEnd2(outgoingShip)
s.add(incomingShip)
s.add(outgoingShip)
s.add(tether)
s.hack()


print "\nOutgoing ship:"
print ("min altitude %g miles" % (outgoingShip.minAltitude / System.mile))
print ("max altitude %g miles" % (outgoingShip.maxAltitude / System.mile))
print ("min altitude %g km" % (outgoingShip.minAltitude / 1000))
print ("max altitude %g km" % (outgoingShip.maxAltitude / 1000))
print ("max velocity %g m/sec" % outgoingShip.maxVelocity)
print ("final velocity %g m/sec" % (outgoingShip.previousVelocity))
print ("max acceleration %g Gs" %
       (outgoingShip.maxAcceleration / System.earthGravity))

print "\nIncoming ship:"
print ("init velocity %g m/sec" % incomingStartingVelocity)
print ("min velocity %g m/sec" % incomingShip.minVelocity)
print ("max velocity %g m/sec" % incomingShip.maxVelocity)

print "\nTether:"
print ("max tension %g newtons" % tether.getMaxTension())
print ("stretch factor %g" % (tether.getMaxLength() / tether.getLength()))
