original_docstring: 
          pos: position of element
          vel: velocity of element
          mu:  gravitational constant/parameter = GM
          
docstring: position of element
  vel: velocity of element
  mu:  gravitational constant/parameter = GM
docstring_tokens: position of element vel : velocity of element mu : gravitational constant / parameter = GM
code: def fromVectors(pos, vel, mu):
          """
          pos: position of element
          vel: velocity of element
          mu:  gravitational constant/parameter = GM
          """
          #calculate orbital momentum vector h (m^2/s)
          r = pos.mag()
          h = pos.cross(vel)
          #obtain eccentricity vector
          print("Vel Pos", vel, pos)
          e1 = vel.cross(h).fdiv(mu)
          e2 = pos.fdiv(pos.mag())
          print("e1 e2", e1, e2)
          e_vec = e1.sub(e2)
          e = e_vec.mag()
          print("evec", e_vec)
          #determine n (m^2/s)
  
          #calculate orbit inclination i by using orbital
          #momentum vector h, where h_z is third component of h
          i = acos(h.z/h.mag())
          while i > pi/2.0:
             i = i - pi
  
          print("i: ", i)
  
  
          n_vec = None
          if i == 0.0:
              n_vec = Vector3.X()
          else:
              n_vec = Vector3.Z().cross(h)
  
          #obtain longtitude of ascending node
          long_asc = 0.0
          if i == 0.0:
              long_asc = 0.0
          elif n_vec.y >= 0:
              print("n_vec:" , n_vec)
              print("h: ", h)
              long_asc = acos(n_vec.x/n_vec.mag())
          else:
              long_asc = 2.0*pi - acos(n_vec.x/n_vec.mag())
  
          #obtain argument of periapsis
          arg_per = 0.0
          if e_vec.z >= 0:
              arg_per = acos(n_vec.dot(e_vec)/(n_vec.mag() * e))
          else:
              arg_per = 2.0 * pi - acos(n_vec.dot(e_vec)/(n_vec.mag() * e))
  
          print("n_vec:" , n_vec)
          print("h: ", h)
  
          p = (h.mag()**2)/2.0 #semi-latus rectum
  
          a = 0.0
          semilatus = 0.0
          v = 0.0
          M = 0.0
          true_lon = 0.0
          arg_lat = 0.0
          lon_per = 0.0
          if e == 0:
              #circle
              a = r
              b = r
  
              lon_per = None
              arg_per = None
  
              if i==0.0:
                  arg_lat = None
                  if(vel.x > 0.0):
                      true_lon = 2*pi - acos(pos.x/r)
                  else:
                      true_lon = acos(pos.x/r)
              else:
                  if n_vec.dot(vel) > 0.0:
                      arg_lat = 2*pi - acos(n_vec.dot(pos)/(n_vec.mag()*r))
                  else:
                      arg_lat = acos(n_vec.dot(pos)/(n_vec.mag()*r))
  
                  #calculate true anomaly v (rad)
                  if (pos.dot(vel) >= 0):
                      true_lon = Vector3(1,0,0).angle(pos)
                  else:
                      true_lon = 2.0*pi - Vector3(1,0,0).angle(pos)
  
          elif (e > 0 and e < 1):
              #ellipse
              #calculate semi-major axis a
              a = 1.0/((2.0/pos.mag()) - ((vel.mag()**2)/mu))
              rp = (1 + e)*a #pericenter
              ra = (1 - e)*a #apocenter
              b = sqrt(ra*rp)  #semi-minor axis
  
              #calculate eccentric anomaly E
              E = 2 * atan(tan(v/2)/sqrt((1+e)/(1-e)))
  
              #calculate mean anomaly with the help of kepler's equation
              #from the eccentric anomaly, and the eccentricity of the orbit
              M = E - e * sin(E)
  
              #longtitude of periapsis
              long_per = long_asc + arg_per
  
              #calculate true anomaly v (rad)
              if (pos.dot(vel) >= 0):
                  v = e_vec.angle(pos)
              else:
                  v = 2.0*pi - e_vec.angle(pos)
  
              #argument of latitude
              arg_lat = v + arg_per
              #true longtitude
              true_lon = v + long_per
  
          elif e == 1:
              #parabola
              b = sys.float_info.max
              a = sys.float_info.max #infinity
  
          elif e > 1:
              #hyperbola
              a = -p/(e**2 - 1.0)
              b = p/sqrt(e**2 - 1)
  
  
  
          print("True anomaly: ", degrees(v))
  
          return KeplerOrbit2(a,
                  b,
                  e,
                  i,
                  long_asc,
                  arg_per,
                  M,
                  true_lon,
                  arg_lat,
                  lon_per,
                  p,
                  mu,
                  n_vec,
                  h)
