Coverage Report

Created: 2026-09-04 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sofars-0.6.1/src/star/hfk5z.rs
Line
Count
Source
1
use crate::consts::{DJ00, DJY};
2
use crate::star::fk5hip;
3
use crate::vm::{anp, pv2s, rv2m, rxp, rxr, s2c, sxp, trxp, pxp};
4
5
/// Transform a Hipparcos star position into FK5 J2000.0, assuming
6
/// zero Hipparcos proper motion.
7
///
8
/// Status:  support function.
9
///
10
/// Given:
11
///    rh            f64    Hipparcos RA (radians)
12
///    dh            f64    Hipparcos Dec (radians)
13
///    date1,date2   f64    TDB date (Note 1)
14
///
15
/// Returned (all FK5, equinox J2000.0, date date1+date2):
16
///    r5            f64    RA (radians)
17
///    d5            f64    Dec (radians)
18
///    dr5           f64    RA proper motion (rad/year, Note 4)
19
///    dd5           f64    Dec proper motion (rad/year, Note 4)
20
///
21
/// Notes:
22
///
23
/// 1) The TT date date1+date2 is a Julian Date, apportioned in any
24
///    convenient way between the two arguments.  For example,
25
///    JD(TT)=2450123.7 could be expressed in any of these ways,
26
///    among others:
27
///
28
///           date1          date2
29
///
30
///        2450123.7           0.0       (JD method)
31
///        2451545.0       -1421.3       (J2000 method)
32
///        2400000.5       50123.2       (MJD method)
33
///        2450123.5           0.2       (date & time method)
34
///
35
///    The JD method is the most natural and convenient to use in
36
///    cases where the loss of several decimal digits of resolution
37
///    is acceptable.  The J2000 method is best matched to the way
38
///    the argument is handled internally and will deliver the
39
///    optimum resolution.  The MJD method and the date & time methods
40
///    are both good compromises between resolution and convenience.
41
///
42
/// 2) The proper motion in RA is dRA/dt rather than cos(Dec)*dRA/dt.
43
///
44
/// 3) The FK5 to Hipparcos transformation is modeled as a pure rotation
45
///    and spin;  zonal errors in the FK5 catalog are not taken into
46
///    account.
47
///
48
/// 4) It was the intention that Hipparcos should be a close
49
///    approximation to an inertial frame, so that distant objects have
50
///    zero proper motion;  such objects have (in general) non-zero
51
///    proper motion in FK5, and this function returns those fictitious
52
///    proper motions.
53
///
54
/// 5) The position returned by this function is in the FK5 J2000.0
55
///    reference system but at date date1+date2.
56
///
57
/// 6) See also fk52h, h2fk5, fk5hz.
58
///
59
/// Called:
60
///    s2c       spherical coordinates to unit vector
61
///    fk5hip    FK5 to Hipparcos rotation and spin
62
///    rxp       product of r-matrix and p-vector
63
///    sxp       multiply p-vector by scalar
64
///    rv2m      r-vector to r-matrix
65
///    rxr       product of two r-matrices
66
///    trxp      product of transpose of r-matrix and p-vector
67
///    pxp       vector product of two p-vectors
68
///    pv2s      pv-vector to spherical
69
///    anp       normalize angle into range 0 to 2pi
70
///
71
/// Reference:
72
///    F.Mignard & M.Froeschle, 2000, Astron.Astrophys. 354, 732-739.
73
0
pub fn hfk5z(rh: f64, dh: f64, date1: f64, date2: f64) -> (f64, f64, f64, f64) {
74
0
    let mut sh = [0.0; 3];
75
0
    let mut rst = [[0.0; 3]; 3];
76
0
    let mut r5ht = [[0.0; 3]; 3];
77
0
    let mut pv5e = [[0.0; 3]; 2];
78
79
    /* Time interval from fundamental epoch J2000.0 to given date (JY). */
80
0
    let t = ((date1 - DJ00) + date2) / DJY;
81
82
    /* Hipparcos barycentric position vector (normalized). */
83
0
    let ph = s2c(rh, dh);
84
85
    /* FK5 to Hipparcos orientation matrix and spin vector. */
86
0
    let (r5h, s5h) = fk5hip();
87
88
    /* Rotate the spin into the Hipparcos system. */
89
0
    rxp(&r5h, &s5h, &mut sh);
90
91
    /* Accumulated Hipparcos wrt FK5 spin over that interval. */
92
0
    let vst = sxp(t, &s5h);
93
94
    /* Express the accumulated spin as a rotation matrix. */
95
0
    rv2m(&vst, &mut rst);
96
97
    /* Rotation matrix:  accumulated spin, then FK5 to Hipparcos. */
98
0
    rxr(&r5h, &rst, &mut r5ht);
99
100
    /* De-orient & de-spin the Hipparcos position into FK5 J2000.0. */
101
0
    trxp(&r5ht, &ph, &mut pv5e[0]);
102
103
    /* Apply spin to the position giving a space motion. */
104
0
    let vv = pxp(&sh, &ph);
105
106
    /* De-orient & de-spin the Hipparcos space motion into FK5 J2000.0. */
107
0
    trxp(&r5ht, &vv, &mut pv5e[1]);
108
109
    /* FK5 position/velocity pv-vector to spherical. */
110
0
    let (w, d5, _, dr5, dd5, _) = pv2s(&pv5e);
111
0
    let r5 = anp(w);
112
113
0
    (r5, d5, dr5, dd5)
114
0
}