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