~ubuntu-branches/debian/squeeze/stellarium/squeeze

« back to all changes in this revision

Viewing changes to src/stellplanet/elliptic_to_rectangular.c

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2008-05-19 21:28:23 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080519212823-m5nfiuntxstxzxj7
Tags: 0.9.1-4
Add libxcursor-dev, libxfixes-dev, libxinerama-dev, libqt4-opengl-dev to
build-deps (Closes: #479906)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/************************************************************************
2
 
 
3
 
The code in this file is heavily inspired by the TASS17 and GUST86 theories
4
 
found on
5
 
ftp://ftp.imcce.fr/pub/ephem/satel
6
 
 
7
 
I (Johannes Gajdosik) have just taken the Fortran code and data
8
 
obtained from above and rearranged it into this piece of software.
9
 
 
10
 
I can neigther allow nor forbid the above theories.
11
 
The copyright notice below covers just my work,
12
 
that is the compilation of the data obtained from above
13
 
into the software supplied in this file.
14
 
 
15
 
 
16
 
Copyright (c) 2005 Johannes Gajdosik
17
 
 
18
 
Permission is hereby granted, free of charge, to any person obtaining a
19
 
copy of this software and associated documentation files (the "Software"),
20
 
to deal in the Software without restriction, including without limitation
21
 
the rights to use, copy, modify, merge, publish, distribute, sublicense,
22
 
and/or sell copies of the Software, and to permit persons to whom the
23
 
Software is furnished to do so, subject to the following conditions:
24
 
 
25
 
The above copyright notice and this permission notice shall be included
26
 
in all copies or substantial portions of the Software.
27
 
 
28
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34
 
SOFTWARE.
35
 
 
36
 
****************************************************************/
37
 
 
38
 
#include "elliptic_to_rectangular.h"
39
 
 
40
 
#include <math.h>
41
 
 
42
 
static void
43
 
EllipticToRectangular(const double mu,const double a,const double n,
44
 
                      const double elem[6],const double dt,double xyz[]) {
45
 
  const double L = fmod(elem[1]+n*dt,2.0*M_PI);
46
 
    /* solve Keplers equation
47
 
        x = L - elem[2]*sin(x) + elem[3]*cos(x)
48
 
      not by trivially iterating
49
 
        x_0 = L
50
 
        x_{j+1} = L - elem[2]*sin(x_j) + elem[3]*cos(x_j)
51
 
      but instead by Newton approximation:
52
 
        0 = f(x) = x - L - elem[2]*sin(x) + elem[3]*cos(x)
53
 
        f'(x) = 1 - elem[2]*cos(x) - elem[3]*sin(x)
54
 
        x_0 = L or whatever, perhaps first step of trivial iteration
55
 
        x_{j+1} = x_j - f(x_j)/f'(x_j)
56
 
    */
57
 
  double Le = L - elem[2]*sin(L) + elem[3]*cos(L);
58
 
  for (;;) {
59
 
    const double cLe = cos(Le);
60
 
    const double sLe = sin(Le);
61
 
      /* for excenticity < 1 we have denominator > 0 */
62
 
    const double dLe = (L - Le + elem[2]*sLe - elem[3]*cLe)
63
 
                     / (1.0    - elem[2]*cLe - elem[3]*sLe);
64
 
    Le += dLe;
65
 
    if (fabs(dLe) <= 1e-14) break; /* L1: <1e-12 */
66
 
  }
67
 
 
68
 
  const double cLe = cos(Le);
69
 
  const double sLe = sin(Le);
70
 
 
71
 
  const double dlf = -elem[2]*sLe + elem[3]*cLe;
72
 
  const double phi = sqrt(1.0 - elem[2]*elem[2] - elem[3]*elem[3]);
73
 
  const double psi = 1.0 / (1.0 + phi);
74
 
 
75
 
  const double x1 = a * (cLe - elem[2] - psi*dlf*elem[3]);
76
 
  const double y1 = a * (sLe - elem[3] + psi*dlf*elem[2]);
77
 
 
78
 
  const double elem_4q = elem[4] * elem[4];
79
 
  const double elem_5q = elem[5] * elem[5];
80
 
  const double dwho = 2.0 * sqrt(1.0 - elem_4q - elem_5q);
81
 
  const double rtp = 1.0 - elem_5q - elem_5q;
82
 
  const double rtq = 1.0 - elem_4q - elem_4q;
83
 
  const double rdg = 2.0 * elem[5] * elem[4];
84
 
 
85
 
  xyz[0] = x1 * rtp + y1 * rdg;
86
 
  xyz[1] = x1 * rdg + y1 * rtq;
87
 
  xyz[2] = (-x1 * elem[5] + y1 * elem[4]) * dwho;
88
 
 
89
 
/*
90
 
  const double rsam1 = -elem[2]*cLe - elem[3]*sLe;
91
 
  const double h = a*n / (1.0 + rsam1);
92
 
  const double vx1 = h * (-sLe - psi*rsam1*elem[3]);
93
 
  const double vy1 = h * ( cLe + psi*rsam1*elem[2]);
94
 
 
95
 
  xyz[3] = vx1 * rtp + vy1 * rdg;
96
 
  xyz[4] = vx1 * rdg + vy1 * rtq;
97
 
  xyz[5] = (-vx1 * elem[5] + vy1 * elem[4]) * dwho;
98
 
*/
99
 
}
100
 
 
101
 
void EllipticToRectangularN(double mu,const double elem[6],double dt,
102
 
                            double xyz[]) {
103
 
  const double n = elem[0];
104
 
  const double a = cbrt(mu/(n*n));
105
 
  EllipticToRectangular(mu,a,n,elem,dt,xyz);
106
 
}
107
 
 
108
 
void EllipticToRectangularA(double mu,const double elem[6],double dt,
109
 
                            double xyz[]) {
110
 
  const double a = elem[0];
111
 
  const double n = sqrt(mu/(a*a*a));
112
 
  EllipticToRectangular(mu,a,n,elem,dt,xyz);
113
 
}
114