1 | #include "erfa.h"
|
---|
2 |
|
---|
3 | void eraPv2s(double pv[2][3],
|
---|
4 | double *theta, double *phi, double *r,
|
---|
5 | double *td, double *pd, double *rd)
|
---|
6 | /*
|
---|
7 | ** - - - - - - - -
|
---|
8 | ** e r a P v 2 s
|
---|
9 | ** - - - - - - - -
|
---|
10 | **
|
---|
11 | ** Convert position/velocity from Cartesian to spherical coordinates.
|
---|
12 | **
|
---|
13 | ** Given:
|
---|
14 | ** pv double[2][3] pv-vector
|
---|
15 | **
|
---|
16 | ** Returned:
|
---|
17 | ** theta double longitude angle (radians)
|
---|
18 | ** phi double latitude angle (radians)
|
---|
19 | ** r double radial distance
|
---|
20 | ** td double rate of change of theta
|
---|
21 | ** pd double rate of change of phi
|
---|
22 | ** rd double rate of change of r
|
---|
23 | **
|
---|
24 | ** Notes:
|
---|
25 | **
|
---|
26 | ** 1) If the position part of pv is null, theta, phi, td and pd
|
---|
27 | ** are indeterminate. This is handled by extrapolating the
|
---|
28 | ** position through unit time by using the velocity part of
|
---|
29 | ** pv. This moves the origin without changing the direction
|
---|
30 | ** of the velocity component. If the position and velocity
|
---|
31 | ** components of pv are both null, zeroes are returned for all
|
---|
32 | ** six results.
|
---|
33 | **
|
---|
34 | ** 2) If the position is a pole, theta, td and pd are indeterminate.
|
---|
35 | ** In such cases zeroes are returned for all three.
|
---|
36 | **
|
---|
37 | ** Copyright (C) 2013-2017, NumFOCUS Foundation.
|
---|
38 | ** Derived, with permission, from the SOFA library. See notes at end of file.
|
---|
39 | */
|
---|
40 | {
|
---|
41 | double x, y, z, xd, yd, zd, rxy2, rxy, r2, rtrue, rw, xyp;
|
---|
42 |
|
---|
43 |
|
---|
44 | /* Components of position/velocity vector. */
|
---|
45 | x = pv[0][0];
|
---|
46 | y = pv[0][1];
|
---|
47 | z = pv[0][2];
|
---|
48 | xd = pv[1][0];
|
---|
49 | yd = pv[1][1];
|
---|
50 | zd = pv[1][2];
|
---|
51 |
|
---|
52 | /* Component of r in XY plane squared. */
|
---|
53 | rxy2 = x*x + y*y;
|
---|
54 |
|
---|
55 | /* Modulus squared. */
|
---|
56 | r2 = rxy2 + z*z;
|
---|
57 |
|
---|
58 | /* Modulus. */
|
---|
59 | rtrue = sqrt(r2);
|
---|
60 |
|
---|
61 | /* If null vector, move the origin along the direction of movement. */
|
---|
62 | rw = rtrue;
|
---|
63 | if (rtrue == 0.0) {
|
---|
64 | x = xd;
|
---|
65 | y = yd;
|
---|
66 | z = zd;
|
---|
67 | rxy2 = x*x + y*y;
|
---|
68 | r2 = rxy2 + z*z;
|
---|
69 | rw = sqrt(r2);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /* Position and velocity in spherical coordinates. */
|
---|
73 | rxy = sqrt(rxy2);
|
---|
74 | xyp = x*xd + y*yd;
|
---|
75 | if (rxy2 != 0.0) {
|
---|
76 | *theta = atan2(y, x);
|
---|
77 | *phi = atan2(z, rxy);
|
---|
78 | *td = (x*yd - y*xd) / rxy2;
|
---|
79 | *pd = (zd*rxy2 - z*xyp) / (r2*rxy);
|
---|
80 | } else {
|
---|
81 | *theta = 0.0;
|
---|
82 | *phi = (z != 0.0) ? atan2(z, rxy) : 0.0;
|
---|
83 | *td = 0.0;
|
---|
84 | *pd = 0.0;
|
---|
85 | }
|
---|
86 | *r = rtrue;
|
---|
87 | *rd = (rw != 0.0) ? (xyp + z*zd) / rw : 0.0;
|
---|
88 |
|
---|
89 | return;
|
---|
90 |
|
---|
91 | }
|
---|
92 | /*----------------------------------------------------------------------
|
---|
93 | **
|
---|
94 | **
|
---|
95 | ** Copyright (C) 2013-2017, NumFOCUS Foundation.
|
---|
96 | ** All rights reserved.
|
---|
97 | **
|
---|
98 | ** This library is derived, with permission, from the International
|
---|
99 | ** Astronomical Union's "Standards of Fundamental Astronomy" library,
|
---|
100 | ** available from http://www.iausofa.org.
|
---|
101 | **
|
---|
102 | ** The ERFA version is intended to retain identical functionality to
|
---|
103 | ** the SOFA library, but made distinct through different function and
|
---|
104 | ** file names, as set out in the SOFA license conditions. The SOFA
|
---|
105 | ** original has a role as a reference standard for the IAU and IERS,
|
---|
106 | ** and consequently redistribution is permitted only in its unaltered
|
---|
107 | ** state. The ERFA version is not subject to this restriction and
|
---|
108 | ** therefore can be included in distributions which do not support the
|
---|
109 | ** concept of "read only" software.
|
---|
110 | **
|
---|
111 | ** Although the intent is to replicate the SOFA API (other than
|
---|
112 | ** replacement of prefix names) and results (with the exception of
|
---|
113 | ** bugs; any that are discovered will be fixed), SOFA is not
|
---|
114 | ** responsible for any errors found in this version of the library.
|
---|
115 | **
|
---|
116 | ** If you wish to acknowledge the SOFA heritage, please acknowledge
|
---|
117 | ** that you are using a library derived from SOFA, rather than SOFA
|
---|
118 | ** itself.
|
---|
119 | **
|
---|
120 | **
|
---|
121 | ** TERMS AND CONDITIONS
|
---|
122 | **
|
---|
123 | ** Redistribution and use in source and binary forms, with or without
|
---|
124 | ** modification, are permitted provided that the following conditions
|
---|
125 | ** are met:
|
---|
126 | **
|
---|
127 | ** 1 Redistributions of source code must retain the above copyright
|
---|
128 | ** notice, this list of conditions and the following disclaimer.
|
---|
129 | **
|
---|
130 | ** 2 Redistributions in binary form must reproduce the above copyright
|
---|
131 | ** notice, this list of conditions and the following disclaimer in
|
---|
132 | ** the documentation and/or other materials provided with the
|
---|
133 | ** distribution.
|
---|
134 | **
|
---|
135 | ** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
|
---|
136 | ** the International Astronomical Union nor the names of its
|
---|
137 | ** contributors may be used to endorse or promote products derived
|
---|
138 | ** from this software without specific prior written permission.
|
---|
139 | **
|
---|
140 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
141 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
142 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
---|
143 | ** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
---|
144 | ** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
145 | ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
---|
146 | ** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
147 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
148 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
149 | ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
---|
150 | ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
---|
151 | ** POSSIBILITY OF SUCH DAMAGE.
|
---|
152 | **
|
---|
153 | */
|
---|