RazerM / orbital

High level orbital mechanics package.
MIT License
91 stars 35 forks source link

Getting Cartesian position and velocity vectors for propagated orbit #6

Closed OrbitalPineapple closed 7 years ago

OrbitalPineapple commented 7 years ago

I am trying to get the cartesian position and velocity vectors for each propagation step in my orbit. I generated the orbit with Keplerian elements.

According to the documentation I should be able to get the state vectors (both position and velocity) from class orbital.utilities.StateVector , but I get a Type Error: new() takes exactly 3 arguments (2 given)

Here is the code:

from scipy.constants import kilo
import orbital
from orbital import earth, KeplerianElements, Maneuver, plot, utilities
from orbital.utilities import Position, Velocity
import matplotlib.pyplot as plt
import numpy as np

#Orbit Setup
orbitPineapple = KeplerianElements.with_period(96 * 60, body=earth, i=(np.deg2rad(51.6)))
plot(orbitPineapple)
plt.show()
orbitPineapple

Out[23]: KeplerianElements(a=6945033.343911132, e=0, i=0.90058989402907408, raan=0, arg_pe=0, M0=0.0, body=orbital.bodies.earth, ref_epoch=

prop1 = orbital.maneuver.PropagateAnomalyTo(M=1.00)
orbitX = orbitPineapple.apply_maneuver(prop1)
plot(orbitPineapple, title='Go Pineapple!')
plt.show()

orbital.utilities.StateVector(orbitPineapple)

TypeError Traceback (most recent call last)

in () 4 #print(orbital.utilities.StateVector.velocity(orbitPineapple)) 5 ----> 6 orbital.utilities.StateVector(orbitPineapple) 7 #orbital.utilities.StateVector.position(orbitPineapple()) 8 TypeError: __new__() takes exactly 3 arguments (2 given)
RazerM commented 7 years ago

Use orbitX.r and orbitX.v.

OrbitalPineapple commented 7 years ago

I tried it before and again now and it resulted in an attribute error. Code:

print(orbitX.r)
print(orbitX.v)
AttributeError                            Traceback (most recent call last)
<ipython-input-16-d39ac04f7e8f> in <module>()
----> 1 print(orbitX.r)
      2 print(orbitX.v)

AttributeError: 'NoneType' object has no attribute 'r'
OrbitalPineapple commented 7 years ago

It turns out that for the state vectors .r and .v you can only use the original orbit name. The original name will automatically be updated after each maneuver or propagation.

So,

print(orbitPineapple.r) 
print(orbitPineapple.v) 

will give me the state vectors, position and velocity, in Earth centric inertial coordinates (ECI).

RazerM commented 7 years ago

Yes, apply_maneuver mutates the orbit as shown in the documentation.