sofars/projection/tpstv.rs
1/// In the tangent plane projection, given the star's rectangular
2/// coordinates and the direction cosines of the tangent point, solve
3/// for the direction cosines of the star.
4///
5/// Status: support function.
6///
7/// Given:
8/// xi,eta f64 rectangular coordinates of star image (Note 2)
9/// v0 [f64; 3] tangent point's direction cosines
10///
11/// Returned:
12/// v [f64; 3] star's direction cosines
13///
14/// Notes:
15///
16/// 1) The tangent plane projection is also called the "gnomonic
17/// projection" and the "central projection".
18///
19/// 2) The eta axis points due north in the adopted coordinate system.
20/// If the direction cosines represent observed (RA,Dec), the tangent
21/// plane coordinates (xi,eta) are conventionally called the
22/// "standard coordinates". If the direction cosines are with
23/// respect to a right-handed triad, (xi,eta) are also right-handed.
24/// The units of (xi,eta) are, effectively, radians at the tangent
25/// point.
26///
27/// 3) The method used is to complete the star vector in the (xi,eta)
28/// based triad and normalize it, then rotate the triad to put the
29/// tangent point at the pole with the x-axis aligned to zero
30/// longitude. Writing (a0,b0) for the celestial spherical
31/// coordinates of the tangent point, the sequence of rotations is
32/// (b-pi/2) around the x-axis followed by (-a-pi/2) around the
33/// z-axis.
34///
35/// 4) If vector v0 is not of unit length, the returned vector v will
36/// be wrong.
37///
38/// 5) If vector v0 points at a pole, the returned vector v will be
39/// based on the arbitrary assumption that the longitude coordinate
40/// of the tangent point is zero.
41///
42/// 6) This function is a member of the following set:
43///
44/// spherical vector solve for
45///
46/// tpxes tpxev xi,eta
47/// tpsts > tpstv < star
48/// tpors tporv origin
49///
50/// References:
51///
52/// Calabretta M.R. & Greisen, E.W., 2002, "Representations of
53/// celestial coordinates in FITS", Astron.Astrophys. 395, 1077
54///
55/// Green, R.M., "Spherical Astronomy", Cambridge University Press,
56/// 1987, Chapter 13.
57pub fn tpstv(xi: f64, eta: f64, v0: [f64; 3]) -> [f64; 3] {
58 let mut x = v0[0];
59 let y = v0[1];
60 let z = v0[2];
61
62 /* Deal with polar case. */
63 let mut r = (x * x + y * y).sqrt();
64 if r == 0.0 {
65 r = 1e-20;
66 x = r;
67 }
68
69 /* Star vector length to tangent plane. */
70 let f = (1.0 + xi * xi + eta * eta).sqrt();
71
72 /* Apply the transformation and normalize. */
73 let v_x = (x - (xi * y + eta * x * z) / r) / f;
74 let v_y = (y + (xi * x - eta * y * z) / r) / f;
75 let v_z = (z + eta * r) / f;
76
77 [v_x, v_y, v_z]
78}