Stellarium 0.12.3
Orbit.hpp
1 // orbit.h
2 //
3 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
4 //
5 // CometOrbit: Copyright (C) 2007,2008 Johannes Gajdosik
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 
12 #ifndef _ORBIT_HPP_
13 #define _ORBIT_HPP_
14 
15 #include "VecMath.hpp"
16 
17 class OrbitSampleProc;
18 
21 class Orbit
22 {
23 public:
24  Orbit(void) {}
25  virtual ~Orbit(void) {}
26 private:
27  Orbit(const Orbit&);
28  const Orbit &operator=(const Orbit&);
29 };
30 
31 
32 class EllipticalOrbit : public Orbit
33 {
34 public:
35  EllipticalOrbit(double pericenterDistance,
36  double eccentricity,
37  double inclination,
38  double ascendingNode,
39  double argOfPeriapsis,
40  double meanAnomalyAtEpoch,
41  double period,
42  double epoch, // = 2451545.0,
43  double parentRotObliquity, // = 0.0,
44  double parentRotAscendingnode, // = 0.0
45  double parentRotJ2000Longitude // = 0.0
46  );
47 
48  // Compute position for a specified Julian date and return coordinates
49  // given in "dynamical equinox and ecliptic J2000"
50  // which is the reference frame for VSOP87
51  // In order to rotate to VSOP87
52  // parentRotObliquity and parentRotAscendingnode must be supplied.
53  void positionAtTimevInVSOP87Coordinates(double JD, double* v) const;
54 
55  // Original one
56  Vec3d positionAtTime(double) const;
57  double getPeriod() const;
58  double getBoundingRadius() const;
59  virtual void sample(double, double, int, OrbitSampleProc&) const;
60 
61 private:
62  double eccentricAnomaly(double) const;
63  Vec3d positionAtE(double) const;
64 
65  double pericenterDistance;
66  double eccentricity;
67  double inclination;
68  double ascendingNode;
69  double argOfPeriapsis;
70  double meanAnomalyAtEpoch;
71  double period;
72  double epoch;
73  double rotateToVsop87[9];
74 };
75 
76 
77 class CometOrbit : public Orbit {
78 public:
79  CometOrbit(double pericenterDistance,
80  double eccentricity,
81  double inclination,
82  double ascendingNode,
83  double argOfPerhelion,
84  double timeAtPerihelion,
85  double meanMotion,
86  double parentRotObliquity,
87  double parentRotAscendingnode,
88  double parentRotJ2000Longitude);
89 
90  // Compute the orbit for a specified Julian date and return a "stellarium compliant" function
91  void positionAtTimevInVSOP87Coordinates(double JD, double* v) const;
92 private:
93  const double q;
94  const double e;
95  const double i;
96  const double Om;
97  const double o;
98  const double t0;
99  const double n;
100  double rotateToVsop87[9];
101 };
102 
103 
105 {
106  public:
107  virtual ~OrbitSampleProc() {;}
108  virtual void sample(const Vec3d&) = 0;
109 };
110 
111 
112 
113 // Custom orbit classes should be derived from CachingOrbit. The custom
114 // orbits can be expensive to compute, with more than 50 periodic terms.
115 // Celestia may need require position of a Planet more than once per frame; in
116 // order to avoid redundant calculation, the CachingOrbit class saves the
117 // result of the last calculation and uses it if the time matches the cached
118 // time.
119 class CachingOrbit : public Orbit
120 {
121 public:
122  CachingOrbit() : lastTime(1.0e-30) {};
123 
124  virtual Vec3d computePosition(double jd) const = 0;
125  virtual double getPeriod() const = 0;
126  virtual double getBoundingRadius() const = 0;
127 
128  Vec3d positionAtTime(double jd) const;
129 
130  virtual void sample(double, double, int, OrbitSampleProc& proc) const;
131 
132 private:
133  mutable Vec3d lastPosition;
134  mutable double lastTime;
135 };
136 
137 
138 
139 #endif // _ORBIT_HPP_