I'm trying to solve the transfer between a circular orbit with 200km radius and an orbit with 200km perigee and 8000km apogee.
The optimal transfer is hoffman, however, izzo.lambert from poliastro gives different result.
My code:
from astropy import units as u
from poliastro.bodies import Earth
from poliastro.iod import izzo
from poliastro.core.elements import coe2rv
from poliastro.util import norm
import math
import time
Earth_k = Earth.k
Req = Earth.R.to(u.km).value
def keplerian2cartesian(kepler):
a=(kepler[0]+kepler[1]+Req*2)*1000/2 * u.m
e=(kepler[0]-kepler[1])/(kepler[0]+kepler[1]+Req*2)
(R,V)=coe2rv(Earth.k,a,e,kepler[2],kepler[3],kepler[4],kepler[5])
return [R * u.m] + [V * u.m/u.s]
# Checking different transfer times
def transfer_time(DV_min,vector0,vector,period):
init_t=10
t_value=init_t
(r0,r,v0,v)=(vector0[0],vector[0],vector0[1],vector[1])
while init_t<period:
tof = init_t * u.min
try:
(f_v0, f_v), = izzo.lambert(Earth_k, r0, r, tof)
except:
init_t+=1
continue
DV0=norm(f_v0-v0).value*1000
DV=norm(f_v-v).value*1000
if(DV0+DV<DV_min):
t_value=init_t
DV0_value=DV0
DV_value=DV
DV_min=DV0+DV
init_t+=1
return (t_value,DV_value,DV0_value)
# Checking different initial and final true anomalies
def transfer_tetta(kepler0,kepler):
DV_min=100000
final_tetta=0
a=(kepler[0]+kepler[1]+Req*2)*1000/2
period=math.ceil(math.sqrt((a**3/Earth.k.value)*4*(math.pi)**2)/60)
while final_tetta<360:
init_tetta=0
while init_tetta<360:
vector0=keplerian2cartesian(kepler0 + [init_tetta*math.pi/180])
vector =keplerian2cartesian(kepler + [final_tetta*math.pi/180])
try:
(init_t,DV,DV0)=transfer_time(DV_min,vector0,vector,period)
except:
init_tetta+=5
continue
if DV+DV0<DV_min:
DV_min=DV+DV0
(t_value,DV0_value,DV_value,init_tetta_value,final_tetta_value)=(init_t,DV0,DV,init_tetta,final_tetta)
init_tetta+=5
final_tetta+=5
print("t: ", t_value, "DV_init: ", DV0_value,"DV_final: ", DV_value)
print("DV: ", DV_min)
print("Init tetta: ", init_tetta_value, "Final tetta: ", final_tetta_value)
# 1->2
transfer_tetta([200, 200, 64.3*math.pi/180, 0, 300*math.pi/180],[8000, 200, 64.3*math.pi/180, 0, 300*math.pi/180])