def fta(self, jd, tepos):
     # compute fixed time arrival guidance
     # jd : date of arrival
     # tepos position of target at jd (barycenter origin)
     dsec = (jd - self.jd) * common.secofday
     ipos = self.ppos - self.sunpos
     
     # sun position at end
     esunpos, esunvel = common.SPKposvel(10, jd)
     
     tpos = tepos - esunpos
     ivel, tvel = lambert(ipos, tpos, dsec, common.solarmu, ccw=True)
     iprobe_vel = self.pvel - self.sunvel
     delta_v = ivel - iprobe_vel
     
     localdv = common.eclv2lv(delta_v, self.ppos, self.pvel, self.sunpos, 
                              self.sunvel)
     return common.rect2polar(localdv)
    def ftavel(self, jd, tepos):
        # compute fixed time arrival guidance
        # jd : date of arrival
        # tepos position of target at jd (barycenter origin)
        dsec = (jd - self.jd) * common.secofday
        ipos = self.ppos - self.sunpos
        
        # sun position and velocity at end
        esunpos, esunvel = common.SPKposvel(10, jd)
        
        tpos = tepos - esunpos
        ivel, tvel = lambert(ipos, tpos, dsec, common.solarmu, ccw=True)
        iprobe_vel = self.pvel - self.sunvel
        delta_v = ivel - iprobe_vel
        localdv = common.eclv2lv(delta_v, self.ppos, self.pvel, self.sunpos, 
                                 self.sunvel)
        dv, phi, elv = common.rect2polar(localdv)
        
        bc_ivel = ivel + self.sunvel
        bc_tvel = tvel + esunvel

        # returns intial velocity and terminal velocity (SSB origin)
        return dv, phi, elv, bc_ivel, bc_tvel
    def drawFLYTO(self):
        c_time = self.last_trj[0][self.c_index]
        delta_jd = c_time - self.start_time
        self.ui.currenttime.setText(common.jd2isot(c_time))
        self.ui.delta_t_edit.setText('{:.8f}'.format(delta_jd))
        
        ppos = np.zeros(3)
        pvel = np.zeros(3)

        ppos[0] = self.last_trj[1][self.c_index]
        ppos[1] = self.last_trj[2][self.c_index]
        ppos[2] = self.last_trj[3][self.c_index]
        pvel[0] = self.last_trj[4][self.c_index]
        pvel[1] = self.last_trj[5][self.c_index]
        pvel[2] = self.last_trj[6][self.c_index]
        ssacc = self.last_trj[7][self.c_index]
        
        self.savedstatus[0] = np.copy(c_time)
        self.savedstatus[1:4] = np.copy(ppos)
        self.savedstatus[4:7] = np.copy(pvel)

        erase_PKepler()
        if self.ui.check_PKepler.isChecked():
            self.tbpred.fix_state(c_time, ppos, pvel)
            x, y, z, t = self.tbpred.points(g.ndata_s)
            g.probe_Kepler = [x, y, z]
            draw_PKepler()

        target_pos, target_vel = g.mytarget.posvel(c_time)
        sun_pos, sun_vel = common.SPKposvel(10, c_time)        

        xlim = g.ax.get_xlim3d()
        hw = (xlim[1] - xlim[0]) * 0.5
        if self.ui.tobarycenter.isChecked():
            cent = [0.0, 0.0, 0.0]
        elif self.ui.toprobe.isChecked():
            cent = ppos
        else:
            cent = target_pos
        
        g.ax.set_xlim3d(cent[0]-hw, cent[0]+hw)
        g.ax.set_ylim3d(cent[1]-hw, cent[1]+hw)
        g.ax.set_zlim3d(cent[2]-hw, cent[2]+hw)

        # redraw planets
        remove_planets()
        if self.ui.showplanets.isChecked():
            replot_planets(c_time)

        if self.artist_of_probe is not None:
            self.artist_of_probe.remove()
            self.artist_of_probe = None
        self.artist_of_probe = g.ax.scatter(*ppos, s=40, c='r',
                                            depthshade=False, marker='x')
        if self.artist_of_target is not None:
            self.artist_of_target.remove()
            self.artist_of_target = None

        # Maneuver Type
        if self.artist_of_type is not None:
            self.artist_of_type.remove()
            self.artist_of_type = None
        if self.ui.showmantype.isChecked():
            acctext = ''
            if self.c_maninfo['sson']:
                acctext = ' SSacc={:.3f}'.format(ssacc)
            if self.c_index == 0:
                self.artist_of_type = g.ax.text(*ppos, self.mantext+acctext+
                    ' (start)', color='r', fontsize=10)
            elif self.c_index + 1 == len(self.last_trj[0]):
                self.artist_of_type = g.ax.text(*ppos, self.mantext+acctext+
                    ' (end)', color='r', fontsize=10)
            else:
                self.artist_of_type = g.ax.text(*ppos, self.mantext+acctext, 
                    color='r', fontsize=10)

        self.artist_of_target = g.ax.scatter(*target_pos, s=50, c='g',
                                             depthshade=False, marker='+')
        if self.artist_of_sun is not None:
            self.artist_of_sun.remove()
            self.artist_of_sun = None
        self.artist_of_sun = g.ax.scatter(*sun_pos, s=50, c='#FFAF00',
                                          depthshade=False, marker='o')

        remove_time()
        replot_time(c_time, self.timecap_real)
        
        if g.fig is not None: plt.draw()
        
        # display relative position and velocity
        rel_pos = target_pos - ppos
        rel_pos = common.eclv2lv(rel_pos, ppos, pvel, sun_pos, sun_vel)
        trange, tphi, telv = common.rect2polar(rel_pos)
        rel_vel = target_vel - pvel
        rel_vel = common.eclv2lv(rel_vel, ppos, pvel, sun_pos, sun_vel)
        relabsvel, tvphi, tvelv = common.rect2polar(rel_vel)
        losvel = np.dot(rel_vel, rel_pos) / trange
        self.ui.RPTrange.setText('{:.3f}'.format(trange / 1000.0))
        self.ui.RPTphi.setText('{:.2f}'.format(tphi))
        self.ui.RPTelv.setText('{:.2f}'.format(telv))
        self.ui.RVTvel.setText('{:.3f}'.format(relabsvel))
        self.ui.RVTphi.setText('{:.2f}'.format(tvphi))
        self.ui.RVTelv.setText('{:.2f}'.format(tvelv))
        self.ui.LoSVvel.setText('{:.3f}'.format(losvel))