source: trunk/FACT++/erfa/src/pv2s.c@ 18614

Last change on this file since 18614 was 18348, checked in by tbretz, 9 years ago
File size: 5.3 KB
Line 
1#include "erfa.h"
2
3void 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-2015, 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/* Components of position/velocity vector. */
44 x = pv[0][0];
45 y = pv[0][1];
46 z = pv[0][2];
47 xd = pv[1][0];
48 yd = pv[1][1];
49 zd = pv[1][2];
50
51/* Component of r in XY plane squared. */
52 rxy2 = x*x + y*y;
53
54/* Modulus squared. */
55 r2 = rxy2 + z*z;
56
57/* Modulus. */
58 rtrue = sqrt(r2);
59
60/* If null vector, move the origin along the direction of movement. */
61 rw = rtrue;
62 if (rtrue == 0.0) {
63 x = xd;
64 y = yd;
65 z = zd;
66 rxy2 = x*x + y*y;
67 r2 = rxy2 + z*z;
68 rw = sqrt(r2);
69 }
70
71/* Position and velocity in spherical coordinates. */
72 rxy = sqrt(rxy2);
73 xyp = x*xd + y*yd;
74 if (rxy2 != 0.0) {
75 *theta = atan2(y, x);
76 *phi = atan2(z, rxy);
77 *td = (x*yd - y*xd) / rxy2;
78 *pd = (zd*rxy2 - z*xyp) / (r2*rxy);
79 } else {
80 *theta = 0.0;
81 *phi = (z != 0.0) ? atan2(z, rxy) : 0.0;
82 *td = 0.0;
83 *pd = 0.0;
84 }
85 *r = rtrue;
86 *rd = (rw != 0.0) ? (xyp + z*zd) / rw : 0.0;
87
88 return;
89
90}
91/*----------------------------------------------------------------------
92**
93**
94** Copyright (C) 2013-2015, NumFOCUS Foundation.
95** All rights reserved.
96**
97** This library is derived, with permission, from the International
98** Astronomical Union's "Standards of Fundamental Astronomy" library,
99** available from http://www.iausofa.org.
100**
101** The ERFA version is intended to retain identical functionality to
102** the SOFA library, but made distinct through different function and
103** file names, as set out in the SOFA license conditions. The SOFA
104** original has a role as a reference standard for the IAU and IERS,
105** and consequently redistribution is permitted only in its unaltered
106** state. The ERFA version is not subject to this restriction and
107** therefore can be included in distributions which do not support the
108** concept of "read only" software.
109**
110** Although the intent is to replicate the SOFA API (other than
111** replacement of prefix names) and results (with the exception of
112** bugs; any that are discovered will be fixed), SOFA is not
113** responsible for any errors found in this version of the library.
114**
115** If you wish to acknowledge the SOFA heritage, please acknowledge
116** that you are using a library derived from SOFA, rather than SOFA
117** itself.
118**
119**
120** TERMS AND CONDITIONS
121**
122** Redistribution and use in source and binary forms, with or without
123** modification, are permitted provided that the following conditions
124** are met:
125**
126** 1 Redistributions of source code must retain the above copyright
127** notice, this list of conditions and the following disclaimer.
128**
129** 2 Redistributions in binary form must reproduce the above copyright
130** notice, this list of conditions and the following disclaimer in
131** the documentation and/or other materials provided with the
132** distribution.
133**
134** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
135** the International Astronomical Union nor the names of its
136** contributors may be used to endorse or promote products derived
137** from this software without specific prior written permission.
138**
139** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
140** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
141** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
142** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
143** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
144** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
145** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
146** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
147** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
148** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
149** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
150** POSSIBILITY OF SUCH DAMAGE.
151**
152*/
Note: See TracBrowser for help on using the repository browser.