source: trunk/FACT++/erfa/src/pap.c@ 18679

Last change on this file since 18679 was 18348, checked in by tbretz, 9 years ago
File size: 5.2 KB
Line 
1#include "erfa.h"
2
3double eraPap(double a[3], double b[3])
4/*
5** - - - - - - -
6** e r a P a p
7** - - - - - - -
8**
9** Position-angle from two p-vectors.
10**
11** Given:
12** a double[3] direction of reference point
13** b double[3] direction of point whose PA is required
14**
15** Returned (function value):
16** double position angle of b with respect to a (radians)
17**
18** Notes:
19**
20** 1) The result is the position angle, in radians, of direction b with
21** respect to direction a. It is in the range -pi to +pi. The
22** sense is such that if b is a small distance "north" of a the
23** position angle is approximately zero, and if b is a small
24** distance "east" of a the position angle is approximately +pi/2.
25**
26** 2) The vectors a and b need not be of unit length.
27**
28** 3) Zero is returned if the two directions are the same or if either
29** vector is null.
30**
31** 4) If vector a is at a pole, the result is ill-defined.
32**
33** Called:
34** eraPn decompose p-vector into modulus and direction
35** eraPm modulus of p-vector
36** eraPxp vector product of two p-vectors
37** eraPmp p-vector minus p-vector
38** eraPdp scalar product of two p-vectors
39**
40** Copyright (C) 2013-2015, NumFOCUS Foundation.
41** Derived, with permission, from the SOFA library. See notes at end of file.
42*/
43{
44 double am, au[3], bm, st, ct, xa, ya, za, eta[3], xi[3], a2b[3], pa;
45
46/* Modulus and direction of the a vector. */
47 eraPn(a, &am, au);
48
49/* Modulus of the b vector. */
50 bm = eraPm(b);
51
52/* Deal with the case of a null vector. */
53 if ((am == 0.0) || (bm == 0.0)) {
54 st = 0.0;
55 ct = 1.0;
56 } else {
57
58 /* The "north" axis tangential from a (arbitrary length). */
59 xa = a[0];
60 ya = a[1];
61 za = a[2];
62 eta[0] = -xa * za;
63 eta[1] = -ya * za;
64 eta[2] = xa*xa + ya*ya;
65
66 /* The "east" axis tangential from a (same length). */
67 eraPxp(eta, au, xi);
68
69 /* The vector from a to b. */
70 eraPmp(b, a, a2b);
71
72 /* Resolve into components along the north and east axes. */
73 st = eraPdp(a2b, xi);
74 ct = eraPdp(a2b, eta);
75
76 /* Deal with degenerate cases. */
77 if ((st == 0.0) && (ct == 0.0)) ct = 1.0;
78 }
79
80/* Position angle. */
81 pa = atan2(st, ct);
82
83 return pa;
84
85}
86/*----------------------------------------------------------------------
87**
88**
89** Copyright (C) 2013-2015, NumFOCUS Foundation.
90** All rights reserved.
91**
92** This library is derived, with permission, from the International
93** Astronomical Union's "Standards of Fundamental Astronomy" library,
94** available from http://www.iausofa.org.
95**
96** The ERFA version is intended to retain identical functionality to
97** the SOFA library, but made distinct through different function and
98** file names, as set out in the SOFA license conditions. The SOFA
99** original has a role as a reference standard for the IAU and IERS,
100** and consequently redistribution is permitted only in its unaltered
101** state. The ERFA version is not subject to this restriction and
102** therefore can be included in distributions which do not support the
103** concept of "read only" software.
104**
105** Although the intent is to replicate the SOFA API (other than
106** replacement of prefix names) and results (with the exception of
107** bugs; any that are discovered will be fixed), SOFA is not
108** responsible for any errors found in this version of the library.
109**
110** If you wish to acknowledge the SOFA heritage, please acknowledge
111** that you are using a library derived from SOFA, rather than SOFA
112** itself.
113**
114**
115** TERMS AND CONDITIONS
116**
117** Redistribution and use in source and binary forms, with or without
118** modification, are permitted provided that the following conditions
119** are met:
120**
121** 1 Redistributions of source code must retain the above copyright
122** notice, this list of conditions and the following disclaimer.
123**
124** 2 Redistributions in binary form must reproduce the above copyright
125** notice, this list of conditions and the following disclaimer in
126** the documentation and/or other materials provided with the
127** distribution.
128**
129** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
130** the International Astronomical Union nor the names of its
131** contributors may be used to endorse or promote products derived
132** from this software without specific prior written permission.
133**
134** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
137** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
138** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
139** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
140** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
141** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
142** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
143** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
144** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
145** POSSIBILITY OF SUCH DAMAGE.
146**
147*/
Note: See TracBrowser for help on using the repository browser.