code_tokens: def fromVectors ( pos , vel , mu ) : r = pos . mag ( ) h = pos . cross ( vel ) print ( "Vel Pos" , vel , pos ) e1 = vel . cross ( h ) . fdiv ( mu ) e2 = pos . fdiv ( pos . mag ( ) ) print ( "e1 e2" , e1 , e2 ) e_vec = e1 . sub ( e2 ) e = e_vec . mag ( ) print ( "evec" , e_vec ) i = acos ( h . z / h . mag ( ) ) while i > pi / 2.0 : i = i - pi print ( "i: " , i ) n_vec = None if i == 0.0 : n_vec = Vector3 . X ( ) else : n_vec = Vector3 . Z ( ) . cross ( h ) long_asc = 0.0 if i == 0.0 : long_asc = 0.0 elif n_vec . y >= 0 : print ( "n_vec:" , n_vec ) print ( "h: " , h ) long_asc = acos ( n_vec . x / n_vec . mag ( ) ) else : long_asc = 2.0 * pi - acos ( n_vec . x / n_vec . mag ( ) ) arg_per = 0.0 if e_vec . z >= 0 : arg_per = acos ( n_vec . dot ( e_vec ) / ( n_vec . mag ( ) * e ) ) else : arg_per = 2.0 * pi - acos ( n_vec . dot ( e_vec ) / ( n_vec . mag ( ) * e ) ) print ( "n_vec:" , n_vec ) print ( "h: " , h ) p = ( h . mag ( ) ** 2 ) / 2.0 a = 0.0 semilatus = 0.0 v = 0.0 M = 0.0 true_lon = 0.0 arg_lat = 0.0 lon_per = 0.0 if e == 0 : a = r b = r lon_per = None arg_per = None if i == 0.0 : arg_lat = None if ( vel . x > 0.0 ) : true_lon = 2 * pi - acos ( pos . x / r ) else : true_lon = acos ( pos . x / r ) else : if n_vec . dot ( vel ) > 0.0 : arg_lat = 2 * pi - acos ( n_vec . dot ( pos ) / ( n_vec . mag ( ) * r ) ) else : arg_lat = acos ( n_vec . dot ( pos ) / ( n_vec . mag ( ) * r ) ) if ( pos . dot ( vel ) >= 0 ) : true_lon = Vector3 ( 1 , 0 , 0 ) . angle ( pos ) else : true_lon = 2.0 * pi - Vector3 ( 1 , 0 , 0 ) . angle ( pos ) elif ( e > 0 and e < 1 ) : a = 1.0 / ( ( 2.0 / pos . mag ( ) ) - ( ( vel . mag ( ) ** 2 ) / mu ) ) rp = ( 1 + e ) * a ra = ( 1 - e ) * a b = sqrt ( ra * rp ) E = 2 * atan ( tan ( v / 2 ) / sqrt ( ( 1 + e ) / ( 1 - e ) ) ) M = E - e * sin ( E ) long_per = long_asc + arg_per if ( pos . dot ( vel ) >= 0 ) : v = e_vec . angle ( pos ) else : v = 2.0 * pi - e_vec . angle ( pos ) arg_lat = v + arg_per true_lon = v + long_per elif e == 1 : b = sys . float_info . max a = sys . float_info . max elif e > 1 : a = - p / ( e ** 2 - 1.0 ) b = p / sqrt ( e ** 2 - 1 ) print ( "True anomaly: " , degrees ( v ) ) return KeplerOrbit2 ( a , b , e , i , long_asc , arg_per , M , true_lon , arg_lat , lon_per , p , mu , n_vec , h )
short_docstring: pos: position of element
  vel: velocity of element
  mu:  gravitational constant/parameter = GM
short_docstring_tokens: pos : position of element vel : velocity of element mu : gravitational constant / parameter = GM
comment: """
          pos: position of element
          vel: velocity of element
          mu:  gravitational constant/parameter = GM
          """$SEP$#calculate orbital momentum vector h (m^2/s)$SEP$#obtain eccentricity vector$SEP$#determine n (m^2/s)$SEP$#calculate orbit inclination i by using orbital$SEP$#momentum vector h, where h_z is third component of h$SEP$#obtain longtitude of ascending node$SEP$#obtain argument of periapsis$SEP$#semi-latus rectum$SEP$#circle$SEP$#calculate true anomaly v (rad)$SEP$#ellipse$SEP$#calculate semi-major axis a$SEP$#pericenter$SEP$#apocenter$SEP$#semi-minor axis$SEP$#calculate eccentric anomaly E$SEP$#calculate mean anomaly with the help of kepler's equation$SEP$#from the eccentric anomaly, and the eccentricity of the orbit$SEP$#longtitude of periapsis$SEP$#calculate true anomaly v (rad)$SEP$#argument of latitude$SEP$#true longtitude$SEP$#parabola$SEP$#infinity$SEP$#hyperbola