File Coverage

erfasrc/src/tporv.c
Criterion Covered Total %
statement 0 23 0.0
branch 0 4 0.0
condition n/a
subroutine n/a
pod n/a
total 0 27 0.0


line stmt bran cond sub pod time code
1             #include "erfa.h"
2              
3 0           int eraTporv(double xi, double eta, double v[3],
4             double v01[3], double v02[3])
5             /*
6             ** - - - - - - - - -
7             ** e r a T p o r v
8             ** - - - - - - - - -
9             **
10             ** In the tangent plane projection, given the rectangular coordinates
11             ** of a star and its direction cosines, determine the direction
12             ** cosines of the tangent point.
13             **
14             ** Given:
15             ** xi,eta double rectangular coordinates of star image (Note 2)
16             ** v double[3] star's direction cosines (Note 3)
17             **
18             ** Returned:
19             ** v01 double[3] tangent point's direction cosines, Solution 1
20             ** v02 double[3] tangent point's direction cosines, Solution 2
21             **
22             ** Returned (function value):
23             ** int number of solutions:
24             ** 0 = no solutions returned (Note 4)
25             ** 1 = only the first solution is useful (Note 5)
26             ** 2 = both solutions are useful (Note 5)
27             **
28             ** Notes:
29             **
30             ** 1) The tangent plane projection is also called the "gnomonic
31             ** projection" and the "central projection".
32             **
33             ** 2) The eta axis points due north in the adopted coordinate system.
34             ** If the direction cosines represent observed (RA,Dec), the tangent
35             ** plane coordinates (xi,eta) are conventionally called the
36             ** "standard coordinates". If the direction cosines are with
37             ** respect to a right-handed triad, (xi,eta) are also right-handed.
38             ** The units of (xi,eta) are, effectively, radians at the tangent
39             ** point.
40             **
41             ** 3) The vector v must be of unit length or the result will be wrong.
42             **
43             ** 4) Cases where there is no solution can arise only near the poles.
44             ** For example, it is clearly impossible for a star at the pole
45             ** itself to have a non-zero xi value, and hence it is meaningless
46             ** to ask where the tangent point would have to be.
47             **
48             ** 5) Also near the poles, cases can arise where there are two useful
49             ** solutions. The return value indicates whether the second of the
50             ** two solutions returned is useful; 1 indicates only one useful
51             ** solution, the usual case.
52             **
53             ** 6) The basis of the algorithm is to solve the spherical triangle
54             ** PSC, where P is the north celestial pole, S is the star and C is
55             ** the tangent point. Calling the celestial spherical coordinates
56             ** of the star and tangent point (a,b) and (a0,b0) respectively, and
57             ** writing rho^2 = (xi^2+eta^2) and r^2 = (1+rho^2), and
58             ** transforming the vector v into (a,b) in the normal way, side c is
59             ** then (pi/2-b), side p is sqrt(xi^2+eta^2) and side s (to be
60             ** found) is (pi/2-b0), while angle C is given by sin(C) = xi/rho
61             ** and cos(C) = eta/rho; angle P (to be found) is (a-a0). After
62             ** solving the spherical triangle, the result (a0,b0) can be
63             ** expressed in vector form as v0.
64             **
65             ** 7) This function is a member of the following set:
66             **
67             ** spherical vector solve for
68             **
69             ** eraTpxes eraTpxev xi,eta
70             ** eraTpsts eraTpstv star
71             ** eraTpors > eraTporv < origin
72             **
73             ** References:
74             **
75             ** Calabretta M.R. & Greisen, E.W., 2002, "Representations of
76             ** celestial coordinates in FITS", Astron.Astrophys. 395, 1077
77             **
78             ** Green, R.M., "Spherical Astronomy", Cambridge University Press,
79             ** 1987, Chapter 13.
80             **
81             ** Copyright (C) 2013-2019, NumFOCUS Foundation.
82             ** Derived, with permission, from the SOFA library. See notes at end of file.
83             */
84             {
85             double x, y, z, rxy2, xi2, eta2p1, r, rsb, rcb, w2, w, c;
86              
87              
88 0           x = v[0];
89 0           y = v[1];
90 0           z = v[2];
91 0           rxy2 = x*x + y*y;
92 0           xi2 = xi*xi;
93 0           eta2p1 = eta*eta + 1.0;
94 0           r = sqrt(xi2 + eta2p1);
95 0           rsb = r*z;
96 0           rcb = r*sqrt(x*x + y*y);
97 0           w2 = rcb*rcb - xi2;
98 0 0         if ( w2 > 0.0 ) {
99 0           w = sqrt(w2);
100 0           c = (rsb*eta + w) / (eta2p1*sqrt(rxy2*(w2+xi2)));
101 0           v01[0] = c * (x*w + y*xi);
102 0           v01[1] = c * (y*w - x*xi);
103 0           v01[2] = (rsb - eta*w) / eta2p1;
104 0           w = - w;
105 0           c = (rsb*eta + w) / (eta2p1*sqrt(rxy2*(w2+xi2)));
106 0           v02[0] = c * (x*w + y*xi);
107 0           v02[1] = c * (y*w - x*xi);
108 0           v02[2] = (rsb - eta*w) / eta2p1;
109 0 0         return (fabs(rsb) < 1.0) ? 1 : 2;
110             } else {
111             return 0;
112             }
113              
114             /* Finished. */
115              
116             }
117             /*----------------------------------------------------------------------
118             **
119             **
120             ** Copyright (C) 2013-2019, NumFOCUS Foundation.
121             ** All rights reserved.
122             **
123             ** This library is derived, with permission, from the International
124             ** Astronomical Union's "Standards of Fundamental Astronomy" library,
125             ** available from http://www.iausofa.org.
126             **
127             ** The ERFA version is intended to retain identical functionality to
128             ** the SOFA library, but made distinct through different function and
129             ** file names, as set out in the SOFA license conditions. The SOFA
130             ** original has a role as a reference standard for the IAU and IERS,
131             ** and consequently redistribution is permitted only in its unaltered
132             ** state. The ERFA version is not subject to this restriction and
133             ** therefore can be included in distributions which do not support the
134             ** concept of "read only" software.
135             **
136             ** Although the intent is to replicate the SOFA API (other than
137             ** replacement of prefix names) and results (with the exception of
138             ** bugs; any that are discovered will be fixed), SOFA is not
139             ** responsible for any errors found in this version of the library.
140             **
141             ** If you wish to acknowledge the SOFA heritage, please acknowledge
142             ** that you are using a library derived from SOFA, rather than SOFA
143             ** itself.
144             **
145             **
146             ** TERMS AND CONDITIONS
147             **
148             ** Redistribution and use in source and binary forms, with or without
149             ** modification, are permitted provided that the following conditions
150             ** are met:
151             **
152             ** 1 Redistributions of source code must retain the above copyright
153             ** notice, this list of conditions and the following disclaimer.
154             **
155             ** 2 Redistributions in binary form must reproduce the above copyright
156             ** notice, this list of conditions and the following disclaimer in
157             ** the documentation and/or other materials provided with the
158             ** distribution.
159             **
160             ** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
161             ** the International Astronomical Union nor the names of its
162             ** contributors may be used to endorse or promote products derived
163             ** from this software without specific prior written permission.
164             **
165             ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
166             ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
167             ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
168             ** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
169             ** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
170             ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
171             ** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
172             ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
173             ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
174             ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
175             ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
176             ** POSSIBILITY OF SUCH DAMAGE.
177             **
178             */