Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

rotation.h

Go to the documentation of this file.
00001 // rotation.h
00002 //
00003 // Copyright (C) 2004 Chris Laurel <claurel@shatters.net>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #ifndef _CELENGINE_ROTATION_H_
00011 #define _CELENGINE_ROTATION_H_
00012 
00013 #include <celmath/quaternion.h>
00014 #include <celengine/astro.h>
00015 
00016 
00017 class RotationElements
00018 {
00019  public:
00020     inline RotationElements();
00021 
00022     inline Quatd eclipticalToEquatorial(double t) const;
00023     inline Quatd eclipticalToPlanetographic(double t) const;
00024     inline Quatd equatorialToPlanetographic(double t) const;
00025 
00026     float period;        // sidereal rotation period
00027     float offset;        // rotation at epoch
00028     double epoch;
00029     float obliquity;     // tilt of rotation axis w.r.t. ecliptic
00030     float ascendingNode; // long. of ascending node of equator on the ecliptic
00031     float precessionRate; // rate of precession of rotation axis in rads/day
00032 };
00033 
00034 
00035 RotationElements::RotationElements() :
00036     period(1.0f),
00037     offset(0.0f),
00038     epoch(astro::J2000),
00039     obliquity(0.0f),
00040     ascendingNode(0.0f),
00041     precessionRate(0.0f)
00042 {
00043 }
00044 
00045 
00046 inline bool operator==(const RotationElements& re0, const RotationElements& re1)
00047 {
00048     return (re0.period         == re1.period        &&
00049             re0.offset         == re1.offset        &&
00050             re0.epoch          == re1.epoch         &&
00051             re0.obliquity      == re1.obliquity     &&
00052             re0.ascendingNode  == re1.ascendingNode &&
00053             re0.precessionRate == re1.precessionRate);
00054 }
00055 
00056 
00057 Quatd RotationElements::eclipticalToEquatorial(double t) const
00058 {
00059     double Omega = (double) ascendingNode + precessionRate * (t - astro::J2000);
00060 
00061     return (Quatd::xrotation(-obliquity) * Quatd::yrotation(-Omega));
00062 }
00063 
00064 
00065 Quatd RotationElements::eclipticalToPlanetographic(double t) const
00066 {
00067     return equatorialToPlanetographic(t) * eclipticalToEquatorial(t);
00068 }
00069 
00070 
00071 Quatd RotationElements::equatorialToPlanetographic(double t) const
00072 {
00073     double rotations = (t - epoch) / (double) period;
00074     double wholeRotations = floor(rotations);
00075     double remainder = rotations - wholeRotations;
00076 
00077     // Add an extra half rotation because of the convention in all
00078     // planet texture maps where zero deg long. is in the middle of
00079     // the texture.
00080     remainder += 0.5;
00081     
00082     Quatd q(1);
00083     q.yrotate(-remainder * 2 * PI - offset);
00084 
00085     return q;
00086 }
00087 
00088 #endif // _CELENGINE_ROTATION_H_

Generated on Sat Jan 14 22:30:28 2006 for Celestia by  doxygen 1.4.1