rv_to_orbital_elements Subroutine

public pure subroutine rv_to_orbital_elements(mu, r, v, p, ecc, inc, raan, aop, tru)

Convert position and velocity vectors to orbital elements.

See also

  • The poliastro routine rv2coe.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: mu

gravitational parameter []

real(kind=wp), intent(in), dimension(3) :: r

position vector [km]

real(kind=wp), intent(in), dimension(3) :: v

velocity vector [km/s]

real(kind=wp), intent(out) :: p

semiparameter [km]

real(kind=wp), intent(out) :: ecc

eccentricity [--]

real(kind=wp), intent(out) :: inc

inclination [rad]

real(kind=wp), intent(out) :: raan

raan [rad]

real(kind=wp), intent(out) :: aop

argument of peripsis [rad]

real(kind=wp), intent(out) :: tru

true anomaly [rad]


Calls

proc~~rv_to_orbital_elements~~CallsGraph proc~rv_to_orbital_elements orbital_mechanics_module::rv_to_orbital_elements proc~cross vector_module::cross proc~rv_to_orbital_elements->proc~cross proc~orbit_check orbital_mechanics_module::orbit_check proc~rv_to_orbital_elements->proc~orbit_check proc~wrap_angle math_module::wrap_angle proc~rv_to_orbital_elements->proc~wrap_angle

Source Code

    pure subroutine rv_to_orbital_elements(mu, r, v, p, ecc, inc, raan, aop, tru)

    implicit none

    real(wp),intent(in)              :: mu   !! gravitational parameter [\(km^{3}/s^{2}\)]
    real(wp),dimension(3),intent(in) :: r    !! position vector [km]
    real(wp),dimension(3),intent(in) :: v    !! velocity vector [km/s]
    real(wp),intent(out)             :: p    !! semiparameter \(a(1-e^{2})\) [km]
    real(wp),intent(out)             :: ecc  !! eccentricity [--]
    real(wp),intent(out)             :: inc  !! inclination [rad]
    real(wp),intent(out)             :: raan !! raan [rad]
    real(wp),intent(out)             :: aop  !! argument of peripsis [rad]
    real(wp),intent(out)             :: tru  !! true anomaly [rad]

    real(wp),dimension(3) :: h,n,e
    logical :: circular,equatorial
    reaL(wp) :: hmag,rmag,vmag

    rmag = norm2(r)
    vmag = norm2(v)
    h    = cross(r,v)
    hmag = norm2(h)
    n    = cross([zero,zero,one],h)/hmag
    e    = ((vmag**2-mu/rmag)*r-dot_product(r,v)*v)/mu
    ecc  = norm2(e)
    p    = hmag**2/mu
    inc  = atan2(norm2(h(1:2)),h(3))

    call orbit_check(ecc,inc,circular,equatorial)

    if (equatorial .and. .not. circular) then
        raan = zero
        aop  = wrap_angle(atan2(e(2),e(1))) ! Longitude of periapsis
        tru  = wrap_angle(atan2(dot_product(h,cross(e,r))/hmag,dot_product(r,e)))
    elseif ( .not. equatorial .and. circular) then
        raan = wrap_angle(atan2(n(2),n(1)))
        aop  = zero
        tru  = wrap_angle(atan2(dot_product(r,cross(h,n))/hmag,dot_product(r,n))) ! Argument of latitude
    elseif (equatorial .and. circular) then
        raan = zero
        aop  = zero
        tru  = wrap_angle(atan2(r(2),r(1))) ! True longitude
    else
        raan = wrap_angle(atan2(n(2),n(1)))
        aop  = wrap_angle(atan2(dot_product(e,cross(h,n))/hmag,dot_product(e,n)))
        tru  = wrap_angle(atan2(dot_product(r,cross(h,e))/hmag,dot_product(r,e)))
    endif

    end subroutine rv_to_orbital_elements