source: trunk/FACT++/sofa/src/pv2s.c@ 18375

Last change on this file since 18375 was 18346, checked in by tbretz, 11 years ago
File size: 6.7 KB
Line 
1#include "sofa.h"
2
3void iauPv2s(double pv[2][3],
4 double *theta, double *phi, double *r,
5 double *td, double *pd, double *rd)
6/*
7** - - - - - - - -
8** i a u P v 2 s
9** - - - - - - - -
10**
11** Convert position/velocity from Cartesian to spherical coordinates.
12**
13** This function is part of the International Astronomical Union's
14** SOFA (Standards Of Fundamental Astronomy) software collection.
15**
16** Status: vector/matrix support function.
17**
18** Given:
19** pv double[2][3] pv-vector
20**
21** Returned:
22** theta double longitude angle (radians)
23** phi double latitude angle (radians)
24** r double radial distance
25** td double rate of change of theta
26** pd double rate of change of phi
27** rd double rate of change of r
28**
29** Notes:
30**
31** 1) If the position part of pv is null, theta, phi, td and pd
32** are indeterminate. This is handled by extrapolating the
33** position through unit time by using the velocity part of
34** pv. This moves the origin without changing the direction
35** of the velocity component. If the position and velocity
36** components of pv are both null, zeroes are returned for all
37** six results.
38**
39** 2) If the position is a pole, theta, td and pd are indeterminate.
40** In such cases zeroes are returned for all three.
41**
42** This revision: 2013 June 18
43**
44** SOFA release 2015-02-09
45**
46** Copyright (C) 2015 IAU SOFA Board. See notes at end.
47*/
48{
49 double x, y, z, xd, yd, zd, rxy2, rxy, r2, rtrue, rw, xyp;
50
51/* Components of position/velocity vector. */
52 x = pv[0][0];
53 y = pv[0][1];
54 z = pv[0][2];
55 xd = pv[1][0];
56 yd = pv[1][1];
57 zd = pv[1][2];
58
59/* Component of r in XY plane squared. */
60 rxy2 = x*x + y*y;
61
62/* Modulus squared. */
63 r2 = rxy2 + z*z;
64
65/* Modulus. */
66 rtrue = sqrt(r2);
67
68/* If null vector, move the origin along the direction of movement. */
69 rw = rtrue;
70 if (rtrue == 0.0) {
71 x = xd;
72 y = yd;
73 z = zd;
74 rxy2 = x*x + y*y;
75 r2 = rxy2 + z*z;
76 rw = sqrt(r2);
77 }
78
79/* Position and velocity in spherical coordinates. */
80 rxy = sqrt(rxy2);
81 xyp = x*xd + y*yd;
82 if (rxy2 != 0.0) {
83 *theta = atan2(y, x);
84 *phi = atan2(z, rxy);
85 *td = (x*yd - y*xd) / rxy2;
86 *pd = (zd*rxy2 - z*xyp) / (r2*rxy);
87 } else {
88 *theta = 0.0;
89 *phi = (z != 0.0) ? atan2(z, rxy) : 0.0;
90 *td = 0.0;
91 *pd = 0.0;
92 }
93 *r = rtrue;
94 *rd = (rw != 0.0) ? (xyp + z*zd) / rw : 0.0;
95
96 return;
97
98/*----------------------------------------------------------------------
99**
100** Copyright (C) 2015
101** Standards Of Fundamental Astronomy Board
102** of the International Astronomical Union.
103**
104** =====================
105** SOFA Software License
106** =====================
107**
108** NOTICE TO USER:
109**
110** BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND
111** CONDITIONS WHICH APPLY TO ITS USE.
112**
113** 1. The Software is owned by the IAU SOFA Board ("SOFA").
114**
115** 2. Permission is granted to anyone to use the SOFA software for any
116** purpose, including commercial applications, free of charge and
117** without payment of royalties, subject to the conditions and
118** restrictions listed below.
119**
120** 3. You (the user) may copy and distribute SOFA source code to others,
121** and use and adapt its code and algorithms in your own software,
122** on a world-wide, royalty-free basis. That portion of your
123** distribution that does not consist of intact and unchanged copies
124** of SOFA source code files is a "derived work" that must comply
125** with the following requirements:
126**
127** a) Your work shall be marked or carry a statement that it
128** (i) uses routines and computations derived by you from
129** software provided by SOFA under license to you; and
130** (ii) does not itself constitute software provided by and/or
131** endorsed by SOFA.
132**
133** b) The source code of your derived work must contain descriptions
134** of how the derived work is based upon, contains and/or differs
135** from the original SOFA software.
136**
137** c) The names of all routines in your derived work shall not
138** include the prefix "iau" or "sofa" or trivial modifications
139** thereof such as changes of case.
140**
141** d) The origin of the SOFA components of your derived work must
142** not be misrepresented; you must not claim that you wrote the
143** original software, nor file a patent application for SOFA
144** software or algorithms embedded in the SOFA software.
145**
146** e) These requirements must be reproduced intact in any source
147** distribution and shall apply to anyone to whom you have
148** granted a further right to modify the source code of your
149** derived work.
150**
151** Note that, as originally distributed, the SOFA software is
152** intended to be a definitive implementation of the IAU standards,
153** and consequently third-party modifications are discouraged. All
154** variations, no matter how minor, must be explicitly marked as
155** such, as explained above.
156**
157** 4. You shall not cause the SOFA software to be brought into
158** disrepute, either by misuse, or use for inappropriate tasks, or
159** by inappropriate modification.
160**
161** 5. The SOFA software is provided "as is" and SOFA makes no warranty
162** as to its use or performance. SOFA does not and cannot warrant
163** the performance or results which the user may obtain by using the
164** SOFA software. SOFA makes no warranties, express or implied, as
165** to non-infringement of third party rights, merchantability, or
166** fitness for any particular purpose. In no event will SOFA be
167** liable to the user for any consequential, incidental, or special
168** damages, including any lost profits or lost savings, even if a
169** SOFA representative has been advised of such damages, or for any
170** claim by any third party.
171**
172** 6. The provision of any version of the SOFA software under the terms
173** and conditions specified herein does not imply that future
174** versions will also be made available under the same terms and
175** conditions.
176*
177** In any published work or commercial product which uses the SOFA
178** software directly, acknowledgement (see www.iausofa.org) is
179** appreciated.
180**
181** Correspondence concerning SOFA software should be addressed as
182** follows:
183**
184** By email: sofa@ukho.gov.uk
185** By post: IAU SOFA Center
186** HM Nautical Almanac Office
187** UK Hydrographic Office
188** Admiralty Way, Taunton
189** Somerset, TA1 2DN
190** United Kingdom
191**
192**--------------------------------------------------------------------*/
193}
Note: See TracBrowser for help on using the repository browser.