Coverage Report

Created: 2026-06-15 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sofars-0.6.1/src/projection/tpxev.rs
Line
Count
Source
1
/// In the tangent plane projection, given celestial direction cosines
2
/// for a star and the tangent point, solve for the star's rectangular
3
/// coordinates in the tangent plane.
4
///
5
/// Status:  support function.
6
///
7
/// Given:
8
///    v         [f64; 3]  direction cosines of star (Note 4)
9
///    v0        [f64; 3]  direction cosines of tangent point (Note 4)
10
///
11
/// Returned:
12
///    xi,eta    f64     tangent plane coordinates of star
13
///    status    i32     status: 0 = OK
14
///                              1 = star too far from axis
15
///                              2 = antistar on tangent plane
16
///                              3 = antistar too far from axis
17
///
18
/// Notes:
19
///
20
/// 1) The tangent plane projection is also called the "gnomonic
21
///    projection" and the "central projection".
22
///
23
/// 2) The eta axis points due north in the adopted coordinate system.
24
///    If the direction cosines represent observed (RA,Dec), the tangent
25
///    plane coordinates (xi,eta) are conventionally called the
26
///    "standard coordinates".  If the direction cosines are with
27
///    respect to a right-handed triad, (xi,eta) are also right-handed.
28
///    The units of (xi,eta) are, effectively, radians at the tangent
29
///    point.
30
///
31
/// 3) The method used is to extend the star vector to the tangent
32
///    plane and then rotate the triad so that (x,y) becomes (xi,eta).
33
///    Writing (a,b) for the celestial spherical coordinates of the
34
///    star, the sequence of rotations is (a+pi/2) around the z-axis
35
///    followed by (pi/2-b) around the x-axis.
36
///
37
/// 4) If vector v0 is not of unit length, or if vector v is of zero
38
///    length, the results will be wrong.
39
///
40
/// 5) If v0 points at a pole, the returned (xi,eta) will be based on
41
///    the arbitrary assumption that the longitude coordinate of the
42
///    tangent point is zero.
43
///
44
/// 6) This function is a member of the following set:
45
///
46
///        spherical      vector         solve for
47
///
48
///        tpxes       > tpxev <       xi,eta
49
///        tpsts         tpstv           star
50
///        tpors         tporv          origin
51
///
52
/// References:
53
///
54
///    Calabretta M.R. & Greisen, E.W., 2002, "Representations of
55
///    celestial coordinates in FITS", Astron.Astrophys. 395, 1077
56
///
57
///    Green, R.M., "Spherical Astronomy", Cambridge University Press,
58
///    1987, Chapter 13.
59
0
pub fn tpxev(v: [f64; 3], v0: [f64; 3]) -> (f64, f64, i32) {
60
    const TINY: f64 = 1e-6;
61
62
0
    let x = v[0];
63
0
    let y = v[1];
64
0
    let z = v[2];
65
0
    let mut x0 = v0[0];
66
0
    let y0 = v0[1];
67
0
    let z0 = v0[2];
68
69
    /* Deal with polar case. */
70
0
    let r2 = x0 * x0 + y0 * y0;
71
0
    let mut r = r2.sqrt();
72
0
    if r == 0.0 {
73
0
        r = 1e-20;
74
0
        x0 = r;
75
0
    }
76
77
    /* Reciprocal of star vector length to tangent plane. */
78
0
    let w = x * x0 + y * y0;
79
0
    let mut d = w + z * z0;
80
81
    /* Check for error cases. */
82
0
    let status = if d > TINY {
83
0
        0
84
0
    } else if d >= 0.0 {
85
0
        d = TINY;
86
0
        1
87
0
    } else if d > -TINY {
88
0
        d = -TINY;
89
0
        2
90
    } else {
91
0
        3
92
    };
93
94
    /* Return the tangent plane coordinates (even in dubious cases). */
95
0
    let d_final = d * r;
96
0
    let xi = (y * x0 - x * y0) / d_final;
97
0
    let eta = (z * r2 - z0 * w) / d_final;
98
99
0
    (xi, eta, status)
100
0
}