00001 ////////////////////////////////////////////////////////////////////////////////////////////////// 00002 /*! \file ssfMathUtils.h 00003 * \brief Collection of math constants and utility functions. 00004 * \author $Author: cakinli $ 00005 * \version $Revision: 1.1.1.1 $ 00006 * \date $Date: 2005/04/26 17:41:00 $ 00007 *////////////////////////////////////////////////////////////////////////////////////////////////// 00008 /* 00009 */ 00010 ////////////////////////////////////////////////////////////////////////////////////////////////// 00011 00012 #ifndef __SSF_MATH_UTILS_H__ 00013 #define __SSF_MATH_UTILS_H__ 00014 #include <math.h> 00015 namespace O_SESSAME { 00016 ////////////////////////////////////////////////////////////////////////////////////////////////// 00017 /*! \defgroup MathUtils Math Utilities 00018 * \ingroup Utilities 00019 * 00020 */ 00021 ////////////////////////////////////////////////////////////////////////////////////////////////// 00022 /** @defgroup Trigonometry Trigonometry Routines 00023 * \ingroup MathUtils 00024 * Toolbox of Trigonometry routines useful for spacecraft operations. 00025 * @{ 00026 */ 00027 00028 /*! \brief Representation of an angle in radians. 00029 * Currently the angle representation is assumed to be radians, and can be used in any of the other 00030 * Trigonometry functions to convert to Degrees or Degrees-Minutes-Seconds. In the future, the Angle 00031 * should be a class that is unit independent and include the appropriate conversion functions. 00032 */ 00033 typedef double Angle; 00034 00035 /*! \brief Converts an angle from Degrees, Minutes, Seconds (^o,','') to a single quantity in degrees 00036 * and fractions of a degree. 00037 * @param _Degrees Number of degrees in angle (^o). 00038 * @param _Minutes Number of minutes in angle ('). 00039 * @param _Seconds Number of seconds in angle (''). 00040 * @returns Angle in degrees (with decimal part). 00041 */ 00042 inline double DMS2Deg(const double& _Degrees, const double& _Minutes, const double& _Seconds) 00043 { 00044 return _Degrees + _Minutes / 60 + _Seconds / 3600; 00045 } 00046 00047 /*! \brief Converts an angle from a single quantity in degrees 00048 * and fractions of a degree to Degrees, Minutes, Seconds (^o,',''). 00049 * @param _Angle in degrees (with decimal part). 00050 * @param _Degrees Number of degrees in angle (^o). 00051 * @param _Minutes Number of minutes in angle ('). 00052 * @param _Seconds Number of seconds in angle (''). 00053 */ 00054 inline void Deg2DMS(const double& _Angle, double& Degrees, double& Minutes, double& Seconds) 00055 { 00056 Degrees = floor(_Angle); 00057 Minutes = floor((_Angle - Degrees) * 60); 00058 Seconds = (_Angle - Degrees - Minutes / 60) * 3600; 00059 } 00060 00061 /*! \brief Converts an angle from Degrees, Minutes, Seconds (^o,','') to radians. 00062 * @param _Degrees Number of degrees in angle (^o). 00063 * @param _Minutes Number of minutes in angle ('). 00064 * @param _Seconds Number of seconds in angle (''). 00065 * @returns Angle in radians (with decimal part). 00066 */ 00067 inline Angle DMS2Rad(const double& _Degrees,const double& _Minutes, const double& _Seconds) 00068 { 00069 return DMS2Deg(_Degrees, _Minutes, _Seconds) * M_PI / 180; 00070 } 00071 00072 /*! \brief Converts an angle from Degrees to radians. 00073 * @param _Degrees Angle to be converted (^o). 00074 * @returns Angle in radians (with decimal part). 00075 */ 00076 inline Angle Deg2Rad(const Angle& _Degrees) 00077 { 00078 return _Degrees * M_PI / 180; 00079 } 00080 00081 /*! \brief Converts an angle from radians to degrees, minutes, second format. 00082 * @param _Radians Angle to be converted (rad). 00083 * @param Degrees returned number of degrees in angle (^o). 00084 * @param Minutes returned number of minutes in angle ('). 00085 * @param Seconds returned number of seconds in angle (''). 00086 */ 00087 inline void Rad2DMS(const Angle& _Radians, double& Degrees, double& Minutes, double& Seconds) 00088 { 00089 double Angle = _Radians * 180 / M_PI; 00090 Deg2DMS(Angle, Degrees, Minutes, Seconds); 00091 return; 00092 } 00093 00094 /*! \brief Converts an angle from radians to degrees. 00095 * @param _Radians The angle to be converted (rad). 00096 * @return returned number of degrees in angle (^o). 00097 */ 00098 inline Angle Rad2Deg(const Angle& _Radians) 00099 { 00100 return _Radians * 180 / M_PI; 00101 } 00102 /*! \brief Calculates the hyperbolic arctangent of an value using \f$1/2 * log((1+z)/(1-z))$\f. 00103 * @param z value to be calculated. 00104 * @returns hyperbolic arctangent in radians. 00105 */ 00106 inline Angle atanh(const double& _z) 00107 { 00108 return 0.5 * log((1+_z)/(1-_z)); 00109 } 00110 /** @} */ // end of Trigonometry 00111 00112 00113 } // close namespace O_SESSAME 00114 00115 #endif 00116 00117 // Do not change the comments below - they will be added automatically by CVS 00118 /***************************************************************************** 00119 * $Log: MathUtils.h,v $ 00120 * Revision 1.1.1.1 2005/04/26 17:41:00 cakinli 00121 * Adding OpenSESSAME to DSACSS distrib to capture fixed version. 00122 * 00123 * Revision 1.2 2003/05/22 03:00:07 nilspace 00124 * Updated Angle type and inline'd all functions. 00125 * 00126 * Revision 1.1 2003/05/15 18:32:20 nilspace 00127 * Initial submission. 00128 * 00129 * 00130 ******************************************************************************/