Coverage Report

Created: 2026-09-14 07:01

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/fk5hz.rs
Line
Count
Source
1
use crate::consts::{DJ00, DJY};
2
use crate::star::fk5hip;
3
use crate::vm::{anp, c2s, rv2m, rxp, s2c, sxp, trxp};
4
5
/// Transform an FK5 (J2000.0) star position into the system of the
6
/// Hipparcos catalog, assuming zero Hipparcos proper motion.
7
///
8
/// Status:  support function.
9
///
10
/// Given:
11
///    r5           f64   FK5 RA (radians), equinox J2000.0, at date
12
///    d5           f64   FK5 Dec (radians), equinox J2000.0, at date
13
///    date1,date2  f64   TDB date (Notes 1,2)
14
///
15
/// Returned:
16
///    rh           f64   Hipparcos RA (radians)
17
///    dh           f64   Hipparcos Dec (radians)
18
///
19
/// Notes:
20
///
21
/// 1) This function converts a star position from the FK5 system to
22
///    the Hipparcos system, in such a way that the Hipparcos proper
23
///    motion is zero.  Because such a star has, in general, a non-zero
24
///    proper motion in the FK5 system, the function requires the date
25
///    at which the position in the FK5 system was determined.
26
///
27
/// 2) The TT date date1+date2 is a Julian Date, apportioned in any
28
///    convenient way between the two arguments.  For example,
29
///    JD(TT)=2450123.7 could be expressed in any of these ways,
30
///    among others:
31
///
32
///           date1          date2
33
///
34
///        2450123.7           0.0       (JD method)
35
///        2451545.0       -1421.3       (J2000 method)
36
///        2400000.5       50123.2       (MJD method)
37
///        2450123.5           0.2       (date & time method)
38
///
39
///    The JD method is the most natural and convenient to use in
40
///    cases where the loss of several decimal digits of resolution
41
///    is acceptable.  The J2000 method is best matched to the way
42
///    the argument is handled internally and will deliver the
43
///    optimum resolution.  The MJD method and the date & time methods
44
///    are both good compromises between resolution and convenience.
45
///
46
/// 3) The FK5 to Hipparcos transformation is modeled as a pure
47
///    rotation and spin;  zonal errors in the FK5 catalog are not
48
///    taken into account.
49
///
50
/// 4) The position returned by this function is in the Hipparcos
51
///    reference system but at date date1+date2.
52
///
53
/// 5) See also fk52h, h2fk5, hfk5z.
54
///
55
/// Called:
56
///    s2c       spherical coordinates to unit vector
57
///    fk5hip    FK5 to Hipparcos rotation and spin
58
///    sxp       multiply p-vector by scalar
59
///    rv2m      r-vector to r-matrix
60
///    trxp      product of transpose of r-matrix and p-vector
61
///    rxp       product of r-matrix and p-vector
62
///    c2s       p-vector to spherical
63
///    anp       normalize angle into range 0 to 2pi
64
///
65
/// Reference:
66
///    F.Mignard & M.Froeschle, 2000, Astron.Astrophys. 354, 732-739.
67
0
pub fn fk5hz(r5: f64, d5: f64, date1: f64, date2: f64) -> (f64, f64) {
68
0
    let mut rst = [[0.0; 3]; 3];
69
0
    let mut p5 = [0.0; 3];
70
0
    let mut ph = [0.0; 3];
71
72
    /* Interval from given date to fundamental epoch J2000.0 (JY). */
73
0
    let t = -((date1 - DJ00) + date2) / DJY;
74
75
    /* FK5 barycentric position vector. */
76
0
    let p5e = s2c(r5, d5);
77
78
    /* FK5 to Hipparcos orientation matrix and spin vector. */
79
0
    let (r5h, s5h) = fk5hip();
80
81
    /* Accumulated Hipparcos wrt FK5 spin over that interval. */
82
0
    let vst = sxp(t, &s5h);
83
84
    /* Express the accumulated spin as a rotation matrix. */
85
0
    rv2m(&vst, &mut rst);
86
87
    /* Derotate the vector's FK5 axes back to date. */
88
0
    trxp(&rst, &p5e, &mut p5);
89
90
    /* Rotate the vector into the Hipparcos system. */
91
0
    rxp(&r5h, &p5, &mut ph);
92
93
    /* Hipparcos vector to spherical. */
94
0
    let (w, dh) = c2s(&ph);
95
0
    let rh = anp(w);
96
97
0
    (rh, dh)
98
0
}