Stellarium 0.14.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 // Amendments (c) 2013 Georg Zotti
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
12 
13 #ifndef _ORBIT_HPP_
14 #define _ORBIT_HPP_
15 
16 #include "VecMath.hpp"
17 
18 class OrbitSampleProc;
19 
22 class Orbit
23 {
24 public:
25  Orbit(void) {}
26  virtual ~Orbit(void) {}
27 private:
28  Orbit(const Orbit&);
29  const Orbit &operator=(const Orbit&);
30 };
31 
32 
33 class EllipticalOrbit : public Orbit
34 {
35 public:
36  EllipticalOrbit(double pericenterDistance,
37  double eccentricity,
38  double inclination,
39  double ascendingNode,
40  double argOfPeriapsis,
41  double meanAnomalyAtEpoch,
42  double period,
43  double epoch, // = 2451545.0,
44  double parentRotObliquity, // = 0.0,
45  double parentRotAscendingnode, // = 0.0
46  double parentRotJ2000Longitude // = 0.0
47  );
48 
49  // Compute position for a specified Julian date and return coordinates
50  // given in "dynamical equinox and ecliptic J2000"
51  // which is the reference frame for VSOP87
52  // In order to rotate to VSOP87
53  // parentRotObliquity and parentRotAscendingnode must be supplied.
54  void positionAtTimevInVSOP87Coordinates(const double JDE, double* v) const;
55 
56  // Original one
57  Vec3d positionAtTime(const double JDE) const;
58  double getPeriod() const;
59  double getBoundingRadius() const;
60  virtual void sample(double, double, int, OrbitSampleProc&) const;
61 
62 private:
64  double eccentricAnomaly(const double M) const;
65  Vec3d positionAtE(const double E) const;
66 
67  double pericenterDistance;
68  double eccentricity;
69  double inclination;
70  double ascendingNode;
71  double argOfPeriapsis;
72  double meanAnomalyAtEpoch;
73  double period;
74  double epoch;
75  double rotateToVsop87[9];
76 };
77 
78 
79 class CometOrbit : public Orbit {
80 public:
81  CometOrbit(double pericenterDistance,
82  double eccentricity,
83  double inclination,
84  double ascendingNode,
85  double argOfPerhelion,
86  double timeAtPerihelion,
87  double orbitGoodDays,
88  double meanMotion, // GZ: for parabolics, this is W/dt in Heafner's lettering
89  double parentRotObliquity, // Comets only have parent==sun, no need for these? Oh yes, VSOP/J2000 eq frames!
90  double parentRotAscendingnode,
91  double parentRotJ2000Longitude
92  );
93  // Compute the orbit for a specified Julian day and return a "stellarium compliant" function
94  // GZ: new optional variable: updateVelocityVector, true required for dust tail orientation!
95  void positionAtTimevInVSOP87Coordinates(double JDE, double* v, bool updateVelocityVector=true);
96  // updating the tails is a bit expensive. try not to overdo it.
97  bool getUpdateTails() const { return updateTails; }
98  void setUpdateTails(const bool update){ updateTails=update; }
100  Vec3d getVelocity() const { return rdot; }
101  bool objectDateValid(const double JDE) const { return (fabs(t0-JDE)<orbitGood); }
102 private:
103  const double q;
104  const double e;
105  const double i;
106  const double Om;
107  const double w;
108  const double t0;
109  const double n;
110  Vec3d rdot;
111  double rotateToVsop87[9];
112  bool updateTails;
113  const double orbitGood;
114 };
115 
116 
118 {
119  public:
120  virtual ~OrbitSampleProc() {;}
121  virtual void sample(const Vec3d&) = 0;
122 };
123 
124 
125 
126 // Custom orbit classes should be derived from CachingOrbit. The custom
127 // orbits can be expensive to compute, with more than 50 periodic terms.
128 // Celestia may need require position of a Planet more than once per frame; in
129 // order to avoid redundant calculation, the CachingOrbit class saves the
130 // result of the last calculation and uses it if the time matches the cached
131 // time.
132 class CachingOrbit : public Orbit
133 {
134 public:
135  CachingOrbit() : lastTime(1.0e-30) {} //;
136 
137  virtual Vec3d computePosition(double JDE) const = 0;
138  virtual double getPeriod() const = 0;
139  virtual double getBoundingRadius() const = 0;
140 
141  Vec3d positionAtTime(double JDE) const;
142 
143  virtual void sample(double, double, int, OrbitSampleProc& proc) const;
144 
145 private:
146  mutable Vec3d lastPosition;
147  mutable double lastTime;
148 };
149 
150 
151 
152 #endif // _ORBIT_HPP_
Definition: Orbit.hpp:22
Vec3d getVelocity() const
return speed value [AU/d] last computed by positionAtTimevInVSOP87Coordinates(JDE, v, true)
Definition: Orbit.hpp:100