rfa 0.5.9

A port ERFA to Rust.
Documentation

use crate::utils::*;
///  Convert position/velocity from Cartesian to spherical coordinates.
///
///  Given:
///   * pv pv-vector
///
///  Returned:
///   * theta    double        longitude angle (radians)
///   * phi      double        latitude angle (radians)
///   * r        double        radial distance
///   * td       double        rate of change of theta
///   * pd       double        rate of change of phi
///   * rd       double        rate of change of r
///
///  Notes:
///   * If the position is a pole, theta, td and pd are indeterminate.
///     In such cases zeroes are returned for all three.
///
///  This revision:  2021 May 11
pub fn pv2s(pv: &[[f64; 3]; 2], theta: &mut f64, phi: &mut f64, r: &mut f64,
    td: &mut f64, pd: &mut f64 , rd:& mut f64)
{
    /* Components of position/velocity vector. */
    let mut x  = pv[0][0];
    let mut y  = pv[0][1];
    let mut z  = pv[0][2];
    let xd = pv[1][0];
    let yd = pv[1][1];
    let zd = pv[1][2];
    
    /* Component of r in XY plane squared. */
    let mut rxy2 = x*x + y*y;
    
    /* Modulus squared. */
    let mut r2 = rxy2 + z*z;
    
    /* Modulus. */
    let rtrue = r2.sqrt();
    
    /* If null vector, move the origin along the direction of movement. */
       let mut rw = rtrue;
       if rtrue == 0.0 {
           x = xd;
           y = yd;
           z = zd;
           rxy2 = x*x + y*y;
           r2 = rxy2 + z*z;
           rw = r2.sqrt();
       }
    
    /* Position and velocity in spherical coordinates. */
       let rxy = sqrt(rxy2);
       let xyp = x*xd + y*yd;
       if rxy2 != 0.0 {
           *theta = atan2(y, x);
           *phi = atan2(z, rxy);
           *td = (x*yd - y*xd) / rxy2;
           *pd = (zd*rxy2 - z*xyp) / (r2*rxy);
       } else {
           *theta = 0.0;
           *phi = if z != 0.0{atan2(z, rxy)}else{ 0.0};
           *td = 0.0;
           *pd = 0.0;
       }
       *r = rtrue;
       *rd = if rw != 0.0{ (xyp + z*zd) / rw } else { 0.0 };
    
    /* Finished. */
    
}